I had to comment out \usepackage[T1]{fontenc} when running tex4ht to bypass an issue why-tex4ht-do-not-change-font-size-of-verb-when-including-usepackaget1font but now I find a strange side effect for not inlcuding this package, which is tex4ht changes \_ in math mode to X in the HTML !

This is auto-generated by Maple. So I am forced now to use \usepackage[T1]{fontenc}

Is there a reason why tex4ht changes \_ to X when not including \usepackage[T1]{fontenc}

PDF has no problem, it is only tex4ht. Here is MWE


   %\usepackage[T1]{fontenc} %do not use. Make tex4ht \verb not accept  different fonts


    y = \_C1

Compiled using make4ht --lua -u foo.tex and this is the output

Mathematica graphics

While lualatex foo.tex gives PDF

Mathematica graphics

Question is: Must one include \usepackage[T1]{fontenc} for tex4ht to give correct outpout? only reason I do not include is to due to the font issue size I linked to above, else I would just include it. And is this is what tex4ht should do? Why it works ok with pdf?

ps. At first I thought it was the \it which causes this, but now I see it is the \_ so I edited the question slightly.

  • 1
    For reasons I don't know (but probably for denoting some HTML entity), when \_ is processed in your test file, eventually \a:HChar is used, which expands to x. This has nothing to do with \it; try with \[\_y={\it \_C1}\] and you'll get an x in front of y as well; curiously, not with $\_y={\it \_C1}$ – egreg Jul 27 '16 at 20:47

The problem is clearly this definition from latex.4ht:

\def\csname ?\string\textunderscore\endcsname{\leavevmode#1}}

\HChar includes special instruction for tex4ht DVI processor to replace next character (which is x) with character with value 95. As math is converted to image by other DVI processor (DVIPS or DVIPNG), which doesn't understand this instruction, the character which should be removed, x, remains here instead of _. we need to disable the use of \HChar in mathmode, use \mathunderscore instead.

Unfortunately, LaTeX default definition of \_ inserts \textunderscore even in math mode:


we can change it to use \mathunderscore in the math mode:


You can try it with the following .cfg file:


The result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.