# Finally, LaTeX in HTML files

Writing a paper in LaTeX will always result in beautiful output, but if you’d like to put that document up on the web you’re limited to two reasonable options: serve the document as a .PDF (with the horrors involves, although Chrome makes things much more palatable), or relying on third-party browser plugins like TeX The World. Now that [Todd Lehman] has finally cooked up a perl script to embed LaTeX in HTML documents, there’s no reason to type e^i*pi + 1 = 0 anymore.

For those not in the know, LaTeX is a document typesetting language that produces beautiful output, usually in PDF form. Unfortunately, when [Tim Berners-Lee] was inventing HTML, he decided to roll his own markup language instead of simply stealing it from [Don Knuth]. Since then, LaTeX aficionados have had to make do with putting TeX snippets into web pages as images or relying on the [; \LaTeX ;] generated from the TeX The World browser extension.

[Todd Lehman]’s perl script generates the PDF of his LaTeX file and pulls out all the weird font and math symbols into PNG files. These PNG files are carefully embedded into the HTML file generated from the normal text pulled from the LaTeX file. It’s a ton of work to get these document systems working correctly, but at least there’s a reasonable way to put good-looking LaTeX on the web now.

## 23 thoughts on “Finally, LaTeX in HTML files”

1. Actually, the accessibility of an image-based system is pretty lacking; investing in MathML with alternative rendering systems for non-supported browsers makes for a much better experience.

See http://www.mathjax.org/ for a rock-solid implementation. Also, that one’s scalable, images aren’t.

1. pascal says:

IMO the best way to do it is to convert the LaTeX-formulas (because they’re easy to write) into MathML (because it’s a standard format and Firefox even renders it, but it’s awful to write manually) and embedd the MathJAX-script to render it in the browsers that don’t understand MathML.

2. Mythgarr says:

I’m confused – what was wrong with MathJax? I’ve been embedding LaTeX into HTML for a while now…

1. bkanuka says:

I agree. Why now use MathJax? it’s incredible what it can do.

and the “horrors of pdf” are pretty negligible. Sometimes I’m annoyed that it’s an end format but even then there’s a latex package to embed the tex file.

3. Aleksejs Popovs says:

In my opinion, this is a really stupid solution as the equations won’t be nor scalable nor selectable. I think that http://mathjax.com/ is a much more beautiful solution to this problem.

Also,
> Unfortunately, when [Tim Berners-Lee] was inventing HTML, he decided to roll his own markup language instead of simply stealing it from [Don Knuth]
Thank God! LaTeX is beautiful, but it’s absolutely not suited for web (unless you use it inline, like with MathJax).

4. Ivan says:

Having a public license I guess it wouldn’t had been “stolen” anyways.

5. jonored says:

I usually use latex2html to do essentially the same thing document structure – not perfect package handling, but otherwise pretty decent at its job.

6. PNG files? Why not SVG? I guess maybe bitmap is easier to work with during generation though.

7. Kalleguld says:

You need a paren around i*pi
:)

1. Brian Benchoff says:

damnit

8. serve the document as a .PDF (with the horrors

I agree just embedding the equations into HTML directly is more elegant, but down and dirty gets it done as well.

Maybe you are referring to special fonts that need to be embedded into the PDF itself?

9. M4CGYV3R says:

If it’s difficult for you to read PDF files, you’re doing it (all) wrong. Acro Reader works just fine.

Especially on a Mac. You don’t even need plugins or a reader for that.

10. zokier says:

There is a very good reason TBL chose to create HTML instead of using TeX. Rendering simple HTML is much much faster than doing the perfect typography of TeX.

11. Isn’t this really old news? There’s been LaTeX-to-PNG renderers for online use for quite a while, and lots of LaTeX-to-MathML converters as well. And the quite excellent MathJAX.

12. I’m too in favour of MathJax, but, to all the naysayers — it’s a hack after all :D

13. Kemp says:

This seems great as a personal project looking into handling LaTeX/PDFs and generating images, but there have been existing solutions for a long time now. The article is pitched a little to far to the “look at this great new technique” side of things.

14. cheshirekow says:

I’ve found LaTeXML to be a great way to get latex into an html format. Far better than latex2html and it’s not a javascript thing so there’s not processing delay in the page.

15. Antonio says:

As GaspingSpark already said ” the MathML support that already works in most browsers. http://www.w3.org/Math/

To write easily formulas then export them in MathML
or Latex or Maxima, or other formats, just use
this applet which works also offline :
http://www.dragmath.bham.ac.uk/demo.html
Also it’s not limited to a single browser,
like the chrome software cited before,
moreover the Licence is GPL !

export to clipboard, paste in a text editor and save
as .html or .tex or other as you like.

Bye ;-)

—————————–ITALIANO—————————–

Come GaspingSpark ha già detto “il supporto MathML funziona già nella maggior parte dei browser. http://www.w3.org/Math/

Per scrivere facilmente le formule e poi esportarle in MathML
o in latex o Maxima, o altri formati, potete usare
questa applet che funziona anche offline:
http://www.dragmath.bham.ac.uk/demo.html
rilasciata con licenza GPL !
Non vincolata ad un solo programma di navigazione
come quella di Chrome.

esportare negli appunti, incollarlo in un editor di testo e salvare
come .html o .tex o altri formati che vi servano.

Ciao ;-)

16. Elliot says:

Also consider AsciiDoc. You can write (with embedded Latex math) into a single document that can be processed into DocBook, HTML, PDF, and etc.

17. Manoj says:

Simple:

\frac{1+sin(x)}{y}

18. Manoj says:

Simple:

other stuff
\frac{1+sin(x)}{y}