Delay placement of a figure?

I was wondering if it was possible to delay a command, so it takes effect several pages later in the document. Specifically, I would like to place a figure several pages later than in appears in the source.

For example, in the following I would like the figure occur on the second or third page:

#figure(
    placement:bottom,
    [#square(fill: blue, size: 4cm)],
    caption: [Somewhere in the middle.])

#lorem(3000) // A several page text document. 

My goal is to control the position of the figure, without interspersing the document text and typst commands

Thanks!

Hello, my first thought was to use place.flush():

Asks the layout algorithm to place pending floating elements before continuing with the content. Place Function – Typst Documentation

Screenshot

It’s probably more toward the opposite of what you’re asking for, but I’m sure this also dawned on others looking at the post.

Yes, place.flush() is essentially of the opposite of what I would like to do.

1 Like

How do you intend to control the position of the figure in the document? I mean what would the ideal solution look like in code?

1 Like

If by “occur” you mean just visually, then do:

#let some-figure = figure(
  placement: bottom,
  square(fill: blue, size: 4cm),
  caption: [Somewhere in the middle.],
)

#lorem(3000) // A several page text document.

#some-figure

But I think any granularity in “place on page n” is impossible. You can do out of document flow conditional placement with page.background. If it doesn’t naturally place into the exact place, then it’s probably never will, gotta place it manually.

Because of the lack of other good solutions, here is a dubious one. You can ask meander to make a layout like this: one or more full pages, then a page with a placed figure on the bottom. And the text flows through those pages.

#import "@preview/meander:0.4.2"

#meander.reflow({
  import meander: *
  container()
  pagebreak()
  placed(bottom, figure(rect(width: 100%, height: 8cm), caption: [Caption]))  
  container()
  content[
    #set par(justify: true)
    #lorem(1500)
  ]
})

This text comes after that block.

1 Like

Thanks, this use of meander does answer my question.

However, when I tried it in my document, I found that it wasn’t a simple drop in replacement. The spacing between the text and figures changed from that in the rest of the document, and spurious paragraph breaks were introduced at the start of each page. Annoyingly, meander did not introduces these extra paragraph breaks when I tried to create a minimal example - something else in my document must be interfering.

These problems are likely solvable with some time, but in the end not worth it for my case.

1 Like

Constructive package usage feedback is always welcome and helps improve it. https://github.com/Vanille-N/meander.typ/issues

The paragraph issue, is that with indent on all paragraphs? I think I’ve run into that. But the main problem with meander (not meander’s fault) is that the whole document becomes sluggish because a lot of layout has to happen in the package code instead of natively by Typst. And I think it’s fair to avoid that unless it’s absolutely needed.