Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

Use KaTeX instead of MathJax

Open fonsp opened this issue 2 years ago • 1 comments

This PR uses KaTeX to render LaTeX math inside markdown instead of what we currently use: https://www.mathjax.org/

Pros:

  • Allow offline support for latex. Right now this is difficult because MathJax loads additional JS/CSS files dynamically, which are not caught by our bundler.
  • Reduce our (web) asset size by about 1MB. But because we already have https://github.com/fonsp/Pluto.jl/pull/1947, this should not change page load time
  • Maybe improve loading/rendering speed,
  • Fix #1500, fix #1801 because we can use an ES6 import
  • KaTeX has a really clean implementation of #1460 that is based on CSS counters, so it magically updates equation numbers when changing the notebook.
  • I was able to get \label and \ref working with https://github.com/KaTeX/KaTeX/issues/2003#issuecomment-843991794 . In general, KaTeX seems more flexible and open to mods (https://fonsp-disorganised-mess.netlify.app/katex%20fun.html)

Cons:

  • KaTeX has different LaTeX support than MathJax, and some things will not work anymore. Searching online, it looks like the support differences are relatively minor, but it will break something.

TODO:

More tests:

  • [ ] try running some community notebooks
  • [ ] computational thinking notebooks
  • [ ] our sample_test_1 notebook
  • [ ] mchem

Misc:

  • [ ] Tweak font size
  • [ ] Nicer copy-paste: https://github.com/KaTeX/KaTeX/pull/3586
  • [ ] MarkdownLiteral.jl

fonsp avatar Mar 21 '22 11:03 fonsp

Try this Pull Request!

Open Julia and type:

julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/fonsp/Pluto.jl", rev="katex")
julia> using Pluto

github-actions[bot] avatar Mar 21 '22 11:03 github-actions[bot]

Chrome 109 (early 2023) will include native support for MatML Core (https://chromestatus.com/feature/5240822173794304), which means that all major browser will support it soon! That might mean that we can use an even smaller/faster JS library (like https://temml.org/ ), or we could even do the latex -> mathml conversion server-side, and use no library at all.

fonsp avatar Dec 29 '22 17:12 fonsp

We shouldn't switch to KaTeX because it supports fewer characters/features of LaTeX that people are now expecting to work. MathJax also seems to take more care about accessibility than KaTeX.

It looks like MathJax is working on a 4.0 release which might fix the two plotly bugs (because ES6 modules are loaded in isolation).

fonsp avatar Oct 30 '23 15:10 fonsp