Inline math output to SVG with 0 margin is not cropped propertly

My sample Typst file is as follows:

#set page(width: auto, height: auto, margin: 0pt)
$union.big_(a in A) X_a$

When compiled using the following command:

typst c -f svg test.typ 

The resulting svg is cropped too much:

image

If I change the Typst code so that the math part is displayed on a separate line:

#set page(width: auto, height: auto, margin: 0pt)
$ union.big_(a in A) X_a $

and compile it with the same command, then the output is:

image

Is there anyway to make inline math also cropped properly? Though I can manualy change the margin value so that the desired content is not cropped, but this is not practical because the margin value depends on the font size, and I do not want to change the margin value every time I change the font size.

Inline math content by default uses “fake” boundaries so that the line spacing in paragraph remains consistent. For cases like yours, where you don’t need that consistency, you can explicitly tell Typst to use the “real” boundaries via the show-set rule

#show math.equation: set text(top-edge: "bounds", bottom-edge: "bounds")
2 Likes

Thanks. This perfectly solves my problem!