Turn the HTML-ish string s that can have \$\$ and \$'s in it into
pure HTML. See below for a precise definition of what this means.
INPUT:
- ``s`` -- a string
OUTPUT:
A :class:`HtmlFragment` instance.
Do the following:
* Replace all ``\$ text \$``\'s by
``<script type="math/tex"> text </script>``
* Replace all ``\$\$ text \$\$``\'s by
``<script type="math/tex; mode=display"> text </script>``
* Replace all ``\ \$``\'s by ``\$``\'s. Note that in
the above two cases nothing is done if the ``\$``
is preceeded by a backslash.
* Replace all ``\[ text \]``\'s by
``<script type="math/tex; mode=display"> text </script>``
It's worth paying attention to the fact that Mathjax 3 is missing a significant feature that might be really critical for Sage, which is "automatic line breaking". See the discussion here:
https://github.com/mathjax/MathJax/issues/2312#issuecomment-692695446
E.g., "So line breaking and other features will most likely have to wait until next year." "That's the reason why nearly nobody is using MathJax? 3." etc.
I think this is very important to be aware of, and it's one reason why CoCalc? doesn't use MathJax? 3, and uses KaTeX by default. For some applications automatic line breaking probably isn't so important, but it might be very important for Sage, due to people often printing out polynomials and big formulas.
I don't understand where MJ enters into the processing when the Sage Cell is
used. Earlier, I looked at the page source for the primary Sage Cell demo page,
thinking I might see it being loaded there (thinking I'd see MJ2).
So I don't understand how/why the MJ3 loaded into a page produced by PreTeXt
seems to "take over." At least that seems to be the case, given that adding
support for the "script" element made the original example render properly, and
that the html() construction clearly creates a "script" element in vanilla Sage
(independent of the Cell server). Perhaps "pretty_print()" runs MJ server-side
for the Sage Cell server? Which still would not explain everything to me.