Solution:
Replace the last \addtocontents
with the following code:
\makeatletter
\immediate\write\@auxout{\noexpand\@writefile{toc}{\noexpand\thispagestyle{headings}}}
\makeatother
If this is required in more than one document, you can define a macro for it.
In this case I would also set \protect
properly (as the normal \addtocontents
does). This is done inside a group of course (note the extra { }
pair).
\makeatletter
\newcommand\immaddtocontents[1]{{%
\let\protect\@unexpandable@protect
\immediate\write\@auxout{\noexpand\@writefile{toc}{#1}}%
}}
\makeatother
which can be used like this:
\immaddtocontents{\protect\thispagestyle{headings}}
Explanation:
The problem is that \addtocontents
is intended to be used together with material which is typeset. The underlying \write
macro is a so called whatsit, i.e. it is only stored when found and executed later when its box is typeset, i.e. when the material is (virtually) written on the page. This is done, because only at this moment the final position of the material i.e. the page number is known.
Your last \addtocontents
is never typeset, so comes never into the file.
Using the code above will write the contents line directly without creating a whatsit. Please note that if you are using this code in the middle of the document your entries could be out of order.
Alternatives:
My first idea was to add an empty box \hbox{}
after the last \addtocontents
to force that the whatsit is executed. However because the last text was in an \include
which executes \clearpage
, adding this box afterwards would create a new empty page at the end of the document. However, if the last content of the document comes from the main file or an \input
file (and does not end in an manual \clearpage
) this solution should work.
Other possibility would be to use the filehook
package to place the \addtocontents
direct before the \clearpage
of the last \include
file:
\usepackage{filehook}
\AtEndOfIncludeFile{<last file>}{\addtocontents{toc}{\protect\thispagestyle{headings}}}
or place the following directly before the last \include
:
\AtEndOfIncludes{\addtocontents{toc}{\protect\thispagestyle{headings}}}
Further Reading:
See The TeXBook it learn all abouts whatsits. For example in Chapter 21: Making Boxes, p.226.
what facilities are available depend on what document class you are using. some classes provide "super-sectioning" of a book into \frontmatter
(automatic roman page numbers), \mainmatter
(restarts page number at 1 and resets font to arabic), and \backmatter
(clears any "leftovers" from appendix
). \appendix
is often set up to reset the \chaptername
to "Appendix"; this flows automatically into the table of contents. look to see what's defined in the document class.
regarding blank pages without running heads, this is what the ams has done to make this happen automatically:
\let\cleardouble@page\cleardoublepage
\AtBeginDocument{%
\ifx\cleardouble@page\cleardoublepage
\def\cleardoublepage{\clearpage{\pagestyle{empty}\cleardouble@page}}
\fi
}
it can safely be used at the end of any chapter or other appropriate segment (like the toc) and will always result in the next "real" output starting on a right-hand page.
ams style doesn't use dots in the toc, so i'll leave that part of the question for someone else.
Best Answer
You can simply add a patched version of the
\@makechapterhead
macro (which is responsable for creating the chapter headings) to the\appendices
macro which will be called when using theappendices
environment via\g@addto@macro
. This patch is locally bounded because it will be applied inside the environment.Complete Code
Original version of
\@makechapterhead
(From latex.ltx)