# make4ht cannot render newcommand in mathjax mode

I use file here, and then I run a command

make4ht -uf html5 maths.tex "mathjax"

but the result is not what I want. I find some solution says I have to add something to cfg file, but I do not want to do that, because I think it is complicated. If I define so many commands and environments in a tex file, it is a lot of work for me. so is there some easy way to figure it out?

• The rendering is done by MathJax, so you need to pass the command definitions to it. If you use lot of custom commands, MathML should be an easier way. Jan 4, 2020 at 11:09
• @michal.h21 mathjax itself supports new command and new environment, if we put them into a math environment, and then run the same command, is it OK? Jan 4, 2020 at 11:25

It seems you can put your macro definitions at the beginning of the HTML page and the macros will be available in all subsequent math environments for MathJax. So what we can try to do is to include a file with custom macros verbatim in the HTML file using TeX4ht.

Try the following file, myconfig.cfg:

\Preamble{xhtml,mathjax}
\Configure{@BODY}{\IgnorePar
\HCode{\detokenize{$$}} \special{t4ht*<mymacros.tex} \HCode{\detokenize{$$}}
\par
}
\begin{document}
\EndPreamble


It requires the MathJax processing using mathjax option in the \Preamble command. \Configure{@BODY} inserts code right after the <body> element. We disable possible spurious paragraph using \IgnorePar. The macros must be enclosed in $$ ... $$ in order to be processed by MathJax. \detokenize will prevent their expansion, we need to get them verbatim to the HTML file. \special{t4ht*<filename} instruction includes a file verbatim to the generated file.

Here is a sample mymacros.tex file:

\def\RR{{\bf R}}
\newcommand\bold[1]{{\bf #1}}


We can also introduce a dummy mymacros.sty package, so they are available using \usepackage in the TeX file. Reason why I don't put the macros definitions in the sty file is that MathJax don't support \ProvidesPackage and \endinput macros, wo they would end rendered in the HTML file.

\ProvidesPackage{mymacros}
\input{mymacros.tex}
\endinput


TeX sample:

\documentclass{article}
\usepackage{mymacros}
\begin{document}

Hello $\RR = \bold{x}$
\end{document}


Generated HTML:

<body>
$$\def\RR{{\bf R}} \def\bold#1{{\bf #1}}$$
<!-- l. 5 --><p class='indent'>   Hello $$\RR = \bold{x}$$ </p>
</body>


And rendered page: