I am new to Observable, and find it not only very intuitive to use but also suitable to almost my everyday experiments on the Web. In addition, it is also comfortable for me to write notes on Observable, some of which contains mathematics formulas. In Observable standard library, there is a template literal, tex, that can be used to typeset some LaTeX expression powered by KaTeX. KaTeX is extremely fast to render beautiful math formulas, but I often write formulas and find KaTeX does not support it (yet). An alternative package that most mathematics website use is MathJax, and I personally use it whenever available. Here is my attempt to make MathJax work in an Observable notebook:
Some caveats are:
MathJax is not a regular module AFAIK. I have to suppress the āinvalid moduleā error and use its injected variable MathJax in the catch block.
It seems that the trailing config=TeX-AMS_CHTML is mandatory. Thatās why I load the JS file via an URL. Not using unpkg because it often timeouts or generates 503 .
It is not reactive, which means if you edit and save a cell, it will not get transformed. Maybe I need to roll up a template literal by myself to hook the typeset process after output.
In this notebook, I write mathematics strings along with markdown contents. This is OK when there is only HTML cells, but is not ideal in other cases, for instance, some tokens used in LaTeX may conflict to Markdown syntax. I am trying combining it with a tokenizer.
I am not very familiar to techniques of Observable, so I kindly ask for recommendations for improvements on this notebook on its usability. Thanks!
Your help request is really thoughtfully written, and from it I imagine that you have a great deal more technical knowledge than do I, so I fear I am going out on a limb somewhat with this response. Please forgive me if this is stuff you know or have triedā¦
Have you seen Tomās module debugger tool? You mentioned not wanted to reference the JS from unpkg, but I think Tom offers alternativesā¦ perhaps one require option is more stable?
This should make mathjax sections properly reactive. This is not as elegant as Iād hoped because MathJax requires the target element to be in the document in order to typeset it, but alas, it does work
Also ports our tagged template literal trick to let you type MathJax equations without having to escape the \s.
EDIT: I now notice that it doesnāt work on load, only when I re-run the mathjax cellsā¦ Iām not sure why this is, looking into it!
Just want to mention that I have built a free service, MathEquationAPI, that makes doing this much simpler. Basically, it renders the equation when you pass it in the query params.
So, Instead of loading javascript, you can directly embed the equation image. Just like I have done here:
This looks fun! I forked your notebook and did some fine tuning and extension. You can have a look here:
While this is Observable specific, some of the ideas work more generally in simple HTML. I would definitely consider setting vertical-align: text-bottom as a style directive for your image, for example.
Feel free to incorporate any of that stuff into your notebook, if you like.
Thank you! I didnāt even see the benefits you listed. My primary motivation to build this was to make it easier to include equations. Certainly, it can all be done with MathJax as well.