The #align function puts it on a new line. I am trying to have it on the last line.
The code below is so close. But there is a small amount of space added after the last line. The background colour is added to illustrate this. If I remove the QED #place code, the box finishes right under the last line. Where is this extra vertical space coming from? I also don’t know exactly how much negative dy offset is needed to line up perfectly with the last line.
Since you have the float parameter enabled, the place element will reserve some space at the bottom of the block to fit the QED symbol. The negative dy offset is only applied afterwards, so the space remains.
It seems to me, that you don’t actually need this to be floating. When you just do
#place(bottom + right, $qed$)
the QED symbol will still be positioned at the bottom right of the block.
This puts the QED symbol into the actual last line of the proof, and should therefore have the correct y position. The difference to the place variant is minuscule, though.
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.
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).
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.
Eric, that works! The only issue is the last characters of the proof write under the floating QED symbol. I solved that by adding an invisible QED symbol at the end of the line. A bit hacky. But it works. I also confirmed that the vertical alignment is pixel perfect the same as the inline invisible QED symbol. Which is nice to know.
SillyFreak, that works except as laurmaedje noted. It at least makes more typographic sense than #place and float right. Maybe? Although, the float method as I implemented is pixel perfect identical vertical positioning.
laurmaedje, that all seems to work perfectly for me, except Typst is throwing errors and it only works when I make the proof equal a block proof(body) = block( ... , { content } ) and not when I put the block in the proof #let proof(body) = { block( ... ) [ content ] }. I think that is code mode vs. markup mode.
Yes indeed, I used code mode because otherwise there will be extra spaces around the word joiner. Markup mode should also be possible, but you would need to write the things tightly after each other and use a semicolon to terminate the word joiner.