1

I wrote a math paper in LaTeX that uses a custom .sty file I wrote (defines some math commands, basically, and imports packages with math symbols and fonts) and I want to convert it into a standalone, uncomplicated HTML file. I've tried many converters, such as lwarp, LateXML, latex2html, and htlatex, and I'm not satisfied. Mostly it's because they don't make the math look right. lwarp was close because it saved math as SVGs but for some reason the images looked terrible, with lots of clipping, and there was lots of HTML code for some reason. latex2html did a good job but the resulting HTML looks complicated. My end goal is to post the HTML in a WordPress.com post, so I was worried that the resulting HTML would not be accepted for some reason. (I'm aware of a program called latex2wp but reading the README suggests that it might not work since I use align.)

There is a combination that gets really close to what I want: pandoc and GladTeX. Pandoc can convert the .tex file into a GladTeX-friendly HTML file, and then I can run GladTeX to get formulas that appear as images, and the images look good. Admittedly there's problems with centering of display-style formulas, but that can easily be fixed and even if not it's not a big deal.

What I have a problem with is that there is no formula numbering; pandoc inserts ugly, opaque links that are not reader-friendly and don't appear to work whenevery I have a reference to a formula (in the style of "and if you look at (1) you see that x=1", or something). The other converters get numbering right, but not pandoc. There are things you can put specifically into pandoc to try and get numbering, but then the document is not truly latex anymore.

So is there a good converter of latex to HTML that does everything but formulas, and which will produce a GladTeX-friendly HTML file for me to run GladTeX on?

1

There are many ways how to display math on web. In theory, best way should be MathML, special XML markup for math. The only problem is that it is supported only by Firefox, it doesn't work in Chrome for example. The support for other browsers can be added using MathJax, but it can be a bit slow. I am also not sure if you will be able to modify the WordPress site to include MathJax. You can try this way using tex4ht with the following command:

make4ht -u filename.tex "mathml,mathjax"

Another way is to keep the math contents as TeX source and use MathJax for the rendering. The issue with MathJax still apply. Moreover, it doesn't support custom commands, you would need to provide a configuration for them:

make4ht -u filename.tex "mathjax"

This method works also for KaTeX, which is faster than MathJax, but it supports lot less commands and doesn't seem to have a support for custom commands.

The safest and fastest method is to use images for math. The downside is that it doesn't look good, especially for inline math. To get that with tex4ht, try the following command:

make4ht -u filename.tex "svg,pic-m+,pic-align,pic-equation"

It requires SVG format for pictures and requires common math commands ($...$,\[ ...\]) and environments to be converted to pictures.

Other options that require pictorial representation of math environments exist, see tex4ht options.

I don't really know about GladTeX, but it seems that it converts LaTeX snippets to images, which isn't really necessary with this method.

I cannot be more specific as you didn't show any code, but in general, you need to configure the conversion a bit to get a good result.

  • Images have to be text; MathML and MathJax won't work on WordPress.com. And I tried make4ht and it garbles the text for reasons I don't understand, in addition to not producing good pictures, even when using the command you suggested. So I went back to latex2html and actually got good results except for the fact that references to equations (such as an equation labelled (10) ) have the number replaced with a box. I have no idea why that box is there or how to get rid of it. I've tried looking through the documentation and Google but have no idea why that box is there. – cgmil May 20 at 7:49
  • Ah, it just wanted an .aux file. Now I'm good. – cgmil May 20 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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