## Tuesday, March 20, 2012

### Test TeX, LaTeX in MathJax

$$\rm\TeX$$ or $$\rm\LaTeX$$ is the leading system for writing mathematical equations via computers. That's how mathematicians and physicists write their papers, e.g. for arxiv.org. See a 4-page summary of its commands or a 157-page not so short introduction to $$\rm\LaTeX$$.

MathJax – see the documentation at mathjax.org – is the most viable implementation of $$\rm\LaTeX$$ on the web. It automatically loads the scripts and fonts it needs, regardless of the platform, doesn't need the user to do anything, and produces an output composed of true fonts of unlimited resolution which look beautiful when printed.

MathJax output appears here:

The form above was taken from Carol Fisher. Click her name and you will see lots of examples and definitions of all the commands.

The inline math mode above should only be tested with "small expressions" that fit into one line. The complicated example above, an equation with many lines, is optimized for the displayed math mode.

I hope that some of the readers who don't know $$\rm\LaTeX$$ will use the form above to play. When one uses a full-fledged $$\LaTeX$$ environment, she probably writes inline maths such as $a^2+b^2=c^2$ i.e. $$a^2+b^2=c^2$$ between ordinary dollars and displayed maths in between double dollars, e.g. $$f(x) = \frac{ax+b}{cx+d}$$ is normally written as $$f(x) = \frac{ax+b}{cx+d}$$. However, in this blog's MathJax environment, we use the standardized MathJax commands $$...$$ for inline maths and $...$ for displayed maths. Well, I admit that triple dollars and double dollars still work ;-) but single dollars are too important a currency on this blog to be wasted for non-financial mathematical babble.

Superscripts and subscripts work using the usual ^ and _ characters and if you want to encapsulate some collection of objects into "parentheses", you use the braces, {...}. $$\rm\TeX$$ commands start with a backslash. The only thing left for you is to learn lots of these commands to type whatever you need to know. An example: \frac{numerator}{denominator} produces a nice fraction.

Ignore the <br> commands in the code above. MathJax manages to ignore them (and empty lines), too. Finally, let me admit that some non-standard commands (macros) are defined in the header of this blog
TeX: {
Macros: {
dd: '{\\rm d}',
CC: '{\\mathbb C}',
RR: '{\\mathbb R}',
ZZ: '{\\mathbb Z}',
NN: '{\\mathbb N}',
NNN: '{\\mathcal N}',
FF: '{\\mathcal F}',
LL: '{\\mathcal L}',
eV: '{\\,\\,{\\rm eV}}',
keV: '{\\,\\,{\\rm keV}}',
MeV: '{\\,\\,{\\rm MeV}}',
GeV: '{\\,\\,{\\rm GeV}}',
TeV: '{\\,\\,{\\rm TeV}}',
diag: '{\\rm diag}',
pfrac: ['\\frac{\\partial #1}{\\partial #2}',2],
ddfrac: ['\\frac{{\\rm d} #1}{{\\rm d} #2}',2],
bold: ['{\\bf #1}',1],
zav: ['\\left({#1}\\right)',1],
eq: ['\\begin{align} #1 \\end{align}',1],
abs: ['\\left|{#1}\\right|',1],
braket: ['\\langle{#1}|{#2}\\rangle',2],
bra: ['\\langle{#1}|',1],
ket: ['{|{#1}\\rangle}',1]
}
},
so you shouldn't be surprised that these unusual commands work in the example of the code above although they would fail to work elsewhere. $$\rm\TeX$$ and $$\rm\LaTeX$$ also allows you to define commands and many other things; in some sense, $$\rm\TeX$$ in general is a programming language by itself (although one optimized for typesetting).
Off-topic: see a cute 12-megapixel photograph of Tevatron control room

1. Unfortunately,

(1) The math display does not work on my iPhone.

(2) On my Mac using Safari, the math shows as black font on a dark green background -- impossible to read.

Luboš, would it be easy for you to fix these?

2. Nope, Peter, it wouldn't be easy. You should send your complaints about your defective hardware to Tim Cook.

MathJax is tested and works at newest (and not only newest) versions of Chrome, Firefox, MSIE, and Safari on Windows 7, Windows Vista, and probably most Linuxes etc. as well.

I can't even sensibly test how MathJax behaves elsewhere, and even if I could, it's clearly not something I should be solving, having no resources, expertise, or time for this kind of work.