+3  A: 

You might find mimeTeX useful.

Ignacio Vazquez-Abrams
Successor mathTeX looks even better---and it's clear that `dvipng` is the workhorse. Thanks for a great pointer! +1
Norman Ramsey
+2  A: 

Perhaps mathJAX is the ticket. It's built on jsMath, a 2004 vintage JavaScript library.

duffymo
A: 

yes, but you'll have to hack it a little yourself. I've written a filter that replaces latex tags $\some\inline\latex$ or $$\some\equation$$ with appropriate image tags to a mimetex.cgi script. It took all of 5 minutes.

Warning: spectacularly ugly...

#!/usr/bin/env python
import sys, markdown,re

MIMETEX_LOC="http://some.server.com/cgi-bin/mimetex.cgi"

def sanitizeLatex(text):
    return re.sub(r"\\",r"%5C", text)

def wrapLatexBlock(text):
    return '<img alt="equation" class="block" src="%s?%s"></img>'%(MIMETEX_LOC,text)

def wrapLatexInline(text):
    return '<img alt="equation" class="inline" src="%s?%s"></img>'%(MIMETEX_LOC,text)

def prepLatexBlock(matchobj):
    return wrapLatexBlock(sanitizeLatex(matchobj.group()[2:-2]))

def prepLatexInline(matchobj):
    return wrapLatexInline(sanitizeLatex(matchobj.group()[1:-1]))


if __name__ == "__main__":
    # initialise markdown
    md=markdown.Markdown()
    raw_md=open(sys.argv[1],"r").read()

    ##
    # deal with embedded latex
    ##
    raw_md=re.sub(r'\$\$(.*?)\$\$',prepLatexBlock, raw_md)
    raw_md=re.sub(r'\$(.*?)\$',prepLatexInline, raw_md)

    ##
    # once latex is parsed, convert md to html
    ##
    main_html=md.convert(raw_md)

    # hey presto!
    print(main_html)

Of course, you have to define the appropriate css yourself for .block and .inline images...

brice
+1  A: 

I'll answer your question with a counter-question...

What do you think of Org-mode? It's not as pure as Markdown, but it is Markdown-like, and I find it as easy to work with, and it allows embedding of Latex. Cf. http://www.gnu.org/software/emacs/manual/html_node/org/Embedded-LaTeX.html

Postscript

In case you haven't looked at org-mode, it has one great strength as a general purpose "natural markup language" over Markdown, namely its treatment of tables. The source:

| 1 | 0 | 0 |
| -1 | 1 | 0 |
| -1 | -1 | 1 |

represents just what you think it will...

And the Latex is rendered in pieces using tex-mode's preview-latex.

Charles Stewart
I looked at org-mode, and although the embedded LaTeX seems very well done, it looks like total overkill for what I want (typical of emacs).Interestingly, I note that the underlying rendering engine is again `dvipng`. The table problem is an important one but I have already written a preprocessor to solve it :-) +1
Norman Ramsey
+2  A: 

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.

Mica
Looks more complicated than what I want, and it's less than clear what the expressive power is (other than MathML is incorporated by reference0).
Norman Ramsey
A: 

And if you will excuse a second flawed answer to your question, this depending on answering another unsolved problem or two...

My question, Convert Tex to Metapost, is concerned with rendering, and if I had a good answer to that, it should be possible to put together a good solution to your question, Metapost having all the abilities to hack bounding boxes you could want, and having your choice of lovely rendering engines, through .eps, SVG, &c.

Maybe it would be possible to make a drop-in replacement/extension to dvipng that is based on SVG? It might be possible to use SVG + HTML technology to present SVG where the browser has that, and have an ALT-tag that presents a PNG if it is not there.

Charles Stewart
+4  A: 

Have you tried with Pandoc?

aalvaradoh
See also http://stackoverflow.com/questions/663532/lighweight-markup-wiki-language-for-documenting
aalvaradoh
+1  A: 

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.

Andrew Stacey