# textit use with tex4ht in mathjax mode

I am trying to compile Latex code generated by Maple. The Latex generated contains things like \textit{\_C1} which works OK in pdf, but when compiled to HTML using tex4ht, in mathjax mode, it does not work, since mathjax does not support nesting inside this macro (reference)

MathJax does not process macros in text-mode, since it only handles math-mode macros. So within \text{} or \hbox{} or other text-mode material embedded within math mode, no macros are performed. That is a feature not a bug. :-)

I tried to use \renewcommand to redefine \textit{\_C1} to {\it \_C1} which works in HTML/mathjax, but not able to do it. The command is not changing in HTML, it still shows as \textit{\_C1}

Here is MWE

\documentclass[12pt]{article}
\usepackage{amsmath}

\ifdefined\HCode
\renewcommand{\textit}[1]{{\it#1}}
\fi

\begin{document}

$y(t) = \textit{\_C1}$

$y (t) = {\it \_C1}$
\end{document}


Compiled to pdf using lualatex, both give same output

But compiled to html

  make4ht -ulm default foo3.tex "mathjax,htm"


The HTML generated is

<!DOCTYPE html>
<html lang="en-US" xml:lang="en-US" >
<meta  charset="utf-8" />
<meta name="generator" content="TeX4ht (https://tug.org/tex4ht/)" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="src" content="foo3.tex" />
<script>window.MathJax = { tex: { tags: "ams", inlineMath: [ ["\\$$","\\$$"] ], displayMath: [ ['$$','$$'], ["\$","\$"] ], processEscapes: true, processEnvironments: true, packages: ['base', 'color', 'ams'] }, loader: { load: ['[tex]/color', '[tex]/ams'] } }; </script>
<script type="text/javascript" async="async" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js"></script>
>
<!--l. 12--><p class="noindent" >$y(t) = \textit{\_C1}$
</p><!--l. 17--><p class="indent" >   $y (t) ={\it \_C1}$ </p>
</body>
</html>



Using TL 2020

• Newer versions of MathJax include an extension to support macros within \text{}, including \it, see docs.mathjax.org/en/latest/input/tex/extensions/textmacros.html. Sep 1, 2020 at 8:16
• @PeterKrautzberger thanks. I use mathjax 3.*, will try to add this textmacro to my configutation and see what I get. Sep 1, 2020 at 8:18
• @PeterKrautzberger thanks again, got it working. Sep 1, 2020 at 8:39

Does your LaTeX generator produce \textit in math mode? I would say that it is an error. It should use \mathit instead. \it shouldn't be used at all, it is a deprecated command. Anyway, as your document is rendered by MathJax and it explicitly says that it doesn't support math content inside \textit, so there is nothing we could do.

This works in both pdflatex and MathJax:

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}

$y(t) = \mathit{\_C1}$

$y (t) = {\it \_C1}$
\end{document}


• Thanks. Maple just generates Latex for an expression. i.e. given a math expression, it generates only the latex for this expression. Then I copy this latex to my latex document and put it inside . So I would say most of the latex generated is meant to be used in math mode, but Mapleitself only generate the latex for the expression, and does not generate $...$ or $...$ with it. Sep 1, 2020 at 8:10
• Thanks Michal, got it working ok using the new macro from mathjax. I did not know about it. Thanks for the info about mathit. I do not think Maple will change their code to do that which would be the better solution otherwise. Sep 1, 2020 at 8:41
• @Nasser yes, a macro definition for MathJax is probably only solution. Sep 1, 2020 at 8:44