1

I have ht5mjlatex.cfg as defined here, and a foo.tex containing:

\documentclass{article}
\renewcommand{\Pr}[1]{P(#1)}
\begin{document}
    $\Pr{h}$
\end{document}

As described in that post, I try to convert it to MathJax-HTML. When I try

htlatex foo.tex ht5mjlatex.cfg

I receive the following error:

! Limit controls must follow a math operator.
\n:limits: ->\o:limits:
                        \:l:mits
l.4     $\Pr
         {h}$
?
! Emergency stop.

Why does this problem occur? I can work around it by avoiding redefining \Pr and such, but for the life of me I can't understand what it should be occurring in the first place.

user541686
  • 9,547
  • Is defining \Pr as \mathop{P(#1)} any help? I can only guess that htlatex tries to add a \limits or \nolimits command after \Pr which doesn't work in your redefined command. – siracusa May 24 '19 at 10:48
  • @siracusa: Nope I in fact had \mathop originally. It's the same problem. – user541686 May 24 '19 at 11:12

2 Answers2

2

You need to delay the \renewcommand, or it would be overridden by the default definitions.

\documentclass{article}

\AtBeginDocument{%
  \renewcommand{\Pr}[1]{P(#1)}%
}

\begin{document}
    $\Pr{h}$
\end{document}

The dangers of using \renewcommand.

egreg
  • 1,121,712
  • 1
    Could you add a bit of explanation on why it fails with htlatex? In a normal document it doesn't seem to make a difference. – siracusa May 24 '19 at 14:51
  • 1
    @siracusa \Pr is a core command of LaTeX and the specific files of TeX4ht have to “translate” it into something manageable by HTML; they do the job at begin document, so the redefinition of \Pr gets overridden. Why the error is about \limits I don't really know. – egreg May 24 '19 at 15:44
  • @egreg: "they do the job at begin document, so the redefinition of \Pr gets overridden"... Confused, so why is there no error if I remove the \renewcommand? – user541686 May 25 '19 at 01:22
  • @Mehrdad The original \Pr is a \mathop, so inserting one of the limits commands after it is correct – siracusa May 25 '19 at 18:16
  • @siracusa: But \renewcommand{\Pr}[1]{\mathop{P(#1)}} doesn't work...? – user541686 May 26 '19 at 12:38
1

As this is too long for the comments: Based on egreg's answer, I think what happens is that htlatex adds a hook to the preamble that looks something like

\AtBeginDocument{\let\oldPr=\Pr \renewcommand\Pr{\oldPr\nolimits}}

with additional code for generating the HTML output.

The standard definition for\Pr is

\newcommand\Pr{\mathop{\operator@font Pr}}

so an example usage of \Pr{h} then would expand as

\Pr{h}
\oldPr\nolimits{h}
\mathop{\operator@font Pr}\nolimits{h}

which gives a correct usage of \nolimits as it occurs after a \mathop.

Now add your redefinition to the preamble:

\renewcommand{\Pr}[1]{\mathop{P(#1)}}

The expansion of \Pr{h} now looks like

\Pr{h}
\oldPr\nolimits{h}
\mathop{P(\nolimits)}{h}

As you can see, the \nolimits is now parsed as first argument of your new \Pr definition thereby going at a wrong position, especially not after a \mathop, which gives the error message you receive

! Limit controls must follow a math operator.
siracusa
  • 13,411