Hello,
I’ve gone down a rabbit hole exploring the issue of unwanted whitespace when using multiline content blocks. I’m writing this both because I have some remaining questions, and so that future people may find this helpful.
The problem is essentially that the following code produces unwanted whitespace between the figure prefix and caption text:
#figure(
image("..."),
caption: [
My long caption which I want to put on multiple lines
],
)
I have already looked at the following links (and possibly more):
- the original issue and all the issues linked to on that page
- this discussion
- this other issue: Create a dedicated section on dangers of using square brackets carelessly (multi-line) · Issue #6844 · typst/typst · GitHub
Out of these, there were a few suggestions that apply to similar issues:
- Simply avoid the linebreak.
- Use
#h(0pt, weak: true), either directly or through a show. - Use code mode for whitespace-sensitive situations.
- Use block comments to eat up the linebreak.
My remaining questions are:
- I’m still not sure how I should go about formatting my code in the figure caption example. The easiest option is clearly just to do
[My long caption...]but that’s not really pretty. The other options aren’t particularly satisfactory either. - Where can I find some explanation of how whitespace is handled in code mode? This has been one of my longstanding confusions but I’ve never been able to find a clear answer. It’s very possible that I once read about it in the docs but I can’t find it now.
- Out of curiosity, does
#footnoteuse some special mechanism for removing leading/trailing whitespace? Why is the behaviour different from figure captions? - Are spaces generally just removed leading and following a paragraph/block-level element? And is that the reason why the following code doesn’t produce a preceding space?
#[
Hello world
]
Thanks in advance!

