I am using typst to write my Facharbeit (scientific paper in a German high school). One of the formal criteria is that all figures have to be appended at the end.
However, for reading the text digitally, this is extremely inconvenient as you have to scroll all the way down only to get the relevant context, and a teacher of mine said she wants to have a printed version of the document with the figures inline, i.e. inserted in the text content at not at the end. Manually moving them is repetitive and error-prone, especially as information is lost when moving the figures at the end.
Would it be possible to implement such a toggle, i.e. #let inline-figures = true | false, and automatically move the figures to where they belong? Ideally, I could just use the figure-command as is without needing to change anything about it, but it would also be fine if there could be a new function, "#myfigure", that did what I described for me.
Thanks in advance!
From the documentation and issue tracker of Typst it seems that it is not possible to modify the position of rendered figures programmatically (see https://github.com/typst/typst/issues/553 for some background).
An alternative approach is to postprocess the document with a different programming language in order to move the figures in the source code which can then be recompiled.
The following Python program searches for
#figure
tags and extracts the following code up to the balanced closing parenthesis and possible label between< >
. Then it reconstructs the code by removing all figure chunks from the main text and adding them back at the end.This Python code can be applied on the following Typst document:
The resulting document
endfigs.typ
, when compiled, looks like this: