How to Convert LaTeX to HTML from the Windows Command Prompt
At a glance
- 1. Install TeX4ht
Use MiKTeX Console to install the tex4ht package, then check that MiKTeX’s binaries are available on PATH.
- 2. Open the source folder
In Command Prompt, change to the directory containing your .tex file, using quotes if the path contains spaces.
- 3. Run htlatex
Convert the document by running htlatex followed by the source filename.
- 4. Check the output
Open the generated HTML file and review any warnings, missing images, or unsupported commands.
To convert a LaTeX document to HTML on Windows, use TeX4ht, a TeX-based conversion system. In a MiKTeX installation, the usual command-line entry point is htlatex. Run it from Command Prompt in the folder where your .tex file is saved; the default configuration produces an HTML file alongside the source, along with any needed assets.
1. Install TeX4ht in MiKTeX
Open MiKTeX Console, select the package-management view, and search for tex4ht. Install the package if it is not already present. Depending on your MiKTeX setup, package installation may require administrator mode, or MiKTeX may offer to install missing packages when you compile.
If you have just installed the package, close and reopen Command Prompt before testing the command. MiKTeX’s binary directory should normally be added to your Windows PATH during installation.
2. Open Command Prompt in the document folder
For example, if your source file is report.tex in C:\Users\Ava\Documents\paper, open Command Prompt and enter:
cd /d "C:\Users\Ava\Documents\paper"
The /d option changes both the current directory and drive if necessary. Quotes are important when a directory name contains spaces. You can also open the folder in File Explorer, select its address bar, type cmd, and press Enter to open a prompt there.
3. Run the conversion
At the prompt, run:
htlatex report.tex
Replace report.tex with the name of your own source file. If the filename contains spaces, quote it:
htlatex "my report.tex"
TeX4ht processes the document and typically creates report.html in the same folder. It may also create CSS, image, and auxiliary files. Keep those files together when you publish or move the HTML: the page can refer to them.
Worked example
Suppose notes.tex contains:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\section{A short note}
The quadratic formula for $ax^2+bx+c=0$, with $a\ne0$, is
\[
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
\]
\end{document}
Save it as notes.tex, open Command Prompt in that folder, and run:
htlatex notes.tex
After the conversion finishes, look for notes.html. Open it in a browser to inspect the result. TeX4ht may represent mathematics using HTML, CSS, or image-based output depending on its configuration and the document features; the exact rendering is not necessarily identical to a PDF.
If Windows does not recognize htlatex
An error such as 'htlatex' is not recognized as an internal or external command means that Windows cannot locate the executable. First check that the MiKTeX tex4ht package is installed. Then run:
where htlatex
If that reports no location, confirm that MiKTeX’s miktex\bin directory is on your PATH. You can find the directory in MiKTeX Console’s settings or by locating your MiKTeX installation. After updating PATH, open a new Command Prompt and try where htlatex again. Avoid guessing an executable path: the install location differs between user and administrator installations.
Common problems
- The command runs, but conversion stops with a LaTeX error. TeX4ht still has to process your source with TeX. Fix the reported source error first; a document that does not compile normally will not convert cleanly.
- A package or font is missing. Install the missing MiKTeX package when prompted, or search for it in MiKTeX Console, then rerun the command.
- The HTML page lacks an image or stylesheet. Keep the generated supporting files beside the HTML file, and check that your source image files are accessible from the document’s folder.
- References or the table of contents are incomplete. Like a normal LaTeX build, cross-references may need another run to settle. Rerun
htlatex report.texand check the resulting page. - You expected a PDF-to-HTML converter.
htlatexconverts the LaTeX source and uses TeX4ht’s processing tools; it is not a general converter for an already-created PDF.
For documents with complex packages or custom macros, inspect the HTML output rather than assuming that every PDF feature has a direct HTML equivalent. TeX4ht provides configuration options for more specialized conversions, but the plain htlatex filename.tex command is the right first test for a typical document.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.