KaTeX – The fastest math typesetting library for the web
katex.org
katex.org
1. Can be rendered server-side without a heavy runtime (ideally written in C/C++/Rust/Whatever instead of JS).
2. Has a well defined output AST, so that the output can be manipulated (e.g. realtime visual equation editing).
3. Is accessible to the visually impared.
Actually, we have such a system: MathML. And its a W3C standard to boot. The only reason why we have to rely on slow JS hacks like KaTeX and MathJax is because of Chrome. Google hates disabled people.
That's insanity. Sure, code is a nice addition, but it does not convey the same information as the math does.
It's akin to asking to replace an engineer's design of a bridge with a scale model.
As someone who hasn't actively done formal math in a couple of decades the slog of relearning syntax to read papers about code can be off putting. I understand that this makes me a barbarian. However code is really the lingua franca we use as an industry but in papers it is treated exactly as you say a nice addition.
No, because those aim to express the same thing, albeit with different limitations and practical considerations. Code and math are entirely separate things.
> As someone who hasn't actively done formal math in a couple of decades the slog of relearning syntax to read papers about code can be off putting.
Surely the syntax is an incredibly minor part of it all?
> However code is really the lingua franca we use as an industry but in papers it is treated exactly as you say a nice addition.
Code is an implementation detail. Papers express ideas, not implementations.
Edit: It's not being implemented by Google. It's a sponsored effort because Google couldn't be bothered. [2]
1: https://bugs.chromium.org/p/chromium/issues/detail?id=6606
<span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>g</mi><mi>a</mi></msup><mspace></mspace><mspace width="0.6666666666666666em"></mspace><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">d</mi></mrow><mtext> </mtext><mtext> </mtext><mi>p</mi><mo>=</mo><mi>A</mi></mrow><annotation encoding="application/x-tex">g^a\mod p=A</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.858832em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.664392em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">a</span></span></span></span></span></span></span></span><span class="mspace allowbreak"></span><span class="mspace" style="margin-right:0.6666666666666666em;"></span></span><span class="base"><span class="strut" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">m</span><span class="mord mathrm">o</span><span class="mord mathrm">d</span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathnormal">p</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathnormal">A</span></span></span></span>
This is: g^k\equiv a\pmod{p}If KaTeX were written in C, for example, it would be no problem FFI'ing it into just about any language. Plus whatever perf benefits there are of not using JS.
https://depot.traits.de/pages/2020/02/21-markdown-example.ht...
Bit of a sad situation, but then again HTML and CSS is not really the best layout language for this kind of stuff.
Commands supported in MathJax: http://docs.mathjax.org/en/latest/input/tex/macros/
Commands supported in KaTeX: https://katex.org/docs/supported.html
While the "aligned" environment is supported by both MathJax and KaTeX, the "align" environment is supported by MathJax only.
https://tex.stackexchange.com/questions/95402/what-is-the-di...
Debugging is horrible, syntax is unnecessarily verbose, formatting is hit or miss, portability is pure lottery, compiling is suuuper slow.
When I write text in an editor, it just works. Why for math do I have to spend all of these additional computing cycles?
I don’t have an alternative (if I had I would have started a company), I just know that I hated all of the hours I wasted formatting math manuscripts and I wish somebody could stand up and go against Knuth’s way of thinking.
Normal texts are a simple character list, so they are easy to input. Math equations are much more complex, with more symbols, 2D placement. So we need to 'mark up' the normal texts to provide enough information for a proper math equation.
Current machine learning can help translate hand-written equations into the one computer can understand, I think this can help a lot. However, if we want to use keyboard only, it still seems very hard to design a system that can input math as smooth as texts without 'mark up' or GUI.
That said, the fact is that for mathematical equation editing, for better or worse, TeX-based systems have a near-monopoly on high-quality typesetting; KaTeX giving us a fast, easy-to-use implementation of it is still a net good.
Sure one could come up with some markup language that would have an easier syntax for relatively simple cases (see e.g. the post a bit further down), but to actually support the complex formulas that latex supports we would quickly end up with something very similar to latex.
It is what you get when you have a genius like Knuth taking math typesetting seriously. To get something better, you need somebody similar sitting down and take another serious stab at it.
Afaik other *tex systems do it in the form of suites of tex macros, but no one really attempts to deviate from tex altogether
A better solution IMO is an alternate mathematical notation which can be simple and unambiguous not only for humans, but also computers. Something like apl - https://www.jsoftware.com/papers/tot.htm
And that is not limited to math type setting, it holds for normal text.
Also, automatic tocs, I ist, bibliography with biblatex/biber.
Error messages are improving using modern packages.
The biggest problem ist the complete absence of dependency management. TeX distributions break regularly and the require workarounds because some package introduced a breaking change.
Additionally, if equations are the the main appeal of it, how have we not made anything better? Why can't I plug the same code that renders my paper into a solver or convert it into Julia and run it? Like, properly, not just by guessing. I get that *tex is a typesetting language, but we're not typesetters!
I don't really see this as an issue. TeX is just a language that can be translated into PDFs for visual consumption well, but it could similarly be translated into audio or code (in the case of equations), we just can't do that because publishing TeX isn't something we do for some reason.
- latexmk knows how often it will need to compile a document in order to get all references right etc.
- pandoc lets you write markdown and converts it to LaTeX (although, if you have to write a lot if math you'll have to use LaTeX mode so often that it's worth considering whether that buys you anything... it's great for short, more textual documents that you want to format nicely though)
- XeTeX removes all the unicode and font problems and lets you actually include fonts on your system
- verbosity can be reduced somewhat by macros
But it's true. LaTeX kind of sucks (which is not really Knuth's "fault", since he only invented TeX and not LaTeX), the syntax errors can be very annoying (trying to hunt for that one missing paren or $...), packages constantly break other packages and totally absurd ways, and worst of all, the maths commands are entirely non-semantic (I've tried parsing maths expressions from LaTeX, it's not pretty), etc.
It's just that there is nothing better for maths right now, and even if there were, good luck fighting all the institutional inertia.
The MathML output is there, and that's all screen readers need to render math properly.
Although, to be honest I'd rather have support for something closer to LaTeX. MathML is incredibly verbose, and certainly not something you would want to write by hand.
<p>
The triangle inequality states that
<la-tex>z \leq x + y</la-tex>.
</p>
Disclosure: I am my self an author of an alternative library MathUp[2].I don’t think it is unreasonable to ask authors that insist on writing in familiar syntax, that they use a tool that enables that. With native MathML authors are free to use whichever tool chain they prefer. Some authors will prefer graphical editing of equations, so they have their authoring tools set up that way. Others will just want to write their familiar latex syntax so they’ll put a:
<script src="./path/to/texzilla.js"></script>
in their document and write as before.https://pub.dev/packages/flutter_tex_js
It’s hacky but it’s been working incredibly well.
What's needed is version of the underlying TeX engine that is HTML-aware. This way, a multipage document could be complied as usual, say to be printed or displayed as a static PDF, or it could be compiled to a web-friendly format for display in a browser, with links, etc.
Ex: $$ c = \pm\sqrt{a^2 + b^2} $$
Or, multiline $$ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } } $$
Some details are available [in this post](https://talk.hyvor.com/blog/introducing-katex-embed/) on how it works.
And, katex.renderToString has an option to set throwOnError: false.. So, whenever if the TeX code inside $$ is not valid, it just returns the text.
I have $3. $$\frac{3}{2}$$