TeX - LaTeX Asked on December 25, 2021
I have been trawling this website for several days but found nothing close to my problem. The only questions that came close, I think, were dealing with inserts and memory requirements. I have cut down the sample code to the bare minimum. It was really hard to reproduce the problem but I think this codes does that. I am using PdfLaTeX with TeXShop on a new MacBook Pro with 32GB of RAM running Mojave.
The problem is that when I request a tocdepth
of 3 the definition of ChapterN
appears to be lost because I get the error message:
! Undefined control sequence.
<argument> Chapter @ChapterN
- Blablabla
l.40 ...bsection}{numberline {1.5.1}Blablabla}{4}
even though it is defined. If tocdepth
is 2 the problem disappears. Crucially, if I specify tocdepth
= 3 but delete one of the section
s or subsection
s, the problem disappears. This is why the minimum example below has so many section
s etc.
It looks like a memory issue to me, and I have a vague idea that increasing the argument of reserveinserts
might help, but I would rather get a proper diagnosis and some proper guidance instead of hacking randomly.
BTW, if you run this code the formatting will be kind of messed up but you can ignore that, it’s just because I stripped the code down to reproduce just the problem at hand.
documentclass[10pt,a4paper]{book}
usepackage{etex}
reserveinserts{28}
usepackage[most]{tcolorbox}
newtcbox{mybox}{blank, on line, opacitytext=0.6}
makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
newcommandChapterN[1]{def@ChapterN{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{fancyhdr}
fancypagestyle{plain}{
fancyhf{}
fancyhead[L]{Left}
fancyhead[C]{Centre}
fancyhead[R]{Right}
fancyfoot[L]{
setlength{fboxsep}{2mm}
setlength{fboxrule}{0.2mm}
fbox{parbox{14.8cm}
{strut mybox{textcolor{red}
{textbf{Chapter @ChapterN - Blablabla}}}}}}
fancyfoot[C]{}
fancyfoot[R]{
setlength{fboxsep}{2mm}
setlength{fboxrule}{0.2mm}
fbox{parbox{1.35cm}{strutcenteringthepage}}}}
makeatother
pagestyle{plain}
usepackage{varwidth}
%%%%%%%%%%%%%%%%%%%%%%%%
setcounter{tocdepth}{3}
%%%%%%%%%%%%%%%%%%%%%%%%
begin{document}
tableofcontents
ChapterN{A}
chapter{Blablabla}
section{Blablabla}
subsection{Blablabla}
subsubsection{IBlabla Blabla Blabla Blabla Blabla}
subsubsection{Isdfgsdfgsdfg Blabla Blabla Blabla}
subsection{klsdfhkajhfdg}
subsection{Blabla Blabla Blabla Blabla Blabla}
subsection{Blabla}
subsection{Blabla Blabla Blabla Blabla}
subsubsection{Blabla}
subsubsection{Blabla}
subsubsection{Blabla}
subsubsection{Blabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
section{Blablabla Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsubsection{Blablabla}
subsubsection{Blablabla}
subsubsection{Blablabla}
subsubsection{Blablabla}
subsubsection{Blablabla Blablabla}
subsection{Blablabla Blablabla Blablabla}
section{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablablai}
section{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla}
subsection{Blablabla Blablabla}
section{Blablabla Blablabla Blablabla}
subsection{Blablabla}
subsection{Blablabla}
end{document}
You use the contents of ChapterN
in left-hand side footers of your document by passing it down via @ChapterN
to fancyfoot[L]
(headers and footers together are referred to as "pagestyle").
When the table of contents is rendered, it usually starts at an odd page (right hand side). If it is short enough, the left hand side will not be rendered at all, so no call to @ChapterN
is made. However, if the ToC is longer, it will eventually break to the next, left-hand, side, and the footer for that page is rendered, where you tell the fancyhdr package to utilize @ChapterN
. The problem is, that at that point that macro is still undefined, since your ChapterN
is after the tableofcontents
.
There are several ways to fix this: You could initialize @ChapterN
by calling ChapterN
immediately after it is defined:
newcommandChapterN[1]{def@ChapterN{#1}}
ChapterN{}
Now, @ChapterN
is empty, but defined, so when the ToC is broken onto the next page, the pagestyle can call @ChapterN
. Note that then you will get "Chapter - Blablabla" as footer on the second contents page, and you problably don't want that.
Alternatively, you can tell fancyhdr
to only use @ChapterN
if it has been initialized:
fancyfoot[L]{
ifx@ChapterN@undefinedelse
setlength{fboxsep}{2mm}
setlength{fboxrule}{0.2mm}
fbox{parbox{14.8cm}
{strut mybox{textcolor{red}
{textbf{Chapter @ChapterN - Blablabla}}}}}
fi
}
Now you are telling the package to render the left-hand side footer only if @ChapterN
is defined. Otherwise the footer on left-hand pages is left completely empty.
The cleanest way, however, would be to use (or define) different page styles for toc and text, respectively:
...
begin{document}
pagestyle{empty}% no headers/footers for ToC
tableofcontents
ChapterN{A}
pagestyle{plain}% re-activate page styles
...
Answered by Lupino on December 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP