# Use of todonotes package breaks classicthesis alignment fix

I had an issue with the toc design of classicthesis described here, but I could not reproduce the solution. Thus, I tested a bit and identified the conflicting package as todonotes.

Hence, if I use the fix mentioned in the post, my minimal non-working example is (note that it will work if you remove \usepackage{todonotes}:

\RequirePackage{fix-cm}
footinclude=true,cleardoublepage=empty,abstractoff, % <--- obsolete, remove (todo)
BCOR=5mm,paper=a4,fontsize=11pt,%11pt,a4paper,%
ngerman,american,%
]{scrreprt}

\input{classicthesis-config}

\usepackage{todonotes}

\makeatletter
\setlength\cftpartnumwidth{1.5em}
\renewcommand\Part[2][]{%
\ifpdf\pdfstringdefDisableCommands{\let\thepart\@gobbletwo}%
\oldpart[\texorpdfstring{\spacedlowsmallcaps{#1}}{#1}]{#2}
\else\oldpart[\spacedlowsmallcaps{#1}]{#2}%
\fi%
\hspace*{4pt}\texorpdfstring{\llap{\thepart}}{}}\texorpdfstring{\noexpand\spacedlowsmallcaps{#1}}{#1}}
\ctparttext{\relax}%
}%
\makeatother

\begin{document}

\tableofcontents

\part{Test Part One}
\chapter{Test Chapter One}
\section{Test Section One One}
\section{Test Section One Two}
\part{Test Part Two}
\chapter{Test Chapter One}
\section{Test Section One One}
\section{Test Section One Two}
\part{Test Part Three}
\chapter{Test Chapter One}
\section{Test Section One One}
\section{Test Section One Two}

\end{document}


The error message (from ShareLaTeX) is:

Missing number, treated as zero.
\begingroup
l.7 ...oup \aftergroup \calc@B \calc@A \begingroup
\aftergroup \calc@B \calc...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
\afterassignment
l.7 ...aftergroup \calc@B \calc@A \afterassignment
\def {\GenericError {(cal...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
output.toc, line 7
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\GenericError  ...
\let \@err@               ...
l.7 ...tion.}{I expected to see one of: + - * / )}
}\calc@A -2!\global \calc@...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing { inserted.
\let
l.7 ...tion.}{I expected to see one of: + - * / )}
}\calc@A -2!\global \calc@...
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)
output.toc, line 9
LaTeX Error: Something's wrong--perhaps a missing \item.
There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.9 ...cedlowsmallcaps {Test Part One}}{3}{part.1}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
output.toc, line 11
Missing number, treated as zero.
\begingroup
l.11 ...up \aftergroup \calc@B \calc@A \begingroup
\aftergroup \calc@B \calc...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
\afterassignment
l.11 ...ftergroup \calc@B \calc@A \afterassignment
\def {\GenericError {(cal...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
output.toc, line 11
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\GenericError  ...
\let \@err@               ...
l.11 ...ion.}{I expected to see one of: + - * / )}
}\calc@A 2!\global \calc@A...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing { inserted.
\let
l.11 ...ion.}{I expected to see one of: + - * / )}
}\calc@A 2!\global \calc@A...
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)
output.toc, line 13
LaTeX Error: Something's wrong--perhaps a missing \item.
There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.13 ...edlowsmallcaps {Test Part One}}{5}{part.1}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
output.toc, line 21
Missing number, treated as zero.
\begingroup
l.21 ...up \aftergroup \calc@B \calc@A \begingroup
\aftergroup \calc@B \calc...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
\afterassignment
l.21 ...ftergroup \calc@B \calc@A \afterassignment
\def {\GenericError {(cal...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
output.toc, line 21
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\GenericError  ...
\let \@err@               ...
l.21 ...ion.}{I expected to see one of: + - * / )}
}\calc@A -2!\global \calc@...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing { inserted.
\let
l.21 ...ion.}{I expected to see one of: + - * / )}
}\calc@A -2!\global \calc@...
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)
output.toc, line 23
LaTeX Error: Something's wrong--perhaps a missing \item.
There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.23 ...edlowsmallcaps {Test Part Two}}{7}{part.2}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
output.toc, line 25
Missing number, treated as zero.
\begingroup
l.25 ...up \aftergroup \calc@B \calc@A \begingroup
\aftergroup \calc@B \calc...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
\afterassignment
l.25 ...ftergroup \calc@B \calc@A \afterassignment
\def {\GenericError {(cal...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
output.toc, line 25
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\GenericError  ...
\let \@err@               ...
l.25 ...ion.}{I expected to see one of: + - * / )}
}\calc@A 2!\global \calc@A...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing { inserted.
\let
l.25 ...ion.}{I expected to see one of: + - * / )}
}\calc@A 2!\global \calc@A...
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)
output.toc, line 27
LaTeX Error: Something's wrong--perhaps a missing \item.
There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.27 ...edlowsmallcaps {Test Part Two}}{9}{part.2}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
output.toc, line 35
Missing number, treated as zero.
\begingroup
l.35 ...up \aftergroup \calc@B \calc@A \begingroup
\aftergroup \calc@B \calc...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
\afterassignment
l.35 ...ftergroup \calc@B \calc@A \afterassignment
\def {\GenericError {(cal...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
output.toc, line 35
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\GenericError  ...
\let \@err@               ...
l.35 ...ion.}{I expected to see one of: + - * / )}
}\calc@A -2!\global \calc@...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing { inserted.
\let
l.35 ...ion.}{I expected to see one of: + - * / )}
}\calc@A -2!\global \calc@...
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)
output.toc, line 37
LaTeX Error: Something's wrong--perhaps a missing \item.
There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.37 ...owsmallcaps {Test Part Three}}{11}{part.3}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
output.toc, line 39
Missing number, treated as zero.
\begingroup
l.39 ...up \aftergroup \calc@B \calc@A \begingroup
\aftergroup \calc@B \calc...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing number, treated as zero.
\afterassignment
l.39 ...ftergroup \calc@B \calc@A \afterassignment
\def {\GenericError {(cal...
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
output.toc, line 39
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\GenericError  ...
\let \@err@               ...
l.39 ...ion.}{I expected to see one of: + - * / )}
}\calc@A 2!\global \calc@A...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Missing { inserted.
\let
l.39 ...ion.}{I expected to see one of: + - * / )}
}\calc@A 2!\global \calc@A...
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing I}' now.)
output.toc, line 41
LaTeX Error: Something's wrong--perhaps a missing \item.
There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.41 ...owsmallcaps {Test Part Three}}{13}{part.3}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
ClassicThesis.tex, line 60
Missing } inserted.
<inserted text>
}
l.60 \tableofcontents

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing 2' now; then
my insertion and my current dilemma will both disappear.
ClassicThesis.tex, line 60
Missing number, treated as zero.
\tb@toc@after@hook
l.60 \tableofcontents

