[tex4ht] Macro parameter bug
Francis Wright
f.j.wright at live.co.uk
Thu Mar 11 12:55:44 CET 2021
Dear Michal,
Thanks for your very prompt reply. Changing the catcode solves the problem. You have also answered my next question, which was going to be about the right way to configure MathJax. (I currently post-process the HTML files.)
In fact, the way I define macros etc. for use in MathJax is like this:
\(
\newcommand{\gc}[1]{\boldsymbol{#1}}
\)%
and I reconfigure MathJax to load the newcommand package. I think that the TeX4ht code that outputs \(...\) etc. essentially verbatim should output # verbatim as well instead of doubling it as at present, and that perhaps modifying \alteqtoks would be the way to do that. I'll experiment with this.
Thanks again, Francis
-----Original Message-----
From: Michal Hoftich <michal.h21 at gmail.com>
Sent: Wednesday, 10 March 2021 9:46 pm
To: Francis Wright <f.j.wright at live.co.uk>
Cc: tex4ht at tug.org
Subject: Re: [tex4ht] Macro parameter bug
Dear Francis,
On Wed, Mar 10, 2021 at 05:46:41PM +0000, Francis Wright wrote:
>I'm using TeX4ht to generate HTML including mathematics to be processed
>by MathJax from LaTeX source files. MathJax supports macro and
>environment definitions provided they are within a math environment,
>and this works fine via TeX4ht provided the definition has no
>parameters. But if I use parameters, the # characters get doubled. I
>currently post-process my HTML files to convert ## back to #, which
>works, but it would be nice if TeX4ht didn't double them in the first
>place. Is there a better way to handle this? I can't find any way to
>escape or encode the # characters to avoid this.
Interesting issue, thanks for the report. I think easiest solution is to change catcode of # to letter before the MathJax configuration, like in the following configuration file:
%%%%%%%%%%%%%%%%%%
\Preamble{xhtml}
\catcode`\#=11
\Configure{MathJaxConfig}{{
tex: {
tags: "ams",
\detokenize{%
macros: {
hello: ["\\sqrt{#1}",1],
sl: "\\it",
}
}
}
}}
% don't forget to return catcode back to the original value
\catcode`\#=6
\begin{document}
\EndPreamble
%%%%%%%%%%%%%%%%%%
It is converted as:
<script>window.MathJax = { tex: { tags: "ams", macros: {
hello: ["\\sqrt{#1}",1],
sl: "\\it",
} } }</script>
in the HTML file, which works correctly.
Best regards,
Michal
More information about the tex4ht
mailing list.