is there a good clean minimal converter of well-defined latex code into html (preferably perl)?

I have played with htlatex and latex2html, but they are too ambitious and too complex in their goals and insufficient in their results. they and their output are hard to modify and to clean up or process further. I need something simpler. I even looked at writing my documents in md, primarily because markdown can generate both latex and xhtml. but my main motivation is to be able to create new clean documents. going to markdown for my own purposes loses a lot of latex features without gaining me the xhtml features I want.

now, when I looked at some of my old sample documents, I realized that most of what I want a converter to do is to understand simple standard latex documents. I do not need it to understand user-defined macros. I need the quasi-parser to create valid xhtml and to facilitate eventually conversion to epub.

my guess is that this has been written many times, so if someone knows of a (perl-) parser that does this, please let me know. I thought a little about my list of needs:

  • intelligence about comments (%), escapes (\%, $, \\), etc., and paragraph starts. it should be reasonably smart, but does not have to be perfectly protected against clever bad latex input. (what does \%\\%$%\% mean? the program can just complain.)

  • knowledge of special characters for conversions into html entities (e.g., \"a, \gamma, \cdot)

  • font shapes, sizes, weights, colors, underline, overline, strikethrough

  • knowledge of direct equivalence environments (e.g., \begin{quote} and <quote>, or \section and h1)

  • environments (such as \begin{table} ... \end{table} to <div class="table", or theorem to div class=theorem.)

  • tabulars to table, graphicx to img

  • tabular intelligence (e.g., & to <td>, \\ to <tr>, multicolumn to rowspan, etc); (if anyone has a standalone perl .pm program to do this intelligently standalone, please let me know.)

  • enumerate/itemize/description lists

  • passing math into mathjax (or better yet creating the rescaleable html+css-mathjax final output)

  • hrefs, both internal and external

  • (maybe some spacing, bigskip, medskip, smallskip, \;)

  • some pragma features to direct the converter to include bits of raw html, or to ignore parts of the latex.

  • some features to decide on unrecognized items. for example, this could be to put these into special divs with classes or into comments and css stylability, with options for complaints, and/or printing rather than in comments. the main idea is that one can then write another unix filter program to hook into the output of this program and do further processing.

the tasks are compact and definable.

is there a good starter perl program for this? my problem is that I have too many other tasks, so I start writing a program and then neglect it for so long that I barely remember it, and then the program suffers from bitrot. keeping it standalone and with this level of understanding as its own command-line program should mean that such a converter is more likely to remain maintainable. tabular to table conversion seems to be the most complex part. many of the above tasks seem to require primarily clever regex's, and not much more.

(PS: for me, it could also serve as a lint-checker for what I deem to be good latex documents, aka usepackage{nag}. if a converter can produce nice html, pandoc can then convert to other formats, too.)



  • I think it is much simpler to configure and postprocess output of tex4ht, than to create another converter, even for limited LaTeX syntax
    – michal.h21
    Commented Jan 20, 2014 at 8:06
  • 1
    Try pandoc. It can convert between LaTeX and HTML. Commented Jan 20, 2014 at 14:47
  • 1
    (pandoc dies on my latex documents.) tex4ht (htlatex) is very ambitious, but there are no good configuration tutorials I could find. can one configure it to pass math to mathjax and leave it inline, instead of generating png files; and can one configure it to produce one and only one output file, rather than many (footnotes, png, etc.)
    – ivo Welch
    Commented Jan 20, 2014 at 17:37
  • @ivoWelch maybe this (pandoc dies on my latex documents) has changed since then?
    – Wolf
    Commented Jun 22, 2017 at 9:56

3 Answers 3


I know this has probably been written many times and many times better than what I can write in my two days with modest perl background here, but because I could not find a good starter that is readable and does the basic job, my attempt is at


I would have posted it here, except that it is too long at 400 perl lines (plus a long entities data base, plus a documentation sample). At 400 lines, the perl program should be reasonably maintainable. It could also be better refactored.

Think of it as a good starter and proof-of-concept. The perl program is not attempting to produce documents that match the latex look. instead, it is trying to convert reasonable subset-latex documents to html documents, to be styled with css and mathjax later. It informs the user of what tags have not been converted (and have been passed through for subsequent processing) and what should be styled.

Alas, I am having problems with tabular's, especially \hline (or \toprule, etc.), as well as with formatting columns. I tried

 <table style="tr td:nth-child(2) { text-align:right }">

and about 20 variations thereon including various versions of table, tr, td, but nothing seemed to work.

A minor nuisance is that Regexp::Common balanced matches include their parentheses, so I have to strip them. It also cannot handle two consecutive arguments, in which case I fall back on {.*?} for matching instead. This is really primarily an issue for commands with optional arguments. This isn't handled well, either.

Another nuisance is that <li> and <p> remain unbalanced. thus, they need to be cleaned up by tidy or pandoc if xhtml is needed. Someone who is more clever than I and who has more knowledge of html (e.g., what other tag can end a paragraph tag?) could probably fix this up fairly easily.

I would love to fix this perl program up further to converge to something useful. For me, this quasi-parser will also help me keep my latex files reasonably sane. I will know what passes and is convertble/recognizable and what is not. It's an itch I have had for a long time.

It's pretty useful already, though.

  • The link gives 404 error...
    – Rmano
    Commented Mar 15, 2014 at 21:47
  • This link works: iawltxhtml.ivo-welch.info But I think Ivo should fix this on his own – either here or introduce again the above linked resource.
    – Speravir
    Commented Mar 15, 2014 at 23:07
  • strange...works for me all the time. it's also evolving quickly, as we use it for our specific purposes. docs are behind...and probably a real release.../iaw
    – ivo Welch
    Commented Mar 16, 2014 at 2:14
  • I am putting a version of iawltxhtml intot ivo-welch.info/unprofessional . it is a very good start of perl code to parse into epub (which is nice html). it was the result of much experimentation, that would save others doing the same a lot of time. the zip file is large, because it contains successful complex documents with images. the converter is "abandonware" for now, until I need to return to it. free, of course. but totally unsupported.
    – ivo Welch
    Commented Jun 23, 2017 at 21:09

So far I have found Hevea to be the easiest to use, understand and customize for LaTeX to HTML with lots of custom LaTeX macros to convert. I also spent a lot of time with plasTeX and found it very powerful but with a steep learning curve and hard to master.


It's very much in an alpha state, and probably will always be, but I have a set of LaTeX style files designed to do exactly this. The project is on github.

In particular, there are output versions that will pass the mathematics through to a mathjax-aware system.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .