Monday 30 January 2017

Displaying Mathematical Expressions

If looking at this post on an android device, the equations will not display properly.
\[\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}\]It was with some difficulty that I've finally figured out how to display mathematical expressions properly in Blogger. The approach that I've adopted is to paste the following script just above the closing head tag in the blog's template:


The MathJax javascript will then render any LaTeX mathematical expressions, such as "\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}" (this is the one behind the expression at the top of this post). This site explains how to use the $ sign:


The double $ signs work fine but the single $ signs, that are supposed to give the inline expression, didn't work at first with the script as above. However, after pasting a modified script (see HMTL template), all was well, with both single dollar signs  and backward slash ( ...  backward slash ) being accepted.

Back on January 27th 2016, I made a post about the ASCIIMathML and the associated javascript program ASCIIMathML.js associated with it. Here is the text of that post:
The ASCIIMathML is a markup language that claims to be close to standard mathematical notation, easy to read and easy to type. In combination with a javascript program ASCIIMathML.js it will faithfully render mathematical expressions within HTML pages. I came across it when using a new online content management service called versal. Using the mathematical gadget provided by versal, I found the markup language very easy to use and was quickly able to create relatively complex formulae. This is my public URL on versal. The free version allows for the creation of unlimited public courses whereas the PRO version (at US$50 per year) allows for the creation of private courses, the tracking of student progress and other benefits.
Apparently ASCIIMathML.js has now been incorporated into the latest version of MathJax.js and the latter is:
a cross-browser JavaScript library that displays mathematical notation in web browsers, using MathML, LaTeX and ASCIIMathML markup. MathJax is released as open-source software under the Apache License and, importantly MathJax can display mathematical notation written in LaTeX or MathML markup. Because MathJax is meant only for math display, whereas LaTeX is a document layout language, MathJax only supports the subset of LaTeX used to describe mathematical notation."   Source.
ASCIIMathML is simpler and less verbose that LaTeX but in Blogger at least, the former seems temperamental and doesn't work consistently. The following equation when entered in ASCIIMathML as "x=(-b +- sqrt(b^2 – 4ac))/(2a)" fails to display the formatted equation. However, when entered in LaTeX as "x=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}", it displays properly:
$$x=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$ A comprehensive list of LaTeX mathematical commands can be found here.

No comments:

Post a Comment