htlatex and make4ht: Convert LaTeX to HTML (2026)
November 11, 2026 · 11 min read
htlatex and make4ht: LaTeX to HTML With TeX4ht, LaTeXML and Pandoc
htlatex is the original TeX4ht command for turning a LaTeX document into a web page. Run htlatex paper.tex and you get paper.html, a stylesheet and any images. This guide decodes its argument string, shows the shorter make4ht command that replaces it, and compares LaTeXML and Pandoc on the same file.
What Does htlatex Actually Do?
The command is a script that ships with TeX4ht, the LaTeX to HTML system Eitan Gurari created at Ohio State University. It compiles your file with LaTeX while loading the tex4ht.sty package, so the DVI file carries special markers that tell the next programs where the HTML tags go. Two helper programs finish the job: tex4ht writes the HTML, and t4ht produces the CSS and image files.
Because a real LaTeX run sits at the centre of every htlatex conversion, TeX4ht understands your own macros and most packages. The TeX4ht project page lists BibLaTeX, TikZ and fontspec among the supported ones.
htlatex paper.tex
Run that in the folder that holds paper.tex. You get paper.html and paper.css next to the source, plus a pile of auxiliary files such as .aux, .4tc, .lg and .dvi. The script calls LaTeX three times before tex4ht and t4ht, so cross-references and the table of contents resolve.
TeX4ht is part of both TeX Live and MiKTeX, according to its CTAN entry. If you have a full TeX install (MacTeX on a Mac is TeX Live), you already have it.
Decoding the htlatex Argument String
You'll find this line copied from the TeX4ht site into many tutorials, usually with no explanation. It produces HTML5 in UTF-8 with MathML for equations:
htlatex paper.tex "xhtml,html5,mathml,charset=utf-8" " -cunihtf -utf8"
The general form is htlatex filename "options1" "options2" "options3" "options4". Each quoted string goes to a different program in the chain:
| Position | Read by | Example | What it controls |
|---|---|---|---|
| options1 | tex4ht.sty | xhtml,html5,mathml,charset=utf-8 | Output flavour, math markup, encoding, page splitting |
| options2 | tex4ht | -cunihtf -utf8 | Font mapping to Unicode and UTF-8 characters |
| options3 | t4ht | -dout/ | Output folder, image generation |
| options4 | latex | -shell-escape | Flags for the LaTeX run itself |
The first string is comma-separated. Per the TeX4ht docs, it must start with html, xhtml or the name of your own .cfg file. Adding a number splits the output into several pages: "html,2" breaks the document at the top two sectioning levels.
Options2 is where htlatex users most often get tripped up. Its first space-separated field is a font directory, usually left empty, so the string has to begin with a space. Drop that space and tex4ht reads -cunihtf as the directory instead of an option.
What Is the Difference Between htlatex and make4ht?
make4ht is the build system for TeX4ht, maintained by Michal Hoftich (version 0.4e on CTAN, dated February 2026). It drives the same tex4ht.sty, tex4ht and t4ht steps, but takes normal command-line flags instead of htlatex's four positional strings. HTML5 is its default output format.
According to the make4ht manual, make4ht -u paper.tex replaces the HTML5 plus UTF-8 htlatex call. The TeX4ht page gives make4ht paper.tex "mathml" as the equivalent of the MathML command above. The flags you'll use most:
| Flag | Effect |
|---|---|
-u | UTF-8 output |
-d out/ | Copy the finished files into out/, keeping image paths intact |
-B build/ | Put .aux, .4tc and other temporary files in build/ |
-x / -l | Compile with XeLaTeX / LuaLaTeX |
-c site | Load your configuration file site.cfg |
-f html5+tidy | Pick a format (html5, xhtml, odt, tei, docbook) and extensions |
-m draft | Run LaTeX once instead of three times |
The bigger difference is the build process. htlatex always runs LaTeX three times and can't call BibTeX or makeindex in between, so people end up running htlatex twice around them. make4ht reads a Lua build file (paper.mk4) where you add those steps or post-process the HTML.
We prefer make4ht for anything new. The flags read like any other CLI tool, -d doesn't break image links, and draft mode saves two LaTeX runs while you iterate. You only need the htlatex form when an old build script depends on it.
To style the output, write a TeX4ht configuration file. This one follows the pattern in the TeX4ht documentation:
\Preamble{xhtml}
\begin{document}
\Css{body { max-width: 42em; margin: auto; }}
\EndPreamble
Save it as site.cfg and run make4ht -c site paper.tex "mathml". The \Css line ends up in the generated stylesheet.
How Do You Keep Equations When Converting LaTeX to HTML?
Math is the real decision in any LaTeX to HTML conversion, and each converter gives you different choices. Your three options are MathML (native browser math), a JavaScript renderer such as MathJax or KaTeX, or images.
- make4ht: the
"mathml"option writes MathML."mathml,mathjax"writes MathML and lets MathJax render it."mathjax"keeps your LaTeX source in the HTML for MathJax to typeset, which the TeX4ht page calls perhaps the best method. Without a math option, TeX4ht can fall back to pictures for equations. - LaTeXML: HTML5 output converts math to Presentation MathML by default.
--mathimagesswitches to PNG images, and the manual's sample--javascript=LaTeXML-maybeMathjax.jsloads MathJax only in browsers without native MathML. - Pandoc:
--math-method=takesmathml,mathjax,katex,webtex,plainorgladtex. Since Pandoc 3.11 (August 2026), MathML is the default and the older--mathjax,--katexand--mathmlflags are deprecated but still work.
We'd pick MathML when readers use screen readers or the page must work without JavaScript. Pick MathJax or KaTeX when you want the same rendering on every browser. Our guide to writing math in Markdown covers how KaTeX and MathJax differ, so we won't repeat it here. Before you settle on KaTeX, read our KaTeX vs LaTeX comparison for the commands it can't render.
LaTeXML: MathML and Structured XML From Your .tex Source
LaTeXML comes from NIST, where it was built for the Digital Library of Mathematical Functions. It emulates TeX in Perl, converts your document to its own XML format, then transforms that XML into HTML5 with MathML and SVG, or into JATS or ePub. According to the LaTeXML site, arXiv uses it for the HTML versions of its papers.
The one-step command, straight from the LaTeXML manual, is:
latexmlc paper.tex --dest=paper.html
If you want to inspect the XML in between, split it into the two underlying programs:
latexml --dest=paper.xml paper.tex
latexmlpost paper --dest=paper.html
The destination extension picks the output. .html gives HTML5 with Presentation MathML, .xhtml gives XHTML with MathML, and --format=html4 turns both math and graphics into images.
Unlike htlatex, LaTeXML doesn't come with TeX Live or MiKTeX. Install it with sudo apt-get install latexml on Debian or Ubuntu, MacPorts on macOS, Chocolatey on Windows, or cpan LaTeXML anywhere Perl runs. The project is candid about its limits: emulating TeX is hard, so expect gaps for packages that have no LaTeXML binding.
Can Pandoc Convert LaTeX to HTML?
Yes. Pandoc reads LaTeX directly and writes clean HTML5 with a single command:
pandoc paper.tex -s -o paper.html
pandoc paper.tex -s --math-method=mathjax -o paper.html
The -s flag writes a complete document with head and body. On Pandoc 3.11 or later, the first line gives you MathML. Older versions default to plain Unicode text for math and need --mathjax instead of --math-method=mathjax.
The catch is that Pandoc doesn't run TeX. It parses LaTeX itself, and the Pandoc manual warns not to expect perfect conversions between formats. In our test with Pandoc 3.8.2.1, a simple \newcommand macro expanded correctly and siunitx units came through. An unknown macro vanished silently along with its argument, and a TikZ picture disappeared entirely. For general Pandoc usage, see our Pandoc Markdown guide.
One .tex File Through All Three Converters
Here's a small test document with a custom macro, inline math, a numbered equation and a table:
\documentclass{article}
\newcommand{\R}{\mathbb{R}}
\begin{document}
\section{Results}
Energy and mass are linked by $E = mc^2$ for every $x \in \R$.
\begin{equation}
\int_0^1 x^2 \, dx = \frac{1}{3}
\end{equation}
\begin{tabular}{ll}
Tool & Math output \\
make4ht & MathML or MathJax \\
LaTeXML & MathML \\
\end{tabular}
\end{document}
make4ht (or plain htlatex) compiles it with your real LaTeX, so \R expands just as it does in your PDF build. LaTeXML handles the macro through its own TeX emulation and writes the equation as MathML. Pandoc expanded \R to \mathbb{R} in our test, but its HTML had no header row for the table, because a LaTeX tabular doesn't mark one.
| make4ht (TeX4ht) | LaTeXML | Pandoc | |
|---|---|---|---|
| Runs a TeX engine | Yes | No, emulates TeX in Perl | No, own LaTeX parser |
| Math output | MathML, MathJax or pictures | MathML by default, PNG optional | MathML by default since 3.11, MathJax, KaTeX |
| Custom macros and packages | Most work | Needs LaTeXML bindings | Simple macros only |
| Install | In TeX Live and MiKTeX | apt, MacPorts, Chocolatey or CPAN | Pandoc installer or package manager |
| Best for | Theses, books, heavy packages | Math-heavy papers, accessible MathML | Simple documents, quick clean HTML |
One limitation applies to all three. None of them reproduces your PDF layout, and a document with unusual packages may need configuration work in any converter. If the page has to look like the PDF, converting the PDF to HTML is the alternative.
Simple Documents: LaTeX to Markdown, Then HTML
If your document is mostly text, headings, lists and math, you can skip the TeX toolchain for the web step. Convert it to Markdown once, then keep editing the Markdown and export HTML when you need it:
pandoc paper.tex -t commonmark_x -o paper.md
The commonmark_x writer keeps math as $...$ and $$...$$ and writes pipe tables. Before you paste the result, put each $$ on its own line and fill in the empty table header row. We also deleted the \begin{equation} and \end{equation} lines Pandoc leaves inside the dollars, and added a Pandoc row to the table:
Our Markdown to HTML converter runs in your browser and returns a full HTML document. Its editor preview renders math with KaTeX from dollar delimiters only, so \(...\) and \[...\] won't render. To be clear, our tools don't compile .tex files or convert full LaTeX documents. Pandoc does the LaTeX step on your own machine.
For the other direction, converting Markdown to LaTeX covers Pandoc's flags. The Markdown to LaTeX tool also has a LaTeX to Markdown mode, but it's a pragmatic parser for simple input, not a TeX engine. To typeset a single formula, the LaTeX equation editor renders it with KaTeX and exports PNG or SVG.
htlatex and LaTeX to HTML Questions
Start with make4ht for any real paper and treat htlatex as the legacy form you'll meet in old scripts. Reach for LaTeXML when MathML quality matters most, and Pandoc when the document is simple and speed counts. If you only need a clean web page from a short, math-light document, convert it to Markdown and finish it in our Markdown editor, where dollar math previews live.