texlab
texlab copied to clipboard
Math equations preview
Hi, do you consider using KaTeX for rendering equation preview? https://katex.org/ https://github.com/KaTeX/KaTeX This looks like an extremely fast approach.
Thanks for the suggestion. I am aware of KaTeX but there is one major limitation that prevents the usage: KaTeX renders to HTML and HTML is not officially supported by LSP so most clients cannot show the rendered formulas. An alternative could be SVG output and embedding the SVG file in a Markdown image but KaTeX does not offer SVG output.
MathJax could work but it is very painful to embed. Besides that, all of those approaches require a JS engine: v8 is extremely large, Duktape does not support everything required and QuickJS does not run on MSVC.
I am afraid that there is no good option at the moment to render math equations. Previously, we used the TeX engine and dvi2png to render equation previews but this approach was too fragile and slow.
Dear Patrick, many thanks for your valuable work! It is as a pity that KaTeX is not suitable due to its limitations. However let me mention that as far as i know MathJax is used for hover preview in LaTeX Workshop extension for VSC. Maybe their implementation might be of some help for your project? Their preview speed is acceptable, in my opinion, but subpar to that in LaTeXTools (Sublime). I am not aware of which approach is used in LaTeXTools, though.
Thanks for the kind words. Providing hover preview on the client is much easier. In the case of VSCode, we already are in a JavaScript/Node context so MathJax works just fine. However, in the server, the implementation needs to support all clients and a lot of clients do not run in a Node environment so there is no benefit to adding a huge dependency if only a small number of clients benefit from it. Instead, it would be better to let the clients implement this feature (maybe with additional help from the server to reliably detect math fragments). For VSCode, I can add this feature to the extension.
Would it be easier to embed a web-assembly evaluator? This project is a port of a tex engine to web-assembly. It might possibly be useful: https://github.com/kisonecat/web2js
@siefkenj
Would it be easier to embed a web-assembly evaluator?
We could also embed tectonic but it would need to be run in a separate process because of potential infinite loops when encountering broken documents (same thing with WebAssembly). But one problem remains: how to display the generated output in the hover request. The PDF/DVI file needs to be rasterized before-hand and embedded into the markdown file. Unfortunately, embedding a PDF rendering library is another huge dependency.