A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
ClassicThesis.tex, line 60
Missing number, treated as zero.
\endgroup
l.60 \tableofcontents

A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
ClassicThesis.tex, line 61
Missing number, treated as zero.
\par
l.61

A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)
ClassicThesis.tex, line 62
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\@calc@post@scan ...st@scan \else \def \calc@next
{\calc@error #1}\fi \fi \f...
l.62 \part{Test Part One}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
ClassicThesis.tex, line 62
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next

l.62 \part{Test Part One}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
ClassicThesis.tex, line 66
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\@calc@post@scan ...st@scan \else \def \calc@next
{\calc@error #1}\fi \fi \f...
l.66 \part{Test Part Two}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
ClassicThesis.tex, line 66
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next

l.66 \part{Test Part Two}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
ClassicThesis.tex, line 70
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\@calc@post@scan ...st@scan \else \def \calc@next
{\calc@error #1}\fi \fi \f...
l.70 \part{Test Part Three}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
ClassicThesis.tex, line 70
Undefined control sequence.
The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}.

\@calc@post@scan ...fi \fi \fi \fi \fi \calc@next

l.70 \part{Test Part Three}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

• Have you tried variations in the package loading/\renewcommand order? Jul 20 '17 at 11:17
• Yes, I tried loading todonotes as the very first package. The errors change slightly, but they are still errors. Jul 20 '17 at 11:19
• Yes, I have, at least I was not able to find an order that works. Jul 20 '17 at 11:21
• You need to protect the two setcounters: \addtocontents{toc}{\protect\setcounter{tocdepth}{-2}. When the package calc is loaded they break. Jul 20 '17 at 11:45
• This is it! Would you mind writing an answer so I can accept your solution? Jul 20 '17 at 11:56

todonotes package loads the calc package and this redefines \setcounter in a way that they break in the \addtocontents commands. Protect them:

 \addtocontents{toc}{\protect\setcounter{tocdepth}{-2}
`