Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there any tool that can convert Latex documents to HTML documents, so that all math is presented with MathJax?

(Obviously, it is fairly easy to hack together a quick Perl script that is able to do a crude conversion, but I am interested in a bit more robust solutions — at least it should get all cross-references right automatically.)

share|improve this question
add comment

1 Answer 1

You can use TeX4ht. It can output math as mathml which can be then displayed with mathjax. You can also configure html header to load mathjax script from mathjax's cdn:

\Preamble{xhtml,mathml}
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}}
\Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
(http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}}
\Configure{@HEAD}{\HCode{<link
         rel="stylesheet" type="text/css"
         href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
\Configure{@HEAD}{\HCode{<script type="text/javascript"\Hnewline
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"\Hnewline
></script>\Hnewline}}
\Configure{@HEAD}{\HCode{<style type="text/css">\Hnewline
  .MathJax_MathML {text-indent: 0;}\Hnewline
</style>\Hnewline}}
\begin{document}
\EndPreamble

With this config file, we request to output math as mathml, then configure html header so resulting file is html5. Save it as for example ht5mjlatex.cfg and then call from command line:

htlatex filename.tex "ht5mjlatex.cfg, charset=utf-8" " -cunihtf -utf8"

or you can use William F. Hammond's script (at bottom of the page)

share|improve this answer
1  
And this has the advantage that browsers that can display MathML (natively or via a plugin) can avoid the necessity of loading MathJaX. –  Loop Space Aug 27 '12 at 7:27
5  
This is certainly better than nothing, but I would prefer to keep the HTML source code somewhat readable. Very simple equations seem to produce dozens of lines of mathml markup... –  Jukka Suomela Aug 27 '12 at 23:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.