This MWE

 p_{i-1} &= -(p_{i})' - \theta p_i   \hspace*{5pt} \text{if} \hspace{10pt} i=n

Compiles with no problem in pdflatex and produces

enter image description here

But when compiling using

make4ht  -ulm default  foo.tex "mathjax,htm" "-cunihtf -utf8"

No error is generated by HTML looks like this

enter image description here

Removing the star from \hspace then it works OK. So for now, I removed the star from \hspace.

The raw HTML is

<!DOCTYPE html> 
<html lang='en-US' xml:lang='en-US'> 
<meta charset='utf-8' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='width=device-width,initial-scale=1' name='viewport' /> 
<link href='foo.css' rel='stylesheet' type='text/css' /> 
<meta content='foo.tex' name='src' /> 
<script>window.MathJax = { tex: { tags: "ams", }, }; </script> 
 <script async='async' id='MathJax-script' src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js' type='text/javascript'></script>  
<!-- l. 7 --><p class='noindent'>\begin {align*}  p_{i-1} &amp;= -(p_{i})' - \theta p_i \hspace *{5pt} \text {if} \hspace {10pt} i=n  \end {align*}

Is this a tex4ht issue or mathjax? Does one need to add special configuration to tex4ht mathjax .cfg to avoid this error?

TL 2022

  • 2
    it is an issue with your code, if you use mathjax option it is your responsibility to use markup understood by mathjax. You could use \quad instead of \hspace*{... or for that matter you could use \hspace as the *does nothing useful in math mode Commented Oct 21, 2022 at 18:03

1 Answer 1


There are several problems. First one is that the * character is separated from \hspace in the HTML output, which is caused by the process of detokenization. But even if we try to fix that and remove the spurious space, it doesn't help. MathJax doesn't know this command, so it doesn't display your equation. I wasn't even able to define the starred commands, it seems that it isn't possible to define them easily for MathJax.

I would use a custom command instead. I've wrote about various means how to configure MathJax recently, so please read this section.

The interesting change in TeX4ht sources is that it is now possible to include file with macro definitions to MathJax. This way, you can have a file with custom command that is used in both PDF compilation, and with MathJax. This file needs to contain only macro definitions, it cannot contain any other LaTeX commands.

Here is an update sample file:

 p_{i-1} &= -(p_{i})' - \theta p_i  \myspace \text{if} \hspace{10pt} i=n


You can see that it uses the \myspace command, and that it includes the mymacros file. This file can look like this:


Now you need to tell TeX4ht to use this file for MathJax, which can be done using the new MathJaxMacros configuration:


It produces a following HTML:

<!-- l. 4 --><p class='noindent'>\(\newcommand\myspace{\quad}
\) \begin {align*}  p_{i-1} &amp;= -(p_{i})' - \theta p_i \myspace \text {if} \hspace {10pt} i=n  \end {align*}

Which is rendered in this way:

enter image description here

You must log in to answer this question.

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