How to Fix MathML and MathJax Issues in TeX4ht
At a glance
- 1. Choose an output
Decide whether TeX4ht should convert equations to MathML or leave TeX for MathJax to process.
- 2. Test a small file
Compile a minimal document first to separate conversion problems from package or document-specific issues.
- 3. Check the HTML
Inspect the generated file to see whether it contains MathML, TeX markup, or image-based equations.
- 4. Verify scripts and logs
Check the browser console, MathJax script loading, TeX4ht logs, and required compilation passes.
Conversion problems with TeX4ht often come from mixing up two different approaches: writing equations as MathML during conversion, and asking MathJax to typeset math in the browser. The right fix depends on what the generated HTML contains.
Start by converting a small document and inspecting its output. If the page contains MathML, focus on whether that markup is valid and whether the browser can display it. If you want MathJax to process TeX, make sure the generated page actually contains TeX in a form MathJax recognizes and loads the matching MathJax configuration.
MathML and MathJax are different stages
MathML is a markup language for describing mathematical notation. TeX4ht can convert LaTeX math into MathML as part of generating HTML. A browser may display that MathML natively, depending on the browser and environment.
MathJax is a JavaScript math-rendering system. It can process supported input formats in a web page and render them for display. It does not automatically fix every kind of math output: for example, if TeX4ht has already turned an equation into an image, MathJax cannot recover the original expression from that image.
Choose one path first:
| Goal | What to check |
|---|---|
| Generate MathML with TeX4ht | Use a TeX4ht MathML configuration and inspect the resulting MathML in the HTML. |
| Typeset TeX in the browser with MathJax | Ensure the HTML preserves TeX in a form MathJax supports, and load the appropriate MathJax component. |
| Render MathML with MathJax | Confirm that the page contains MathML and that the chosen MathJax setup supports MathML input. |
The exact options available depend on the TeX4ht and MathJax versions and on the conversion command or configuration file in use. Avoid combining options copied from different TeX4ht examples without checking what each one generates.
Make a minimal test
Save this as test.tex:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Inline math: $a^2+b^2=c^2$.
\[
\int_0^1 x^2\,dx = \frac{1}{3}
\]
\end{document}
The amsmath package is included because real documents often use its environments and commands; this example also checks ordinary inline and displayed equations. Try converting it with the MathML option in your TeX4ht installation, for example:
htlatex test.tex "xhtml,mathml" " -cunihtf -utf8"
This is a common form of the legacy htlatex command, not a guarantee that every TeX4ht installation uses identical options. Run it from a directory where TeX can find the file, and check the command output for errors. If your installation uses make4ht or a local configuration, follow that installation’s documentation for the corresponding MathML or MathJax setup.
Open the generated HTML as text. Search for the equation, especially for <math or recognizable TeX delimiters. If you see MathML, TeX4ht has converted the expression; test whether the HTML is valid and whether your target browser displays it. If the source still contains TeX delimiters, verify that MathJax is included and configured for that input. If the equation appears as an <img> element, the conversion used an image-based route instead.
Diagnose the usual failure points
- The wrong output mode is selected. A MathML configuration and a MathJax-oriented configuration do not necessarily produce the same HTML. Decide which output you want before changing options.
- The MathJax script is missing or blocked. For browser-side rendering, inspect the page source and browser developer console. Check for failed network requests, content-security-policy restrictions, and JavaScript errors. A page opened offline may be unable to load a script hosted online.
- The markup does not match the configured input. MathJax must be told to process an input format actually present in the page. A script configured for TeX will not typeset arbitrary TeX4ht output if the math has been converted to something else.
- A command or package is unsupported by the conversion path. If the minimal example works but the full document does not, add packages and macros back gradually. The first addition that breaks conversion often identifies the issue.
- The conversion has not completed successfully. TeX4ht workflows can involve several stages. Look at the full terminal output and generated files rather than relying only on whether an HTML file exists; an incomplete run can leave stale output behind.
A practical troubleshooting sequence
First, compile the minimal example and confirm that the expected HTML file is produced. Next, inspect the HTML to identify the actual representation of the equations. Then test that file in the intended browser and, if using MathJax, check the browser console for script-loading or parsing errors. Finally, repeat the conversion after deleting or moving old generated files, so you know you are viewing the latest output.
If only one expression fails, reduce it to a small example and check whether it uses a custom macro, a package-specific command, or a LaTeX construct that the chosen converter does not support. If all equations fail, investigate the conversion options, MathJax setup, and generated HTML before changing individual equations.
References
- TeX4ht documentation
- MathJax Documentation: MathML Input
- MathJax Documentation: TeX Input
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.