I've been using Markdown for class notes, and it's great. I even do some preprocessing on the Markdown so I can do things like tables. But this term I'm teaching a class with a lot of math, and I'd love to be able to put LaTeX formulas with Markdown, something like this:
The refinement relation is written $a \sqsubseteq b$, which can be
pronounced "$a$ approximates $b$" or "$b$ is at least as defined as $a$".
I'd like to be able to take each fragment of LaTeX and preprocess it into a nice antialiased PNG file which I could then include in my Markdown via the HTML <img>
tag. But I have absolutely no idea how to take a fragment of LaTeX and get a nice image that
- Has the right bounding box
- Is antialiased
All I know how to do is get full pages in DVI, PostScript, or PDF formats.
I'm sure this problem has been addressed, but I haven't been able to guess the right search terms. Any suggestions how to solve it or where to look for an existing solution?
EDIT: Having installed mathTeX, I can say that the code is inflexible, that it violates the Linux Filesystem Hierarchy standard, and that it is amateur work—in both the good and bad senses of that word. The code is so complex that there are no obvious faults. I will be looking for alternatives.
Also, it's clear that at bottom, solutions are based on dvipng
.
ONE YEAR LATER: I never did get the seamless integration I had been hoping for, but I am limping along on a script of my own devising. It turns out that instead of dvipng
it is a little easier to use dvips -E
and the convert
program of ImageMagick. The benefits are slightly more control of things like scaling, and ease of making a transparent background.
The curious can inspect this example.
I can't recommend this solution to anyone. But I can't recommend MathTeX either.
It is possible to parse Markdown in Lua using the Lunamark code (see its Github repo), meaning that Markdown may be parsed directly by macros in Luatex and supports conversion to many of the formats supported by Pandoc (i.e., the library is well-suited to use in
lualatex
,context
, Metafun, Plain Luatex, andtexlua
scripts).The project was started by John MacFarlane, author of Pandoc, and the tool's development tracks that of Pandoc quite closely and is of similar (i.e., excellent) quality.
Khaled Hosny wrote a Context module, providing convenient macro support. Michal's answer to the Is there any package with Markdown support? question gives code providing similar support for Latex.
Have you tried with Pandoc?
What language are you using?
If you can use ruby, then maruku can be configured to process maths using various latex->MathML converters. Instiki uses this. It's also possible to extend PHPMarkdown to use itex2MML as well to convert maths. Basically, you insert extra steps in the Markdown engine at the appropriate points.
So with ruby and PHP, this is done. I guess these solutions could also be adapted to other languages - I've gotten the itex2MML extension to produce perl bindings as well.
you should look at multimarkdown http://fletcherpenney.net/multimarkdown/
it has support for metadata (headers, keywords, date, author, etc), tables, asciimath, mathml, hell i'm sure you could stick latex math code right in there. it's basically an extension to markdown to add all these other very useful features. It uses XSLT, so you can easily whip up your own LaTeX styles, and have it directly convert. I use it all the time, and I like it a lot.
I wish the markdown would just incorporate multimarkdown. it would be rather nice.
Edit: Multimarkdown will produce html, latex, and a few other formats. html can come with a style sheet of your choice. it will convert into MathML as well, which displays in Firefox and Safari/Chrome, if I remember correctly.
I came across this discussion only now, so I hope my comment is still useful. I am involved with MathJax and, from how I understand your situation, I think that it would be a good way to solve the problem: you leave your LaTeX code as is, and let MathJax render the mathematics upon viewing.
Is there any reason why you would prefer images?
You might find mimeTeX useful.