Previous post May 3, 2025 at 11:25 AM by Dr. Drang Since switching from MathJax to MathML to render equations here on ANIAT, I’ve tried several approaches to generate the MathML. There are many utilities and libraries that claim to do the conversion, but I’ve found all of them to be limited in one way or another. For a while, I was even writing MathML directly, albeit with the help of some Typinator abbreviations, because I couldn’t trust the converters to generate the correct characters or even understand some LaTeX commands I use regularly. Recently, I began using what I should have started out with: Pandoc. It’s not that I wasn’t aware of Pandoc. Its famous in the Markdown/HTML/LaTeX world, and I probably first heard of it shortly after its release. But I’ve always thought of it as a document converter, not an equation converter. I was wrong. It’s very easy to use with a single equation. pandoc --mathml <<<'$$T = \frac{1}{2} v_x^2$$' produces <p> <math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> <semantics> <mrow> <mi>T</mi> <mo>=</mo> <mfrac><mn>1</mn><mn>2</mn></mfrac> <msubsup><mi>v</mi><mi>x</mi><mn>2</mn></msubsup> </mrow> <annotation encoding="application/x-tex"> T = \frac{1}{2} v_x^2 </annotation> </semantics> </math> </p> where I’ve added linebreaks and indentation to the output to make it easier to read. Because it’s delimited by double dollar signs, the equation is rendered in block mode, like this: T=12v2 Single dollar signs would generate MathML with a display="inline" attribute. (If you look at the source code for this page, you’ll see that I usually delete some of the code Pandoc generates—we’ll get to that later.) All the converters handled simple equations, like v02, well, but more complicated stuff can be troublesome. One of the problems other converters have is dealing with multiline equations, something Pandoc handles with ease. For example, this piecewise function definition, $$ f(x) = \left\{ \begin{array} {rcl} -1 & : & x<0 \...
First seen: 2025-05-03 18:45
Last seen: 2025-05-04 04:47