MathJax: Beautiful and accessible math in all browsers
mathjax.org
mathjax.org
Common mistakes that other people make when using an image-based approach include:
* failing to apply the proper sizing and offset for the baseline * using a raster PNG format which is bigger and looks fuzzy
Math ML is much more than alt text. It presents mathematical expressions in a hierarchical, tree-like way, letting you explore parts of the expression in detail. Depending on the implementation, you may also be able to adjust the verbosity or render the expression in Braille using one of a few different math codes.
If you want accessible math, just alt text is not enough.
It's a very powerful authoring and publication system, for example if you're writing an interactive Math book, you could use <sage/> blocks to specify language e.g. Python, write around code blocks, providing references to equations, etc [3].
Fun facts, PreTeXt was originally called MathBook XML thus it has robust support for mathematical formulas [4],[5].
Last but not least, don't let XML being used in Pretext scared you off since XML is great for markup language and anything todo with publication online, printed, Braille, etc [6].
[1] PreTeXt Write Once, Read Anywhere:
[2] PreTeXt: Write Once Read Anywhere Authoring and Publishing System:
https://news.ycombinator.com/item?id=37231025
[3] The PreTeXt Guide: 3.17 Sage:
https://pretextbook.org/doc/guide/html/overview-sage.html
[4] The PreTeXt Guide: 4.9 Mathematics:
https://pretextbook.org/doc/guide/html/topic-mathematics.htm...
[5] The PreTeXt Guide: Chapter 13 Mathematics
https://pretextbook.org/doc/guide/html/basics-ch-math.html
[6] XML is better than YAML – Hear me out:
* Right-click > copy copies the image itself
* Highlight the image, then Right-click > copy gives you the alt text
MathJaX had a good run, they did a good job, I would say their job is done however.
1. [Input] Even if only targeting MathML output, you still need some way to take the user's TeX input and generate MathML, which is what MathJax provides here. What are the alternatives to MathJax that you have in mind? The closest competitor I'm aware of is KaTeX, and while it is fast when it works, there are still some holes in its support (relative to MathJax). (Another comment in this discussion points out Temml, which indeed looks good: https://temml.org https://github.com/ronkok/Temml https://temml.org/docs/en/comparison.html )
2. [Output] The MathML output rendering in browsers is not yet 100% identical to TeX's typesetting (they're certainly aware of it / thinking of the right things, looking at the mentions of [TEXBOOK] at https://w3c.github.io/mathml-core ), and this may even be intentional. In particular, looking at various MathML demo pages I found online (http://eyeasme.com/Joe/MathML/MathML_browser_test.html https://fred-wang.github.io/MathFonts/mozilla_mathml_test https://www-archive.mozilla.org/projects/mathml/demo/texvsmm... and Temml's useful demo pages: https://temml.org/tests/wiki-tests https://temml.org/tests/latexml-tests https://temml.org/tests/mozilla-tests) it appears that in all three of Chrome/Firefox/Safari the rendering of nested square roots is a bit suboptimal, while Safari has some more serious issues (example 9 of the Mozilla MathML Test looks poor in Safari). But clearly the Igalia (for Chrome) and Mozilla folks have done great work, and it's pretty close, but in the meantime I imagine at least some authors would prefer the more deterministic (across browsers) output of SVG or HTML+CSS.
(Also, on a lot of these MathML demo pages, selecting and copy-pasting the math produces junk, while with MathJax there's a right-click menu providing the TeX source and also some accessibility options… it seems that accessibility is actually higher with MathJax under certain circumstances at least.)
<la-tex>x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}</la-tex>
In my own mathup library I have a similar functionality: <math-up>x = -b+-sqrt(b^2 - 4ac) / 2a</math-up>
For MathJax to continue staying relevant it should probably do something similar (note that it is not that hard [1]).As for the output. This is in large part due to the font being used. The default math font for me using firefox on ubuntu is indeed rather ugly. If you want something similar to the TeX output you can simply use the TeX-Gyre font face. In my documentation for mathup[2] I use Libertinus Math, which pairs very nicely with the other font faces on the page (Libertinus and Libertinus Mono). Aside: here is another example of why MathML is a superior target output then HTML+CSS as you actually have control over the font face.
And finally, as for the copy-pasting. You can download numerous browser add-ons that make copy-pasting formulas as easy as MathJax’s. I will admit this is a handy feature of MathJax, and if you want user to be able to copy-paste your expressions while not assuming they will download an add-on to do so, then MathJax is probably your number 1 choice.
1: https://github.com/mathjax/MathJax/issues/2292#issuecomment-...
2: https://runarberg.github.io/mathup/ - Note, I haven’t updated the software to target the newer MathML Core, so many expressions will not work in Chrome. You should definitely use MathJax over my library.
From what you're writing I'm not entirely sure you think MathML has good or bad readability then ;)
But in case you don't find MathML's presentational syntax convincing for authoring, you can pickup SGML shortref syntax (a technique even older than MathML itself [1]) for at least eg. a highscool math subset in order to cut down on excessive <mo>, <mi> tags.
I actually don’t like writing MathML, and I actually wrote a library my self that targets MathML.
I'd say the opposite: now we can safely use MathJAX to translate TeX syntax to an efficient rendering representation.
If you want to write LaTeX and include the equivalent MathML in your webpage, then something like Temml is a lot better choice, as that is it’s primary function.
(insert starcraft "about time" meme)
That said, I think MathML Core is an excellent standard, and Chrome made the right choice to support it (or rather to allow Igalia to develop it for them). Going forward I’m certainly going to update my library to target MathML Core only.
For example MathJax!
MathJax v3.2.0 - https://news.ycombinator.com/item?id=28155836 - Aug 2021 (1 comment)
MathJax - https://news.ycombinator.com/item?id=24741077 - Oct 2020 (42 comments)
MathJax: Beautiful Math in All Browsers - https://news.ycombinator.com/item?id=23286761 - May 2020 (2 comments)
MathJax Turns 3.0 - https://news.ycombinator.com/item?id=22582343 - March 2020 (34 comments)
MathJax CDN shutting down on April 30, 2017 - https://news.ycombinator.com/item?id=14074689 - April 2017 (75 comments)
MathJax 2.0, probably the nicest way for showing/writing math on the Web - https://news.ycombinator.com/item?id=3720516 - March 2012 (4 comments)
MathJax: Math just works on the web now - https://news.ycombinator.com/item?id=2455698 - April 2011 (4 comments)
MathJax, beautiful math in all browsers - https://news.ycombinator.com/item?id=1974646 - Dec 2010 (36 comments)
MathJax: convert LaTeX to HTML on the client - https://news.ycombinator.com/item?id=1034480 - Jan 2010 (3 comments)
Mathjax - https://news.ycombinator.com/item?id=997096 - Dec 2009 (34 comments)
Because every math extension seems to fail the one great feature of markdown: that when I view Markdown as plain text, it's still really legible and the amount of noise added by the markup is minimal, especially if you use the "underline with hyphens" syntax for headings.
Like, every time I see backslashes they're just distracting if I'm trying to read it raw.
Like is there any math format where the Quadratic Formula is just
-b ± √(b² - 4ac)
x = ----------------
2a
Obviously I'd expect something like this to be the output after running the text file through a formatter, just like how in Markdown it's common to reformat things as you go because they're hard to type manually.Like with Markdown Tables.
Tables are extremely difficult to type in MD, and should never be done manually, right?
Basically, here's how you do tables in markdown:
First, you do them the wrong way, half-assed.
| Header1 |Header2 |Header3 |
|-|-|-|
| BodyRow1 Cell1 | Cell2 |Cell3|
| BodyRow2 Cell1 | Foo |Bar|
which looks like crap, right?then you run them through a formatter and you get
| Header1 | Header2 | Header3 |
| -------------- | ------- | ------- |
| BodyRow1 Cell1 | Cell2 | Cell3 |
| BodyRow2 Cell1 | Foo | Bar |
which looks nice, right?And then it becomes a real table when you convert your Markdown into Html/Pdf/Docx/whatever.
That's what I was wondering if there's anything similar for math.
Like, the way I'd type the Quadratic Formula would be
x = -b +- sqrt(-b-4ac)) over 2a
but when I run it through the code formatter, I'd expect to get cleaned up the same way my table did. -b ± √̅(b² - 4ac)
x = ————————————————
2aLaTeX notation lets you type math without the ambiguity of parsing text. And you can render a lot of it in Unicode (See Unicodeit.net).
I would not want to type math in markdown notation due to loss of fidelity. Also LaTeX is like SQL: it’s there, everybody knows it, and it works. Any effort to displace it will end up reinventing it badly imho.
> I wonder if that would limit you to the very simplest of ~~math~~markup.
> ~~LaTeX~~HTML notation lets you type ~~math~~markup without the ambiguity of parsing text.
> I would not want to type ~~math~~markup in markdown notation due to loss of fidelity. Also ~~LaTeX~~HTML is like SQL: it’s there, everybody knows it, and it works. Any effort to displace it will end up reinventing it badly imho.
I mean the lack of Unicode support for superscripts would basically make this futile, but then you could say the same about the extreme limitations of Markdown tables.
edit: I forgot that HN doesn't support markdown strikethroughs. You get the idea.
x = -b +- sqrt(-b-4ac) / 2a
would actually put the -b ± part in front of the fraction: x = -b+-sqrt(-b-4ac) / 2a
works as intended, as does: x = (-b +- sqrt(-b-4ac)) / 2a
I haven’t touched it for a minute and it is does not fully support MathML 4, meaning there are expressions which cannot be read properly by chrome. I was always going to revist this at some point but time is hard to find.If you're not much of a Unicode person, you can write this:
$ x = (-b plus.minus sqrt(b^2 - 4 a c))/(2a) $
If you're more of a Unicode person, you can write this, and it means the same thing AFAICT:
$ x = (-b ± √(b^2 - 4 a c))/(2a) $
You can also put newlines in this, and it works just fine:
$ x =
(-b ± √(b² - 4 a c))
/
(2a)
$
Both ± and √ have been on Mac keyboards, if you hold down the Option key, since probably 1984. Using ² instead of ^2 doesn't give me the same output, though.A Typst Unicoderator could make this transformation for you, but I don't think one's been written yet. An automatic linebreaker à la Prettier sounds like an even more difficult challenge.
There's UnicodeMath, defined at <https://www.unicode.org/notes/tn28/UTN28-PlainTextMath-v3.2....> and <https://unicodemath.org> says there's a UnicodeMath to MathML converter at <https://github.com/MurrayIII/UnicodeMathML/tree/main>. All UnicodeMath seems to get you over Typst in this instance is superscript support.
┌──────┬───────────────┬───────────┐
│ It's │ occasionally │ useful │
├──────┼───────────────┼───────────┤
│ for │ HackerNews │ comments │
└──────┴───────────────┴───────────┘This is similar to how pre-wrapped text often looks terrible on mobile. This is an issue with plaintext email, for instance. [0]
[0] https://lists.sr.ht/~sircmpwn/public-inbox/%3C87wo85l3c5.fsf...
So this is not monospaced,
but this text that is indented with 4 spaces is monospaced
so I can easily align words. Two spaces is all you needAnyway, if you like the idea of using way too much Unicode, I've been working on an esoteric document format proposal, 'Utext', for using exclusively Unicode in text files for complicated typography. Seems like Unicode is so enormous these days that you can do quite a lot: https://gwern.net/utext
For most mathuses in blog posts KaTeX is going to provide a bettter user experience, but if you want to put a math paper on a webpageMathJax is the way to go.
[1] https://docs.mathjax.org/en/latest/input/tex/extensions/inde...
(MathJax's output formats, namely HTML+CSS, SVG, MathML — see https://mathjax.github.io/MathJax-demos-web or https://docs.mathjax.org/en/latest/output/ — are strictly a superset of KaTeX's output formats, namely HTML+CSS and MathML: https://katex.org/docs/options.html )
I'm happy with the way it looks. I'd used KaTeX over MathJax previously because I found it rendered pages faster.
I've been meaning to look into KaTex. Could you elaborate on why you switched away from it? KaTeX appears to support server-side rendering already, in the sense that it generates plain HTML.
I started using KaTeX sometime after 2015 because it promised to be fast (the fastest! [1]). I had to change the representation of a bunch of expressions because KaTeX didn't support some environments, whilst MathJax did. It was a trade-off I was willing to accept at the time.
Many years later, I started writing a personal static-site generator. I wanted comparatively lightweight pages, so rendering server-side was an option. I re-evaluated MathJax vs KaTeX again and this time I leaned towards MathJax, as speed was no longer an issue for me. It looks like KaTeX has broader support now [2].
- "This is important, since several math-based instances exist (such as https://mathstodon.xyz ,https://types.pl) and produce math-based posts. However, when these posts federate to other instances they cannot be rendered, since other instances do not have MathJAX installed. Thus, a more portable version based on open standards is necessary."
Edit: Don't want to send negative vibes toward MathJax. They do great work. Just think it would have been better if google didn't decide "no, the web shall not have native math rendering".
Edit2: Didn't know chrome supported MathML now.
It doesn't help with ChatGPT hallucinating and generally being poor about math/stats related queries, but it does make things a good bit more readable!