Hi all,
Some of us had previously discussed the possibility of taking MathML
seriously and enabling users who prefer it to skip KaTeX altogether. The
built-in XML support makes it possible to input MathML, but there have
been some obstacles to this being practicable (in addition to the
verbosity, which persists to some degree even if you wrap things in
macros). I have a feeling the verbosity can be solved and am actively
thinking about it, but the main show-stopping obstacle has rather been
the integration with LaTeX for rendering diagrams (e.g. tikz stuff).
Currently, the “TeXlike” content sent to KaTeX can equally well be
sent to tikz, and so things mostly just work. But if MathML was the base
format, there would be no TeXlike content to send to tikz; I thought for
some time about whether we could do things like convert the TeXlike code
to LaTeX (e.g. by doing an XSL transform on the fly) but I think this is
ultimately a bad idea, not to mention one that would be very hard to
implement in the Forester tool.
I realised something that could give us a way out: Context actually has
built-in support for MathML, and you can even dump MathML blobs into
ConTeXt code. ConTeXt supports tikz as well (though you have to be a
little careful with the syntax). But here’s an example of some ConTeXt
code that renders properly (with context --luatex):
\usemodule[mathml]
\usemodule[tikz]
\usetikzlibrary[cd]
\starttext
\starttikzcd
\XMLdata{
<m:math xmlns:m='http://www.w3c.org/mathml'>
<m:mrow>
<m:msup>
<m:mi>x</m:mi>
<m:mn>2</m:mn>
</m:msup>
</m:mrow>
</m:math>
}
\arrow[r]
\NC
\XMLdata{
<m:math xmlns:m='http://www.w3c.org/mathml'>
<m:mi>y</m:mi>
</m:math>
}
\stoptikzcd
\stoptext
I think that this is viable… Many users will prefer to use KaTeX +
LaTeX, but there is an amazing variety of more advanced kinds of content
we can support through direct use of MathML, and I think that advanced
users like myself would probably like to use it if we can make it
friendly enough. Given that the above resolves the main technical
problem, I think it is possible to start brainstorming how to facilitate
usable macro libraries for generating MathML code. I can imagine a
couple features that would be really useful, for example:
+ A way to take an XML attribute list as an argument in a macro and pass
it to a given XML element.
+ A feature that lets you write macros that automatically enclose
themselves in some XML element (e.g. to be able to write `\mi{foo}`
instead of `\math{\mi{foo}}` in various places).
Best,
Jon