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.

I used SimpleTeX4ht to convert a LaTeX file to HTML. The file is fine except that square roots are rendering badly in juxtaposition with the rest of the text, e.g. like:

like this

Any suggestions on how to get the square roots to render better? (Whether by using a different converter, using different LaTeX, etc.)

My LaTeX code is

\noindent \textbf{Example:} Failure of unique prime factorization in $\mathbb{Z}[\sqrt{-5}\hspace{0.1 cm}]$:\\
 $6 = (1 + \sqrt{-5})\cdot (1 + \sqrt{-5}) = 2 \cdot 3$.\\

and the corresponding HTML is something like

<!--l. 269--><p class="noindent" ><span 
class="cmbx-12">Example: </span>Failure of unique prime factorization in <span 
class="msbm-10x-x-120">&#x2124;</span>[<img 
src="Fermat10x.png" alt="&#x221A; --5"  class="sqrt" > ]:<br 
class="newline" />6 = (1 + <img 
src="Fermat11x.png" alt="&#x221A; ---
  - 5"  class="sqrt" >) <span 
class="cmsy-10x-x-120">&#x22C5; </span>(1 + <img 
src="Fermat12x.png" alt="&#x221A; ---
  - 5"  class="sqrt" >) = 2 <span 
class="cmsy-10x-x-120">&#x22C5; </span>3.<br 
class="newline" />
share|improve this question
    
can you tell us the commands your running? –  cmhughes Nov 12 '12 at 2:22
    
Does this provide the answer: ccrma.stanford.edu/~jos/bestviewing.html. I remember reading a very detailed description of this exact problem at some web page (but can't find it now)... –  Peter Grill Nov 12 '12 at 2:27
    
for mathjax output from tex4ht, see tex.stackexchange.com/q/68916/2891 for image placement corrections, see tex.stackexchange.com/q/44486/2891 or my package github.com/michal-h21/mathdimen –  michal.h21 Nov 12 '12 at 12:17

3 Answers 3

up vote 4 down vote accepted

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.

share|improve this answer

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
share|improve this answer
    
“Chrome … can’t do it yet” – and probably never will will; there’s little incentive now that we have a better alternative with MathJax. –  Konrad Rudolph Nov 12 '12 at 9:53
    
Chrome 24 has native support for MathML, At the time of writing that means the dev or beta channels but it should be in the stable channel by the new year. –  David Carlisle Nov 12 '12 at 9:56
    
MathPlayer works (with slightly different incantations) with every version of IE between 5.5 and 10, I'm not sure why you say "Only IE8". –  David Carlisle Nov 12 '12 at 10:02
    
Safari also has MathML support (from version 5) and Opera has limited MathML support via an automatically added css style. –  David Carlisle Nov 12 '12 at 10:03
    
@DavidCarlisle thanks for the comments :) I'll update, and feel free to edit if you like –  cmhughes Nov 12 '12 at 18:05

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!!!

share|improve this answer
1  
MathJax is a nice piece of software, but you appear to be confused by its relationship to MathML. The first stage of MathJax (its TeX input Jax) is to convert the TeX syntax within the page to MathML. Everything it does after that is an implementation of MathML. Currently it has three MathML implementations: Using the Browser's native MathML support, conversion to HTML/CSS and conversion to SVG. –  David Carlisle Nov 12 '12 at 12:28
    
@David Carlisle Thank you so much for educating me on MathML just like on many other topics! I edited my post accordingly. –  Predrag Punosevac Nov 12 '12 at 16:48

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.