One unfortunate edge case with this solution is if the QED symbol doesn’t fit into the last line. Then, the h(1fr)
remains in the second-to-last line and the QED symbol is on the left side of the last line.
A possible fix is adding a Unicode Word Joiner (sym.wj
) after the spacing.
#let proof(body) = block(width: 100%, fill: rgb("#EEEEEE"), {
[_Proof._ ]
body
h(1fr)
sym.wj
sym.space.nobreak
$qed$
})
However, this also forces the last preceding word to the next line. If this is not desirable, one could add a zero-width box before the spacing (which will then be forced to the next line instead of the last word, to no visible effect).
#let proof(body) = block(width: 100%, fill: rgb("#EEEEEE"), {
[_Proof._ ]
body
box(width: 0pt)
h(1fr)
sym.wj
sym.space.nobreak
$qed$
})
This is obviously somewhat obscure and requires intricate knowledge of Unicode and Typst’s paragraph layout. I also only came up with this solution now even though I’ve thought about this problem a few times before. I’m not 100% sure whether there are cases where it doesn’t work correctly, but it any case it felt worth sharing.
Edit: Added nobreak spaces to ensure that there is a minimum amount of space before the proof square.