The failings of low-end consumer software, to typeset Math as (HTML) MathML.

One of the features which HTML5 has, and which many Web-browsers support, is the ability to typeset Mathematical formulae, which is known as ‘MathML’. Actually, MathML is an extension of XML, which also happens to be supported when inserted into HTML.

The “WiKiPedia” uses some such solution, partially because they need their formulae to look as sharp as possible at any resolution, but also, because they’d only have so much capacity, to store many, many image-files. In fact, the WiKiPedia uses a number of lossless techniques, to store sharp images as well as formulae. ( :1 )

But from a personal perspective, I’d appreciate a GUI, which allows me to export MathML. It’s fine to learn the syntax and code the HTML by hand, but in my life, the number of syntax-variations I’d need to invest to learn, would be almost as great, as the total number of software-packages I have installed, since each software-package, potentially uses yet-another syntax.

What I find however, is that if our software is open-source, very little of it will actually export to MathML. It would be very nice if we could get our Linux-based LaTeX engines, to export to this format, in a way that specifically preserves Math well. But what I find is, even though I posses a powerful GUI to help me manage various LaTeX renderings, that GUI being named “Kile”, that GUI relies back on a simple command-line tool named ‘latex2html’. Whatever that command-line outputs, that’s what all of Kile will output, if we tell it to render LaTeX specifically to HTML. ‘latex2html’ in turn, depends on ‘netpbm’, which counts as very old, legacy software.

One reason ‘latex2html’ will fail us, is the fact that in general, its intent is to render LaTeX, but not Math in any specific way. And so, just to posses the .TEX Files, will not guarantee a Linux user, that his resulting HTML will be stellar. ‘latex2html’ will generally output PNG Images, and will embed those images in the HTML File, on the premise that aside from the rasterization, PNG Format is lossless. Further, if the LaTeX code was generated by “wxMaxima”, using its ‘pdfLaTeX’ export format, we end up with incorrectly-aligned syntax, just because that dialect of LaTeX has been optimized by wxMaxima, for use in generating .PDF Files next.

(Updated 05/27/2018 : )

(As of 05/26/2018 : )

Now, even under Linux, we have options.

Firstly, it’s not a given, that we always want Computer-Algebra to be typeset. We might just as well want formulae typeset, which we just chose to display, and that were not generated by a Computer-Algebra System. But in case we do want the output of a CAS typeset, two viable options are:

  1. Use ‘wxMaxima’, and use its ‘Export to HTML’ feature.
  2. Use an expensive, commercial CAS, which has the feature to output to XML / MathML, and then, borrow the MathML from the resulting .XML File, into our carefully-crafted HTML File.

The big disappointment that comes with using approach (1) above is that, although it results in HTML, it does not actually use MathML. I don’t really know why this is, but ways to typeset Math as HTML may not even use MathML, in practical situations. Instead, the HTML which gets generated may use a JavaScript-Library, which is known as ‘MathJax’. And, instead of always including such JavaScript libraries in the output HTML, such HTML can point to global URLs, which possess powerful ‘CDN’s (“Content Delivery Networks”), from which a myriad of browsers can be downloading the JS-Library, while visiting a Myriad of different sites.

If such a CDN was to be shut down someplace on the WWW, the result would also be, that a wide variety of Web-sites would next lose their ability to display the Math correctly, even though those Web-sites were never specifically affiliated with the CDN in question.

Finally, if the Math we want to typeset comes from the top of our heads, and not from an actual CAS, then our options start to improve:

  1. The “LibreOffice” application-suite includes a Formula Editor, which stores its formulae in .ODF Files. But it has a feature, to Export to .MML . The big caveat with this is, that it never used LaTeX in any way.
  2. I hear that “LyX,” a WYSIWYG LaTeX Editor, offers to export as MathML.

My main problem with LyX would be, that although I have it installed, I have never put it to extensive use, and have therefore also not tested its capabilities vis-à-vis MathML.

(Edit : )

I have just performed a simple test, to see whether LyX can in fact be used, to export humanly-typeset Math as MathML.

If we simply use its ‘Export as HTML’ feature, then LyX will generate those PNG Image Files again, which in the pure sense are not MathML, but which are at least aligned correctly, unlike what I found from ‘latex2html’. But, because we want true MathML, I dug further. And what I found was that the ‘Export as LyXHTML’ option does what it’s supposed to do, which is to output an .XHTML-File, that uses true MathML. We could then do as I suggested, and pick out the Tags which define our formulae, to convert this XML, basically, into HTML. Or, we could do something simpler, which would be, to embed the XHTML File as an <iframe>… If the browser supports MathML in the first place, then it will also be able to display the XHTML File. The example below is the definition of the Golden Ratio:



 

Interestingly enough, There appears to be a Web-article, which documents the fact that in general, Google Chrome doesn’t support MathML.

In view of the fact that WiKiPedia formulae display fine in Google Chrome, I would conclude that their system involves JavaScript-Libraries, similar to MathJax.

(Update 05/27/2018 : )

1: )

One of the mysteries of the modern Web would be, ‘How an external JavaScript Library can convert a text-representation of Mathematical formulae, into images, entirely on the browser?’ And after having given this some thought, I’ve concluded that at least a part of the conversion needs to take place on the actual server. This is consistent with CDNs in general, having a very high data-rate and server-side processing power.

What this means for the programmers of the latest version of ‘wxMaxima’, is that they did not goof, by failing to put their JavaScript Library into the exported HTML, nor into a separate package. Further, just looking at the JavaScript in the exported HTML of this application, merely reveals that the externally-hosted code is being invoked, not, what the code does.

In the case of the WiKiPedia, there is no scenario of a 3rd party wanting such image-conversions done. And so they can just as easily bypass the need for much JavaScript, and focus on converting the text-syntax into images on their servers, dynamically – on the fly.

Some people might respond with the idea, ‘Doing this may conserve the storage space on the server, but might congest the bandwidth between the server and the browser.’ But my own conclusion about that would be, ‘Because PNG Images can be both compressed and lossless, the actual bandwidth that is consumed to download those to the browser, can be minimized well.’

Dirk

 

Print Friendly, PDF & Email

4 thoughts on “The failings of low-end consumer software, to typeset Math as (HTML) MathML.”

    1. It works like a charm! And, because I can have a hard time at remembering all the Syntaxes, I just created a LyX Conversion Rule, which still works.

      Now, if we could only get Google Chrome to support it? BTW, I did not at first notice that Chrome does not, because I mainly use FireFox (ESR)…

      Dirk

      1. The support in Chrome (in fact in all browsers except Firefox) for MathML is non-existent. There are two solutions using MathJax: first is to include MathJax in the generated HTML and let it render MathML, as in this answer of mine on TeX.sx.

        The other solution is to pre-render MathML to HTML+CSS. It requires MathJax support for Node.js, the process is described here.

        1. I thank you for this information, and the time you gave me.

          I did look at your first link, and found the resource to work better, than any previous solutions I’ve tried. And so your resource will likely be a script I use in the future.

          Further, I think that your links will be of great use in turn, to anybody who stumbles upon my blog.

          Dirk

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.