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
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.