4

I do not know if this is new error, caused by latest TL update. But this is first time I see it.

This MWE compiles with no problem with lualatex, but gives

(/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/graphics-hooks.4ht) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty
! Missing number, treated as zero.
<to be read again>
^
l.39 \catcode`\^^
               A=\catcode`\%
?

When compiled with tex4ht. This is the smallest example I could make it to show the error. The Latex is auto-generated.

\documentclass[11pt]{article}
\usepackage{amsmath} 
\usepackage{mathtools}

\begin{document}
\begin{align*}
\frac{1}{18} \, \sqrt{3} \log\left(\frac{{\left| 6 \, x - 2 \, \sqrt{3} \right|}}
  {{\left| 6 \, x + 2 \, \sqrt{3} \right|}}\right) - \frac{1}{18} \, \sqrt{3} 
  \log\left(-\frac{{\left| -6 \, x - 8 \, \sqrt{3} + 6 \, \sqrt{x^{2} + 1} - \frac{6}{x - \sqrt{x^{2} + 1}} \right|}}
  {2 \, {\left(3 \, x - 4 \, \sqrt{3} - 3 \, \sqrt{x^{2} + 1} + \frac{3}{x - \sqrt{x^{2} + 1}}\right)}}\right) 
  - \frac{4 \, {\left(x - \sqrt{x^{2} + 1} + \frac{1}{x - \sqrt{x^{2} + 1}}\right)}}
  {3 \, {\left(3 \, {\left(x - \sqrt{x^{2} + 1} + 
  \frac{1}{x - \sqrt{x^{2} + 1}}\right)}^{2} - 16\right)}} - \frac{4 \, x}{3 \, {\left(3 \, x^{2} - 1\right)}}
\end{align*}
\end{document}

And now I compile using:

make4ht -ulm default -a debug foo5.tex "htm"

it gives

(base) >make4ht -ulm default -a debug foo5.tex "htm"
[INFO]    mkparams: Output dir:
[INFO]    mkparams: Compiler: dvilualatex
[INFO]    mkparams: Latex options: -jobname=foo5
[INFO]    mkparams: tex4ht.sty: xhtml,htm,charset=utf-8
[INFO]    mkparams: tex4ht:  -cmozhtf -utf8
[INFO]    mkparams: build_file: foo5.mk4
[INFO]    mkparams: Output format: html5
[STATUS]  make4ht: Conversion started
[STATUS]  make4ht: Input file: foo5.tex
[INFO]    mkutils: Load extension       common_domfilters
[INFO]    mkutils: Cannot open config file      foo5.mk4
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: setting param ext
[INFO]    make4ht-lib: Adding:  ext     dvi
[INFO]    htlatex: LaTeX call: dvilualatex --interaction=errorstopmode -jobname=foo5   '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode xhtml,htm,charset=utf-8,html5.a.b.c.\input "\detokenize{foo5.tex}"'
This is LuaTeX, Version 1.12.0 (TeX Live 2020)
 restricted system commands enabled.
LaTeX2e <2020-10-01> patch level 2


