Why does a semicolon go missing from output when inserted directly after code expression?

I just had a problem where I have the following code:

#set page(height: auto, width: auto, margin: 1cm)

The semicolon after this #{[code epxression]}; will disappear.

Is the disappearance of the semicolon after #{} intended behavior? How would you correct it? Indeed it happens after any code expression, namely functions etc. Adding a space between the code expression and the semicolon also adds an actual space in the output, so how would you fix this?

1 Like

I just found out that one can escape the semicolon with a backslash.

#set page(height: auto, width: auto, margin: 1cm)

After this #{[code expression]}\; the semicolon will appear.

Still the question remains if this is intended behavior.

from the docs

If a character would continue the expression but should be interpreted as text, the expression can forcibly be ended with a semicolon (; ).

Scripting – Typst Documentation.

So writing #{ ...};, the semicolon directly after } is interpreted as the expression termination character.

3 Likes

Ah ok I see. I guess that makes sense. So I could also write

After this #{[code expression]};; the semicolon will appear.

Hi @SebastianJL, I have moved your question to the Questions category, please make sure to check the category when creating a topic :slight_smile: that also means that you can select an answer. If you feel the response you got has sufficiently answered your question, be sure to give it a checkmark. This will help others find the solution in the future. Thanks!

Thanks for the gentle slap on the wrist :slight_smile: I went back and marked questions as solved in past threads. Unfortunately I wasn’t able to change the categories for all posts that where questions. Sorry for posting a bit carelessly. The forum has been a great help this week.

3 Likes

I must say I find the explanation a bit unsatisfying: isn’t } already terminating the expression? Which character could continue the expression here?

I agree this is a bit of an edge case. This could be improved in the parser.

Basically, the idea behind semicolon is to handle expressions like

#import "module.typ": a, c;bye

Here specifically, the use case would be

#{{let x = 1}; 1+1} // without ;, it throws

In the parser, we would be at embedded_code_expr.

Because we are entering code block (Hash + LeftBrace), then the whole Brace is considered as one expression, hence the termination character ; is consumed at the end.
I don’t know if this might be considered a bug, but it is certainly an unexpected behaviour.

After this #{"..."}; there is text
1 Like