Markdown and Mathematics

Michel Fortin michel.fortin at michelf.com
Sun Apr 4 10:21:26 EDT 2004


I've been asking myself how math formulas could be written in a 
Markdown document. Here are my thoughts.

A way I see that could make not too much unreadable equations (while 
reading text) and powerful ones (as in complex ones) is latex. Here are 
some equations in latex:

	x^2 + y^2 = z^2
	e^x = \relstack{\rm lim}{n\rightar\infty} \ (1+\frac xn\)^n

You can see that when the expression is simple it's perfectly readable 
as plain text. When the equation is more complex it becomes a little 
less readable, but it's still a lot more readable than plain MathML 
tags (an XML language for mathematics). Latex is already well known by 
many mathematicians and is a tool of choice for anyone who want to 
write mathematics.

So I've thought of a way to include a latex equation into a Markdown 
document:

	The equation { x^2 + y^2 = z^2 } is really interesting!

This syntax is the most interesting as it's totally readable, it feels 
natural to read and to write since latex also use curly brackets as a 
grouping delimiter. But it has one downside: it may cause some 
conflicts if you use those curly brackets elsewhere. Here is an 
alternate syntax that could be used:

	The equation {$ x^2 + y^2 = z^2 $} is really interesting!

It's a little less readable, but the chances to be in conflict with 
something else you write are close to zero.

Now, enough about the syntax. How can it be rendered in HTML? Embedding 
MathML in the document would be the ideal choice, but some browsers 
(like Safari) do not support it (Mozilla, Firebird and Win IE using the 
MathPlayer plugin can however). The other way is to use the 
[mimetex][1]. MimeTeX is a small program that you put in your CGI 
directory and that generate image for the latex equation you put in the 
url. You simply have to write an equation image like this in HTML:

	<img src="/cgi-bin/mimetex.cgi?x^2+y^2=z^2" alt="x^2 + y^2 = z^2" />

[1]:http://www.forkosh.dreamhost.com/mimetex.html

I took the simple bracket syntax `{ x }` and made an experimental 
version of Markdown using mimetex. You can try on my dingus page. 
Choose "PHP Markdown Math" form the filter box and you're in!

<http://www.michelf.com/php-markdown/>

So, is latex a good choice? Is the curly braket syntax dangerous? What 
is the best way of doing this? I would like to know what everyone 
thinks and especially what John Gruber has to say on the subject.

* * *
Hum, just before hitting send I remember John saying he wants to keep 
these curly brackets for class and id assignments. It could become 
confusing if the curly brakets are used elsewhere too. But if I use 
latex, do I have the choice? There will be some of these brakets inside 
the formulas any way.

* * *
Another (latex-compatible) maybe easier to use equation syntax:

[ASCIIMathML] (http://www1.chapman.edu/~jipsen/asciimath.xml) -
This one is fantastic! but output is in MathML and requires Mozilla, 
Firebird, or Win IE + MathPlayer. Go try the javascript demo!

Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/


More information about the Markdown-discuss mailing list