L3 programming layer <2020-12-07> xparse <2020-03-03> (./foo5.tex (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size11.clo)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/tex4ht.sty) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/usepackage.4ht) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2020/texmf-dist/tex/latex/mathtools/mathtools.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/tools/calc.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/mathtools/mhsetup.sty)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file
::::::::::::::::::::::::::::::::::::::::::
) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/tex4ht.sty
--- needs --- tex4ht foo5 ---
(./foo5.tmp) (./foo5.xref) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/latex.4ht (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/lm/ot1lmr.fd)) (/usr/local/texlive/2020/texmf-dist/tex/generic/kastrup/binhex.tex) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/tuenc.def) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/tuenc-luatex.4ht
(/usr/local/texlive/2020/texmf-dist/tex/luatex/luatexbase/luatexbase.sty (/usr/local/texlive/2020/texmf-dist/tex/luatex/ctablestack/ctablestack.sty)) (/usr/local/texlive/2020/texmf-dist/tex/lualatex/luacode/luacode.sty (/usr/local/texlive/2020/texmf-dist/tex/generic/iftex/ifluatex.sty (/usr/local/texlive/2020/texmf-dist/tex/generic/iftex/iftex.sty))) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht)
(/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/fontmath.4ht (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/article.4ht (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/amsmath.4ht
(/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/amstext.4ht (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/amsbsy.4ht (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/amsopn.4ht (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/mathtools.4ht (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht)) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/unicode.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/html5.4ht))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-dvips.def) (./foo5.aux) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2020/texmf-dist/tex/generic/tex4ht/graphics-hooks.4ht) (/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty
! Missing number, treated as zero.
<to be read again>
^
l.39 \catcode`\^^
               A=\catcode`\%
?

When removing the \usepackage{mathtools} package, it compiles OK. No errors. TL fully updated 3-4 days ago.

make4ht --version
make4ht version v0.3f

which tex4ht
/usr/local/texlive/2020/bin/x86_64-linux/tex4ht
5

Edit:

I've found the source of this issue. TeX4ht redefines \@begindocumenthook and executes some code before and after it. \@begindocumenthook contained code that is added using \AtBeginDocument. It was deprecated by the new LaTeX hook system. Because it is not used anymore, TeX4ht code that handled \AtBeginDocument is not executed, which results in this catcode clash.

This issue can be fixed by using the hook system to execute the TeX4ht handling of \AtBeginDocument. I've fixed it in TeX4ht sources already. In the meantime, you can emulate it using the following .cfg file:

\Preamble{xhtml}
\AddToHook{begindocument/before}[tex4ht]{\csname a:AtBeginDocument\endcsname}
\AddToHook{begindocument/end}[tex4ht]{\csname b:AtBeginDocument\endcsname}
\begin{document}
\EndPreamble

Original answer:

Mathtools loads the graphicx package in \AtBeginDocument. It is loaded after package .4ht files had been processed and there is some catcode clash, it seems.

The simplest fix is to load graphicx package in your document, as Egreg showed. Fix on the TeX4ht side is to load graphicx in mathtools.4ht:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% mathtools.4ht                         2009-05-21-09:32 %
% Copyright (C) 2007--2009       Eitan M. Gurari         %
%                                                        %
% This work may be distributed and/or modified under the %
% conditions of the LaTeX Project Public License, either %
% version 1.3c of this license or (at your option) any   %
% later version. The latest version of this license is   %
% in                                                     %
%   http://www.latex-project.org/lppl.txt                %
% and version 1.3c or later is part of all distributions %
% of LaTeX version 2005/12/01 or later.                  %
%                                                        %
% This work has the LPPL maintenance status "maintained".%
%                                                        %
% This Current Maintainer of this work                   %
% is Eitan M. Gurari.                                    %
%                                                        %
% If you modify this program your changing its signature %
% with a directive of the following form will be         %
% appreciated.                                           %
%            \message{signature}                         %
%                                                        %
%                             gurari@cse.ohio-state.edu  %
%                 http://www.cse.ohio-state.edu/~gurari  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2009-05-21-09:32}

\@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}}

\ifx \o:endgathered:\:UnDef\else
   \HRestore\endgathered
\fi
\def\shortintertext{\intertext}
\def\:tempc#1#2{{\csname a:prescript\endcsname}\sp{#1}\sb{#2}}
\expandafter\HLet\csname prescript \endcsname=\:tempc
\NewConfigure{prescript}{1}
\Configure{prescript}{\HCode{<mrow class="prescript"></mrow>}}
\renewenvironment{dcases}[1][c]{%
  \RIfM@\else
      \nonmatherr@{\begin{\@currenvir}}%
  \fi
  \left\lbrace
  \vcenter \bgroup
      \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
      \spread@equation
      \ialign\bgroup
        \strut@$\m@th\displaystyle{##}$\hfil&\quad$\m@th\displaystyle{##}$\hfil\strut@
        \crcr
}
{\endaligned\right.}
                                    \catcode`\#13 \catcode`\!6
\def\reg:dcases[!1]{%
  \RIfM@\else
      \nonmatherr@{\begin{dcases}}%
  \fi
  \vcenter\bgroup
    \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
    \SaveMkHalignConf:g{dcases}%
    \MkHalign#{$\m@th\displaystyle{\HCode{}}#$&\quad$\m@th\displaystyle{\HCode{}}#$}%
}
                                    \catcode`\#=6 \catcode`\!=12
\def\:tempc{\crcr\EndMkHalign
    \RecallMkHalignConfig \egroup\b:dcases \right.}
\HLet\enddcases\:tempc
\def\:temp{\left\lbrace   \pic:MkHalign{dcases}}
\expandafter\HLet\csname \string\dcases\endcsname\:temp
\NewConfigure{dcases}{6}
\renewenvironment{dcases*}[1][c]{%
  \RIfM@\else
      \nonmatherr@{\begin{\@currenvir}}%
  \fi
  \left\lbrace
  \vcenter \bgroup
      \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
      \spread@equation
      \ialign\bgroup
        \strut@$\m@th\displaystyle{##}$\hfil&\quad{##}\hfil\strut@
        \crcr
}
{\endaligned\right.}
                                    \catcode`\#13 \catcode`\!6
\expandafter\def\csname reg:dcases*\endcsname[!1]{%
  \RIfM@\else
      \nonmatherr@{\begin{dcases*}}%
  \fi
  \vcenter\bgroup
    \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
    \SaveMkHalignConf:g{dcases*}%
    \MkHalign#{$\m@th\displaystyle{\HCode{}}#$\quad&#}%
}
                                    \catcode`\#=6 \catcode`\!=12
\def\:tempc{\crcr\EndMkHalign
    \RecallMkHalignConfig \egroup\csname b:dcases*\endcsname \right.}
\expandafter\HLet\csname enddcases*\endcsname\:tempc
\def\:temp{\left\lbrace   \pic:MkHalign{dcases*}}
\expandafter\HLet\csname \string\dcases*\endcsname\:temp
\NewConfigure{dcases*}{6}

\edef\cat:underscore{%
   \noexpand\catcode`\noexpand\_=\the\catcode`\_ }
\catcode`\_=11
\def\MT_gathered_pre:{}
      \def\MT_gathered_post:{}
      \def\MT_gathered_env_end:{}
                                    \catcode`\#13 \catcode`\!6
\def\reg:MT_gathered_env[!1]{%
  \RIfM@\else
      \nonmatherr@{\begin{MT_gathered_env}}%
  \fi
  \null  \vcenter\bgroup
    \Let@ \chardef\dspbrk@context\@ne \restore@math@cr
    \SaveMkHalignConf:g{MT_gathered_env}%
\MkHalign#{$\m@th\displaystyle{\HCode{}}#$}%
}
                                    \catcode`\#=6 \catcode`\!=12
\def\:tempc{\crcr\EndMkHalign
    \RecallMkHalignConfig \egroup\b:MT_gathered_env}
\HLet\endMT_gathered_env\:tempc
\def\:temp{\pic:MkHalign{MT_gathered_env}}
\expandafter\HLet\csname \string\MT_gathered_env\endcsname\:temp
\NewConfigure{MT_gathered_env}{6}
\def\:tempc#1#2{{\m@th#1{#2}}}
\HLet\MT_cramped_internal:Nn\:tempc

\cat:underscore
\Hinput{mathtools}
\endinput

The document is processed without errors with this fix.

4
  • tex4ht seems to change the catcode of ^ to 12, is this needed? – Ulrike Fischer Dec 24 '20 at 14:23
  • @UlrikeFischer handling of sub and superscripts is pretty complicated in TeX4ht, it changes their catcodes when .4ht files are processed, as it does various tricks at that moment. – michal.h21 Dec 24 '20 at 14:45
  • @UlrikeFischer I've found the issue, please see the updated answer. – michal.h21 Dec 25 '20 at 13:24
  • ah, good find. I hadn't the time to look, but I suspected that some resetting code didn't work anymore. – Ulrike Fischer Dec 25 '20 at 18:08
2

The error happens during loading of graphics.sty. I'm not sure why this happens, but a workaround is to load graphicx before mathtools.

\documentclass{article}
\usepackage{graphicx}
\usepackage{mathtools}

\begin{document}
test
\begin{align*} a&=b\\c&=d\end{align*}
\end{document}

What's the problem? That mathtools does

\AtBeginDocument{\RequirePackage{graphicx}...}

which is incorrect and should be

\RequirePackage{graphicx}
\AtBeginDocument{...}

On the other hand tex4ht makes ^ into a math active character, hence with category code 12. Loading a package with “strange” category codes can lead to unexpected results.

So, in my opinion, mathtools and tex4ht are linked in a conspiracy and both should fix the respective problems; mathtools should load the package earlier and tex4ht should change category codes as late as possible.

7
  • mathtools loads graphicx at begin document (no idea why ...), and tex4ht has reset the catcode of ^ to 12 there (no idea why too ...) – Ulrike Fischer Dec 24 '20 at 13:43
  • @UlrikeFischer I'm not sure why mathtools loads graphicx at begin document in the first place. With tex4ht the ^ is made into a math active character (they surely have reasons to). – egreg Dec 24 '20 at 14:30
  • perhaps they load graphicx late to avoid an option clash error. – Ulrike Fischer Dec 24 '20 at 14:34
  • @UlrikeFischer Well, then it should be done at end preamble rather than at begin document. – egreg Dec 24 '20 at 14:36
  • yes, but probably the end preamble hook didn't exist at the time the code was written ;-) – Ulrike Fischer Dec 24 '20 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.