3

I'm using tex4ht to produce HTML that contains mathematical content to be rendered using MathJax.

This question is about inline mathematical content in moving arguments, such as \section{\(y^2\)} and \caption{\(y^2\)}.

Working minimal example

The following code compiles fine:

\documentclass{article}
\begin{document}
\section{$y^2$}
\end{document}

Non-working minimal example

Using \(...\) within the moving argument makes the compilation fail:

\documentclass{article}
\begin{document}
\section{\(y^2\)}
\end{document}

Compilation

For both the working, and the non-working minimum working example, I'm using the following command to compile:

make4ht -a debug mwe.tex "mathjax"

texmf-dist/tex/generic/tex4ht/mathjax-latex-4ht.4ht

I think that this will likely come down to redefining \AltlMath from mathjax-latex-4ht.4ht, to make it robust. The default definition is:

\long\def\AltlMath#1\){\expandafter\alteqtoks{\(#1\)}\)}

Question

How can I configure AltlMath to be robust so that \(...\) works within moving arguments?

Footnote: changing the .tex file is not an option :)

2 Answers 2

4

The MathJax configuration for TeX4ht provides command for commands that cause issues in sections: \fixmathjaxtoc. The problem is that some commands cause issues when they are written to the TOC file.

Try this config file:

\Preamble{xhtml}

\fixmathjaxtoc\(
\fixmathjaxtoc\)
\begin{document}
\EndPreamble

This is the result:

enter image description here

4
  • Ah, of course! That's wonderful, thank you so much. I do fully intend to help with the documentation of tex4ht once work allows. Thank you!
    – cmhughes
    Feb 18, 2021 at 13:43
  • @cmhughes I've added this to TeX4ht sources. It would be great if you could take a look at the docs! I found that this issue is even already described in the draft
    – michal.h21
    Feb 18, 2021 at 19:16
  • This looks great, thanks for the link. I assume the source is still in your github. I'm hopeful to contribute to it once things calm down at work. I use make4ht and tex4ht a lot, and your help has been invaluable
    – cmhughes
    Feb 18, 2021 at 20:25
  • 1
    @cmhughes yes, this pages is automatically generated using Github Actions from github.com/michal-h21/tex4ht-doc. It needs lot of work, spell checking, grammar checking, expanding sections with information from older documentation or from my answers here, for example.
    – michal.h21
    Feb 18, 2021 at 20:39
0

Is this helps you?

%%mwe.cfg
    \Preamble{html}
    \newtoks\eqtoks 
    \def\AltMath#1${\eqtoks{$#1$}% 
       \HCode{\the\eqtoks}$}
    \Configure{$}{}{}{\expandafter\AltMath}  
    \def\AltlMathI#1\){\eqtoks{\(#1\)}% 
            \HCode{\the\eqtoks}}
    \Configure{()}{\AltlMathI}{}
    \begin{document}
    \EndPreamble

Modified TeX code:

\section{\protect\(y^2\)}

It works for me....

Please excuse, if not so ....

4
  • When I place this in mwe.cfg and run make4ht -m draft -a debug -c mwe.cfg mwe.tex the document does not compile. Did it compile for you?
    – cmhughes
    Feb 18, 2021 at 13:08
  • Sorry, please check the update ....
    – MadyYuvi
    Feb 18, 2021 at 13:26
  • Thanks for looking at this. As I noted in my question: changing the .tex file is not an option :) I know that I can add \protect to all of these, but if that were an option, then I would simply change them all to $...$.
    – cmhughes
    Feb 18, 2021 at 13:31
  • I read your MWE, I thought that you don't want to change \(...\) to $...$1, but now I understood that don't want to give \protect` too....sorry....
    – MadyYuvi
    Feb 18, 2021 at 13:40

You must log in to answer this question.

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