LaTeX to HTML - Square roots

The previous two answers have already addressed your immediate query. However, I would like to add that may be you should try pandocHomepage. It can convert various formats like latex, html, xhtml, html5, docx, odt, epub, conTeXt etc. into each other. My experience has been pleasant. However, installation of pandoc requires haskell platform which took nearly 350MB of space on ubuntu 12.04.

For a good rendering of math in html, I think that mathjax is the way to go. It is supported by most browsers. It can handle most of the latex math environments. One drawback though is the slow loading of the webpages with a lot of math.

I used:

pandoc -s --mathjax a.tex -o a.html

to get

enter image description here

Personally, I have converted my PhD Thesis with a lot of math into html using pandoc which also handles bibliographies.

EDIT: Major bugs regarding math environments have been addressed in pandoc v1.9.2. The example above uses the latest version 1.9.4.5. Ubuntu repository has older versions. Hence, it is recommended that the latest versions be installed from haskell repository for best results.


It looks to me like your output is using images for the Mathematical content; you get better output if you use MathML. You have a few choices:

htlatex myfile.tex "html,mathml"

produces an html file with MathML and

mk4ht mzlatex myfile.tex "html,mathplayer"

produces a .xht file with MathML.

screenshot

From an accessibility point of view, most screen readers work best with .xht files.

MathML is wonderful, but the only slight disadvantage is that not all browsers can render it natively.

  • Firefox will render it fine without any hastle (and has been able to for a number of years)
  • IE will work ok if you ask it nicely, and install MathPlayer, for IE up to version 8 (or the beta of MathPlayer2 from the same URL for IE 9 and 10.)

From David Carlisle

  • Chrome 24 has native support
  • Safari from version 5 has native support
  • Opera has limited support

Lately I have experimented a lot with Math on the web and maybe some of my conclusions might be helpful to you.

  1. At this point I actually thing that going from LaTeX to HTML is a philosophically wrong way of doing things (I am semi-familiar with most tools for converting LeTeX to HTML).

  2. In liue of my previous conclusion I thing that one should start typing a document from the very beginning with idea that it should display nicely on the web and print nicely as LaTeX. My approach was to adopt txt2tags. However txt2tags has as its main goal to use light mark up to produce 10 different outputs. The price to pay is that outputs are not perfect in any of 10 outputs formats but something that you can work with. My approach is to use txt2tags with idea that end output will be LaTeX or XHTML. Getting reasonably good LaTeX output including formula is possible by including peaces of LaTeX code into t2t ASCII file in tag mode. For example mwe.t2t

mwe.t2t

Predrag Punosevac

Example: Failure of unique prime factorization in $\mathbb{Z}[\sqrt{-5}\hspace{0.1 cm}]$

'''
\begin{equation*}
6 = (1 + \sqrt{-5})\cdot (1 + \sqrt{-5}) = 2 \cdot 3
\end{equation*}
'''
but must be processed with pdflatex!  

Processing such file with

txt2tags -t tex mwe.t2t
pdflatex mwe.tex
pdflatex.mwe.tex

will produce "perfect" LaTeX code. But what about XHTML? Well the first thing that we have to investigate is how to properly display mathematics on the web. The answer is MathJex which uses MathML as a backend! MathJex can use various syntax as input to produce mathematics but in particular it can use LaTeX native syntax. That mean that above test file processed as

txt2tags -t xhtml mwe.t2t

is almost what you need. How come? Namely MathJax needs not to be installed on your local machine. You just need to to append mwe.xhtml file with the following few lines of code

<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'],
['\\(','\\)']]}});
</script>
<script type="text/javascript"

src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorM
ML">
</script>

just after the last meta tag and fonts for displaying Math on the web will be uploaded from the MathJex server. The page will require a split of a second longer to load but no big deal. It will be correctly displayed on any browser supporting evil JavaScript. Put the above code into mathjax.patch file. The dirty work will be done by sed load file (r-command)

$ more Makefile
SHELL = /bin/sh
.SUFFIXES : .t2t .tex .pdf .html

FILE = lesson_plans
SRC  = ${FILE}.t2t

TXT2TAGS = /usr/local/bin/txt2tags
PDFLATEX = /usr/local/bin/pdflatex

TEX  = ${SRC:.t2t=.tex}
HTML = ${SRC:.t2t=.html}
XHTML = ${SRC:.t2t=.xhtml}

.xhtml.t2t :
        ${TXT2TAGS} -t xhtml ${FILE}.t2t


html : ${SRC}
        ${TXT2TAGS} -t xhtml ${FILE}.t2t
        mv ${XHTML} ${HTML}
        sed '/meta/r mathjax.patch' ${HTML} > aux
        mv aux ${HTML}
${TEX}: ${SRC}
        ${TXT2TAGS} -t tex ${FILE}.t2t
pdf: ${TEX}
        ${PDFLATEX} ${TEX}
        ${PDFLATEX} ${TEX}


clean-html :
        /bin/rm -f *.html *.xhtml
clean-tex : 
        /bin/rm -f *.tex
clean : 
        /bin/rm -f  *.log *.aux *.bbl *.blg *.bm *.toc *.out *.bak
clean-ps : clean
        /bin/rm -f *.ps
clean-all : clean-tex clean-html clean
        /bin/rm -f *.pdf

Remark I have clean-ps target because I usually use tex->dvi->ps->pdf routine and my .exrc file for nvi editor has

map ^X :w^M:!make pdf clean-ps %^M

So I can do everything just from inside nvi with CTRL+x command.

Enjoy!!!