fenjalien / obsidian-typst

Renders typst code blocks in Obsidian into images using Typst through the power of WASM!
Apache License 2.0
336 stars 16 forks source link

math in titles #39

Closed joleeee closed 8 months ago

joleeee commented 10 months ago

when using typst in titles, it's not rendered as big as it should be

# Big Theta - $Theta$

Text:

image

Rendered:

image
fenjalien commented 10 months ago

Not sure if this really is a bug or working as intended. Math blocks have no context of where they are, so extra styling is incredibly difficult to apply. We could get more context by using a codemirror extension but I haven't found a way to completely stop Obsidian's own math blocks.

joleeee commented 10 months ago

i mean the built in latex math blocks work fine in titles so i definitely think this is a bug

Enter-tainer commented 9 months ago

Not sure if this really is a bug or working as intended. Math blocks have no context of where they are, so extra styling is incredibly difficult to apply. We could get more context by using a codemirror extension but I haven't found a way to completely stop Obsidian's own math blocks.

Hi I'm doing similar thing last week(rendering typst to svg and embed them in markdown). To solve this you need to adjust the svg: by changing the unit of its height and width to em, the svg will automatically scale itself according to the font size.

Code here: https://github.com/Myriad-Dreamin/typst.ts/blob/main/projects/rehype-typst/lib/index.js#L116

And this is how it looks like image

Enter-tainer commented 9 months ago

Also I see currently the css is set to

.typst-doc {
    vertical-align: bottom;
}

There can be better control of this by querying the location of text baseline in typst and set vertical-align according to it.

Enter-tainer commented 9 months ago

I guess the optimize svg thing is no longer needed too because currently typst use a stable id to name glyphs so there is no collisions now.

joleeee commented 9 months ago

I guess related is:

some vec $vec(1,2,3)$.

renders as

image

meawhile without the plugin this

some vec $\begin{pmatrix}1\\2\\3\end{pmatrix}$.

renders as

image
fenjalien commented 8 months ago

As of version 0.9 the output SVG's size is in em which should scale with the font size of the line it is on including headings. This does highlight another issue of the base line but that should be discussed in a new issue.

I guess related is:

some vec $vec(1,2,3)$.

...

@joleeee This is related to #17, please discuss it there