MultiMarkdown and MathML - new feature and request for help

Dr. Drang drdrang at gmail.com
Sat Jun 10 22:49:35 EDT 2006


On 6/10/06, Fletcher T. Penney <fletcher at alumni.duke.edu> wrote:

> A lot of people have expressed interest in combining math features

> with Markdown, but I am not aware of any real developments from these

> requests.

>

> I was looking around and toying with [ASCIIMathPHP](http://

> www.jcphysics.com/ASCIIMath/) and integrated it with MultiMarkdown

> and my xhtml2latex XSLT transforms.

>

> You can include math as an inline formula by using a markup similar

> to inline code, such as ``x^2 + y^2 = 1`` (note the double ``).

>

> You can include a formula as a separate paragraph in the same way, or

> with a leading tab like:

>

> `x_(1,2) = (-b+-sqrt(b^2-4ac))/(2a)`

>

> (Note the single use of ` when prefaced by a tab)

>

> The leading tab is not required, but is allowed as I suspect most

> people would like to be able to indent the formula to distinguish it

> from regular text, and don't want it interpreted as a code block.


As Fletcher may recall, I had a math-enabled version of MultiMarkdown
going several months ago. It differed from his in that

* it used $$ and $$$ as the inline and display equation delimiters,
respectively;
* the equations had to be written in LaTeX form, not ASCIIMathML; and
* it output HTML that was to be interpreted by [jsMath][1], not ASCIIMathML.

The double and triple dollar signs were chosen because they reminded
me of the usual TeX delimiters, but left the single dollar sign with
its usual, non-TeX, meaning.

I chose jsMath over ASCIIMathML because it works on more browsers.
jsMath is essentially a JavaScript rewrite of the TeX equation
formatting engine. It works on browsers that don't understand MathML.
True, the ASCIIMathML syntax is more Markdown-like, but TeX is pretty
well established as an equation syntax (for those of you who are not
native speakers of English, that's a bit of Midwestern
understatement).

One of the other advantages of jsMath is that it's easy to write XSLT
for it. jsMath uses <span class="math">...</span> to delimit inline
equations and <div class="math">...</div> for display equations. These
are easy to convert into $ and $$ for LaTeX.

<!-- inline math -->
<xsl:template match="span[@class='math']">
<xsl:text>$</xsl:text>
<xsl:value-of select="node()"/>
<xsl:text>$</xsl:text>
</xsl:template>

<!-- display math -->
<xsl:template match="div[@class='math']">
<xsl:text>$$</xsl:text>
<xsl:value-of select="node()"/>
<xsl:text>$$</xsl:text>
<xsl:value-of select="$newline"/>
<xsl:value-of select="$newline"/>
</xsl:template>

Recently, however, [I decided to give up on my fork of
MultiMarkdown][2] and go back to the standard version. Fletcher is too
damned prolific, and I didn't want to keep inserting my code into
newer and newer versions of MultiMarkdown. To this end, I started
delimiting my equations with \\( and \\) for inline and \\[ and \\]
for display. Regular MultMarkdown (or Markdown itself) just turns the
double backslash into a single. jsMath has a preprocessor, the
tex2math plugin, that will take these LaTeX delimiters and convert
them to <span class="math"> and <div class="math"> before the usual
jsMath processing. This is what I use for equations in [my ongoing
solutions manual][3] for Den Hartog's *Mechanics* textbook.

For documents that are to be run through LaTeX for paper output, I
pass them through

1. a preprocessor that converts the \\(..\\) and \\[...\\] to <span
class="math">...</span> and <div class="math">...</div>;
2. MultiMarkdown
3. an XSLT processor using my stylesheet with the above stanzas for math.

Having written this long message, how is it responsive to Fletcher's
post? First, I'd prefer LaTeX syntax and jsMath to ASCIIMathML. My
preference comes from the wider applicability of jsMath, but it turns
out that XSL is easier, too. And since you're using LaTeX for final
processing (if you're publishing to paper), it makes sense to use
LaTeX syntax for the equations.

As for delimiters, I'd prefer something a little more TeX-like than
backquotes, but I'm flexible. I had about 20 posts up at the
*Mechanics* site with the multiple dollar sign notation before I
decided to give up on my fork of MultiMarkdown; now I have about 40
posts up using the \\( and \\[ notation.

--
Dr. Drang

[1]: http://www.math.union.edu/~dpvc/jsMath/welcome.html
[2]: http://www.leancrew.com/all-this/2006/05/mechanics_blog_update.html
[3]: http://www.leancrew.com/mechanics


More information about the Markdown-Discuss mailing list