# How to debug todonotes issues (expandafter {\@captype)

In a LaTeX document (using revtex-4.2 and todonotes) I run into issues with todo note related errors – which seem erratic and which I somehow cannot debug. The issue seems to be related to a certain number of todonotos, somewhere around 40, but here's the wider story:

Compiling the document with pdflatex (14159265-2.6-1.40.20, TeX Live 2019) I get the following error

./document.tex:441: Undefined control sequence.
<argument> ...tally@float \expandafter {\@captype
}
l.441    not?}
closer to the cation the Coulomb attraction grows and results ...

./document.tex:441: Missing \endcsname inserted.
\ftype@
l.441    not?}
closer to the cation the Coulomb attraction grows and results ...

./document.tex:441: Extra \endcsname.
\tally@float ...ame ftype@#1\endcsname \endcsname
\@ifnotrelax \@tempa {\@if...l.441    not?}
closer to the cation the Coulomb attraction grows and results ...


Commenting out either the first or the second half to the text (or any good chunk of the document) this works without error as long as the overall number of todonotes is <~40. That is, no single todonote or any other code of the document causes the error as such, only in the sum the errors occur.

However, creating a minimal example I see that todonotes as such has no problem with 100 notes:

\pdfoutput=1
%\documentclass[galley]{revtex4-2}
\documentclass{article}
\usepackage[textsize=tiny]{todonotes}
\usepackage{forloop}
\begin{document}
\noindent Testing the number of todonotes without error \\
\newcounter{ct}
\forloop{ct}{1}{\value{ct} < 101}%
{%
\noindent testing \todo{Note \thect}note \thect. \par
}
\end{document}


If I choose the revtex4-2 document class instead of article in the example above, I get some other error (which I assume to be an revtex4-2 vs. forloop incompatibility)

./minimal.tex:13: Output loop---100 consecutive dead cycles.
<argument> ...do {Note \thect }note \thect . \par


Now, is there a know issue here? What could be the actual problem with my original document? How could I go ahead and investigate this systematically?

Let me point out that I see this same behavior repeatedly when I add a significant numbers of todonotes to a revtex document.

• I don't know revtex nor todonotes, but the “Undefined control sequence: \@captype” error could happen as a result of using \caption outside any figure or table environment. As for the Output loop---100 consecutive dead cycles, this suggests that something is retaining contents, delaying its shipping out via the \output routine. Maybe you need to add normal text to allow the retained material to find a place? (just a humble guess since I don't know these packages) – frougon Apr 5 '20 at 10:46
• Unrelated: why are you setting \pdfoutput=1? – daleif Apr 5 '20 at 12:20
• It is not related to todonotes but to the fact that todonotes uses \marginpar internally, you get the same error with just \marginpar{test}. I tend to use the fixme package instead of todonotes. Fixme can be configured to use the marginnote package and then does not rely on the \marginpar command. – daleif Apr 5 '20 at 12:25
• @daleif Thank you for the suggestion. I did switch our groups macro package to fixme now, which is a bit of a pain for everybody (which is the reason I did not go that route previous times I arrived at todonotes problems... thank you for the reminder;-) But now its set to layout pdfcnote:-O layout=marginnote, also with innerlayout=inline/or similar does not really provide useful output – horizontal alignment does not work on all pages, notes overlap each other, etc... But that's for another day and question;-) fixme it is now:-) – yogik Apr 5 '20 at 17:36
• The price of marginnote is the overlap, but that can be manually adjusted by adding an extra option to fxnote. I neven have a setup that also add the marker path used by todo – daleif Apr 5 '20 at 17:38

I am facing a similar problem with todonotes and revtex-4.2, where after a certain number of notes the Undefined control sequence captype-related error appears (similar to the OP, no one specific note is triggering it).
Putting this invasive-looking \def\ in the preamble solves the problem:
\makeatletter \def\@captype{figure} \makeatother