siefkenj / unified-latex

Utilities for parsing and manipulating LaTeX ASTs with the Unified.js framework
MIT License
91 stars 24 forks source link

Rendering the ast with katex #126

Closed Mw3y closed 1 week ago

Mw3y commented 1 week ago

Hello 👋🏻!

I'm currently trying to parse some latex content, process the tree and render it. In the source code of the hast module I could see some content related to katex but couldn't figure out how to use it to render something. Could you give me some guidance/examples please?

PS: Amazing project! Thank you for developing it!

siefkenj commented 1 week ago

Try looking in the html conversion code. Also, you can look at https://github.com/siefkenj/latex-parser-playground for an example using the generated HTML with katex.

Mw3y commented 1 week ago

Thank you very much! I also have another question: while trying out the hast plugin, I noticed that \LaTeX for example is being translated to macro-LaTeX. It looks like the content is lost. Is there any workaround to still get the it so as to render it using katex?

siefkenj commented 1 week ago

Any unrecognized macros are converted that way. KaTeX will only handle math. You can do $\LaTeX$ to activate math mode if you want KaTeX to render it.

Mw3y commented 1 week ago

Is there a way to automatically toggle math mode for a set of macros?

siefkenj commented 1 week ago

You can do a replaceNode and wrap them in math if you like.

Mw3y commented 1 week ago

Thank you very much!

One last question: I'm trying to render a latex file using vuejs render functions. I'm thinking of using the "hast" representation as a basis for rendering. What do you think about that? Since I'm discovering your project I'm wondering if this is the best way to do it.

siefkenj commented 1 week ago

Check out https://github.com/rehypejs/rehype-react

Mw3y commented 1 week ago

Alright thank you very much!