#Settings the `margin`s to 0 in SVG Export

63 messages · Page 1 of 1 (latest)

olive matrix
#

Hello! I'm experimenting with making a Typst inline math previewer for Emacs just like org-latex-preview and co.
I decided that the output format be svg so that I can easily open view it in Emacs. Since the images are to be viewed inline, i also set the following page show rules

#set page(width: auto, height: auto, margin: 0pt)

However, I noticed that certain previews were "cut-off". e.g. for the code

#example[
  Express the function $f(t) = cases(20t & 0<=t<5, 0 & t>=5)$
  #solution[$f(t) = 20t(1-heaviside(t-5))$]
]

I confirmed it with Firefox that the .svgs produced were "clipped". It seems to only happen only in inline math fragments, not the display math fragments.

lethal spindle
#

Settings the margins to 0 in SVG Export

#

Hello @olive matrix , do you mind providing a MRE (minimal reproduction example) so others can test it locally? Thanks!

#

In principle, I don't see any obvious causes for the problem, but messing a bit with it could be insightful.

olive matrix
#

Sure, I can send in the generated preview .typ file's contents

#set page(width: auto, height: auto, margin: 0pt)

$m(t) = cases(20t quad & 0<=t<5, 0 quad & t>=5) $

Note that it's inline math, display math doesn't reproduce the same issue

lethal spindle
#

ah.

#

I don't think inline math handles height very well

#

?render ```

Text text text text text text text
text $x + cases(20t, 40t, 30t)$ text text text
hello world!

agile lichen
#

certainly reproducable in the web app which also uses svg for preview

lethal spindle
agile lichen
#

oh

lethal spindle
#

however the typst preview vscode extension uses svg

agile lichen
#

well in any case, webapp has same problem

lethal spindle
# wooden whale

well interesting, i was expecting the cases to go above the text or something

#

so let's just test the given code directly

lethal spindle
#

like $... $

#

usually it's either $...$ (for inline math) or $ ... $ (for display math)

olive matrix
#

The issue is exacerbated in Emacs because the svgs are interleaved with the buffer text

olive matrix
lethal spindle
#

?render

#set page(width: auto, height: auto, margin: 0pt)

b $m(t) = cases(20t quad & 0<=t<5, 0 quad & t>=5) $ a \
c
lethal spindle
#

okay

#

interesting

#

lol

#

so

#

seems like u need a bit of margin

agile lichen
#

ig inline math might try to use the text height as its height for the page, therefore clipping stuff when there are no margins?

inner sandal
#

i wondering what is the default margin?

#

seems that 0pt and auto both produce bad result🤔

olive matrix
#

Case in point, this would get padded out

#

Oh, yeah that preview example exhibits another bug, fractions don't display correctly in Emacs, nor Inkscape. But that's better left for another "issue"

inner sandal
#

how about chrome or ff

olive matrix
#

It's normal in Firefox

inner sandal
lethal spindle
agile lichen
#

?render

#set page(width: auto, height: auto, margin: 0pt)
#show math.equation.where(block: false): pad.with(0.5em)

$m(t) = cases(20t quad & 0<=t<5, 0 quad & t>=5)$
olive matrix
agile lichen
#

yea idk either tbh

olive matrix
#

?render

#set page(width: auto, height: auto, margin: 0pt)
#show math.equation.where(block: false): pad.with(0.5em)

$m(t) = cases(20t quad & 0<=t<5, 0 quad & t>=5, 0 quad & t>=5, 0 quad & t>=5, 0 quad & t>=5)$
olive matrix
#

Seems like it, lemme try it in emacs

agile lichen
#

you can also just pad on the y-axis, the left and right one seemed fine i think

agile lichen
#

nice

lethal spindle
#

?render

#set page(width: auto, height: auto, margin: 0pt)
#show math.equation.where(block: false): pad.with(top: 0.5em, bottom: 0.5em)

$m(t) = cases(20t quad & 0<=t<5, 0 quad & t>=5) $
lethal spindle
#

seems like its exactly 0.5em

olive matrix
#

Even the absurdly tall line.

agile lichen
olive matrix
#

Also, one question. Is it normal for typst to not rename the extension when you choose the export format?

#

I compile with typst compile -f svg ./test.typ and get a test.pdf that is actually a svg (typst v0.8)

lethal spindle
#

-f svg you mean?

#

yea so

#

that was fixed already on main

#

so the fix will be out on 0.9

olive matrix
#

So for now i could just specify typst compile test.typ test.svg and it would work?

lethal spindle
#

yes