1

As the MWE below stands, after loading both crossreftools and doclicense, I get the following error on the second pdflatex pass when a restatable theorem is restated.

./restate-thm.tex:43: Undefined control sequence.
\@calc@post@scan ...st@scan \else \def \calc@next 
                                                  {\calc@error #1}\fi \fi \f...

I get no error when...

  • crossreftools is loaded but doclicense is not; or
  • doclicense is loaded but crossreftools is not; or
  • hyperref is not loaded (but crossreftools and doclicense are loaded).

The same behavior occurs if I use the unstarred restatable instead of the starred restatable*.

What could cause the strange interaction?

I note that this only happened today. A couple of days ago, before some TeXLive 2020 updates, it did not occur! And I note that thmtools was updated 2020/07/16 (ver 69); whereas doclicense and other files it uses were not updated since 2020-06-28, and crossreftools was last updated 2019/01/03.

% file restate-thm.tex
\documentclass{book}

% Theorems...
\usepackage{amsmath,amsthm}
\usepackage{thmtools} % loads thm-restate
%
\swapnumbers
%
\declaretheorem[name=Theorem,numberwithin=chapter,style=plain]{theorem}
%
\makeatletter
\declaretheoremstyle[
  notefont=\bfseries,notebraces={}{},
  headformat=\NUMBER\let\thmt@space\@empty\NOTE,
]{namedthmstyle}
%
\declaretheorem[style=namedthmstyle,name=Theorem,title = {},numberlike=theorem
]{namedtheorem}
\makeatother

% Links...
%\usepackage{hyperxmp} % to add metadata info into pdf
\usepackage[colorlinks]{hyperref}

% the problems??
\usepackage[type={CC},modifier={by-nc-nd},version={4.0},lang={english}]{doclicense}%
\usepackage{crossreftools}

\begin{document}

\chapter{Statement}

\begin{restatable*}[Theorem of Pythagoras]{namedtheorem}{PythagorasTheorem}
%\label{thm:Pythagoras}

The square on the hypotenuse of a right triangle equals the sum of the squares on the other two sides.

\end{restatable*}

\chapter{Proof}
Recall the theorem.
\PythagorasTheorem

\end{document}

When thmtools option degug is included, then after the first pdflatex pass I see the following in the log:

Chapter 2.
Key `Theorem of Pythagoras' with value `' ignored by label.
Key `Theorem of Pythagoras' with value `' ignored by name.
Key `Theorem of Pythagoras' with value `' ignored by continues.
Key `Theorem of Pythagoras' with value `' ignored by restate phase 1.
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 44.
[3]
Package atveryend Info: Empty hook `AfterLastShipout' on input line 44.
 (./restate-thm.aux)
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 44.
Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 44.


Package rerunfilecheck Warning: File `restate-thm.out' has changed.
(rerunfilecheck)                Rerun to get outlines right
(rerunfilecheck)                or use package `bookmark'.

...

LaTeX Warning: There were undefined references.
1
  • Hello, I am the current maintainer of thmtools. I can confirm this is not a regression issue caused by thmtools v69. Actually, the problem is reproducible with Overleaf's texlive 2019. Anyway, I will try to solve this. Jul 18, 2020 at 22:41

1 Answer 1

1

Update:

crossreftools v1.0 (2020-07-19) has fixed this issue, so the following patch is not necessary.


Original answer:

Try this:

\makeatletter
\renewcommand{\crtaddlabeltotoc}[1]{%
  \ifcrtfinal
  \else
  % replace "\expandafter\crtrefnumber{#1}" with "\string\crtrefnumber{#1}"
  \addcontentsline{\crt@listoflabelsfileextension}{\crt@listoflabelsstructurelevel}{\protect\numberline{\string\crtrefnumber{#1}}#1}%
  \fi
}
\makeatother

This seems a bug of crossreftools and here is a minimum example reproduces the problem.

\documentclass{article}
\usepackage{crossreftools}

\begin{document}
\makeatletter
\def\@currentlabel{\protect\def\protect\x{x}}
\makeatother

text \label{key}
\end{document}

Some explanations:

  • corssreftools has a \crtlistoflabels which outputs a list of labels stored in aux file .lla. For a label named sec:xxx of section 3 on page 5, its corresponding entry in list of labels would look like "3 sec:xxx ... ... 5". Here 3 is equivalent to the output of \ref{sec:xxx}.
    • Through first run of latex, \crtaddlabeltotoc is called to write necessary info to .aux. When .aux is input at the begin of document, .lla is created. And when \crtlistoflabels is used, .lla is input.
    • The whole \crtlistoflabels utility can be turned off by crossreftools's package option `final.
  • In the current implementation of \crtaddlabeltotoc, which extracts the reference value (plain output of \ref{<label>}) of a label,
    • firstly the \expandafter in \expandafter\crtrefnumber{#1} has no effect since the token after \crtrefnumber is {, unexpandable.
    • Secondly, this would write the result of fully expanded \crtrefnumber{#1} to .aux. \crtrefnumber is expandable, but the result of its expansion is not necessarily expandable.
  • thmtools's restatable environment do stores un-expandable staff in label's reference value, and this causes problems as long as it is used with crossreftools.
    • In OP's example, when doclicense is commented, there is still wrong contents in .aux file, for example (note the \def \@arabic {\c@equation } snippet)
    \@writefile{lla}{\contentsline {section}{\numberline {\def \@arabic {\c@equation }{\@arabic {\c@equation }}\global \c@equation 0\relax }thmt@@PythagorasTheorem@data}{1}\protected@file@percent }
    
    • But, if user doesn't use \crtlistoflabels, the file .lla is never loaded. Hence the problem in contents of .lla is never uncovered.
    • In OP's example, when doclicense is uncommented, package calc is loaded. This makes the process of fully expansion of \crtrefnumber{#1} causing problems serious enough to raise an error.

Concerning the current fix, since the labels are already defined at the beginning of document, using \crtrefnumber{<label name>} rather than its expansion in \crtlistoflabels is safe. Therefore, \string replaces \expandafter to write \crtrefnumber{#1} to .aux.

After the fix,

\@writefile{lla}{\contentsline {section}{\numberline {\crtrefnumber{thmt@@PythagorasTheorem@data}}thmt@@PythagorasTheorem@data}{1}\protected@file@percent }

is written to .aux.

11
  • @muzimuhi Z: Your fix resolves the immediate problem. But how do I reconcile it with a different redefinition of \crtaddlabeltotoc that fixes a conflict with babel-french, namely: \renewcommand{\crtaddlabeltotoc}[1]{% \ifcrtfinal \else \addcontentsline{\crt@listoflabelsfileextension}{\crt@listoflabelsstructurelevel}{% \protect\numberline{\expandafter\crtrefnumber\expandafter{\detokenize{#1}}}#1}% \fi } from tex.stackexchange.com/a/510641/13492 ?
    – murray
    Jul 19, 2020 at 0:30
  • What does the bug you cite in crossreftools have to do with doclicense, though? I was getting the error only when doclicense was used, too (which seems weird).
    – murray
    Jul 19, 2020 at 0:33
  • @murray Because doclicense depends on calc, and it is calc that makes the problem serious enough to raise a bug when .aux is input at second run. When adding \crtlistoflabels to your example, you can get errors (though the error message varies) without doclicense and even without hyperref. Jul 19, 2020 at 0:45
  • @murray I cannot reproduce your problem in tex.stackexchange.com/q/510591, either on my local texlive 2020 or on Overleaf's texlive 2019. It might be the fact that babel-french.ldf has fixed it. Jul 19, 2020 at 0:58
  • @murray Using Overleaf's texlive 2018, the problem reproduces. It can be fixed by redefining \crtaddlabeltotoc by replacing \expandafter\crtrefnumber{#1} with \string\crtrefnumber{\detokenize{#1}}. This resolves problems reported both in referenced question and in current one. Jul 19, 2020 at 1:02

You must log in to answer this question.

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