-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX math rendering in Markdown blocks #8
Comments
Working prototype: import handout
doc = handout.Handout('handout')
doc.add_html('<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>')
"""
$$f(x)=\int x^2 \ \mathrm{d}x$$
"""
doc.show() |
Great to hear. It works well for me, too. I want to include a local copy of the MathJax script by default, so that users don't have to add the line and the handout also renders correctly without internet access. Feel free to create a PR for it if you have a chance. |
@danijar I am interested in solving this issue. I have this workflow in mind:
is this workflow fine? if you think we can do something else in here, please do suggest. |
Thanks! How about just bundling a copy of MathJax the same way the other scripts are bundled? I think updating it every now and then is easy enough and would keep the dev workflow easier and code complexity lower. Users should definitely not have to install anything manually to get MathJax support. In other words, a light Python package is fine to add as dependency, but requiring users to have a node package manager is not. |
Having LaTeX math in Markdown blocks is nice, having Latex math generated by Python code is even nicer because you can present the output of calculations in what is (sometimes) the most appropriate format, i.e., a nicely formatted mathematical notation.
in Handout maybe |
@danijar mathjax script is bundled as a zip and upon extraction all the files size to ~69 MB, is there any way I can minify it, since it will become an overhead upon copying it from data dir to output dir, also it makes handout slow. |
That's more than I expected. Do you know how KaTeX compares? |
KaTex is really small in comparison ~3.2MB , I am still finding a way to make it work locally as for some reason even it's CDN script doesn't work on my end. |
KaTeX requires including a style file and initializing it by calling a JavaScript function as far as I know. |
I played around with including KaTeX but it seems to not play as nicely with our Markdown renderer For now I added MathJax from the CND in the latest release to cover the most common use case. Looking around it seems possible to create a more lightweight distribution of MathJax to bundle with Handout, which would be great to include in the next/a future release. |
@danijar yes, even I was playing around with KaTex but the results were not satisfactory for me, even when I managed to somehow get KaTex working, it still didn't render the fonts nicely. |
Thanks for also taking a look. Yes, let's leave this open. It would be great to bundle a stripped down version of MathJax because I think it can be frustrating to users if their document suddenly doesn't render anymore when they're offline. I think the browser cache could mitigate this a bit, but relying on that seems risky. If you're interested, it'd be great if you could look into how small we can get a local version of MathJax. There seem to be a couple of tools that people wrote to minify and strip away unnecessary parts of the MathJax repository. |
sure, I will take a look into it. |
KaTeX and MathJax seem like great options.
Current status: LaTeX is included by default now. However, it is loaded from a URL and we are working on bundling a local copy with the package for offline viewing.
The text was updated successfully, but these errors were encountered: