The attached image shows the problems in an almost MWE:
- In
TOC, the appendices are called Chapter instead of Appendix - Much worse is that the sections in the Appendices find their way in the Chapter toc of the last Chapter.
What complicates matters are the construction of the Chapter Toc, the Oberdiek hack which loads showidx, and the hack which allows showidx to display mathematics and, say,
$\langle23\rangle$
(See image.)
The code is:
% !TEX TS-program = pdflatexmk
\documentclass[11pt]{book}
%Begin Chapter TOC
\usepackage[titletoc]{appendix}
\usepackage[dotinlabels]{titletoc}%a companion to the titlesec package which does Chapter Tocs
\titlecontents{chapter}[6pc]{\addvspace{1pc}\bfseries\filright}%
{\contentslabel[\chaptername \ \thecontentslabel]{6pc}}%
{}{\hfill\contentspage}[\addvspace{2pt}]%
\newcommand\xquad{\hspace{0.4em plus .2em minus .2em}}%
\titlecontents*{p-section}[0pt]{\filright\small}{}{}{, \thecontentspage}[\xquad\textbullet\xquad][.]%
\newcommand{\ChapterToc}{\startcontents[chapters]\printcontents[chapters]{p-}{1}{}\vspace{10mm}}%
%End Chapter TOC
%Begin References
\usepackage{makeidx} %
%package showidx must NOT be loaded because it is Hyperref that loads it in the Oberdiek hack below
\usepackage[hyperfootnotes=false]{hyperref}%[pdfborder={0 0 0}]
\hypersetup{colorlinks,linkcolor={black},}
%Begin the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\makeatletter
\ifHy@hyperindex
\def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
\let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
\def\HyInd@showidx#1{%
\@showidx{#1}%
\if@nobreak
\ifvmode
\nobrak
\fi
\fi
}%
% Load package showidx
\let\siOrg@makeindex\makeindex
\let\siOrg@@index\@index
\let\siOrg@@wrindex\@wrindex
\let\siOrg@index\index
\RequirePackage{showidx}
\let\makeindex\siOrg@makeindex
\let\@index\siOrg@@index
\let\@wrindex\siOrg@@wrindex
\let\index\siOrg@index
% rest of hyperref part
\@ifpackageloaded{multind}{%
\let\HyInd@org@wrindex\@wrindex
\def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
\def\HyInd@@wrindex#1#2|#3|#4\\{%
\ifx\\#3\\%
\HyInd@org@wrindex{#1}{#2|hyperpage}%
\else
\def\Hy@temp@A{#3}%
\ifx\Hy@temp@A\HyInd@ParenLeft
HyInd@org@wrindex{#1}{#2|#3hyperpage}%
\else
\HyInd@org@wrindex{#1}{#2|#3}%
\fi
\fi
}%
}{%
\def\@wrindex#1{\@@wrindex#1||\\}
\def\@@wrindex#1|#2|#3\\{%
\ifx\\#2\\%
\protected@write\@indexfile{}{%
\string\indexentry{#1|hyperpage}{\thepage}%
}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2hyperpage}{\thepage}%
}%
\else
\protected@write\@indexfile{}{%
\string\indexentry{#1|#2}{\thepage}%
}%
\fi
\fi
\endgroup
\HyInd@showidx{#1}%
\@esphack
}%
}%
\fi
\makeatother
%End the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
%Begin hack to have math in Showindex
\let\oldopenparen\(
\let\oldcloseparen\)
\def\({\protect\oldopenparen}
\def\){\protect\oldcloseparen}
\newcommand{\INDEX}[1]{\index{#1}}
%Begin hack for \langle and \rangle.
\let\oldlangle\langle
\def\langle{\protect\oldlangle}
\let\oldrangle\rangle
\def\rangle{\protect\oldrangle}
%End hacks
\makeindex
\begin{document}
\tableofcontents
\chapter{ONE}
\ChapterToc
Some irrelevant text
\section{Plain Numbers}
Some text where \textbf{Number\(\langle23\rangle\)}\INDEX{number \(\langle23\rangle\)} is used.
\appendixpage
\appendix
%\begin{appendices}
\chapter{Addition Formulas}
Some arelevant text
\section{Squares}
Appended text
%\end{appendices}
\backmatter%
\phantomsection
\addcontentsline{toc}{chapter}{Index}
\printindex
\end{document}

titletocpackage? This package is used to typeset the entries in the table of contents. Unfortunately, it doesn't appear to be sufficiently flexible to permit a renewal of the\chapternamemacro halfway through the document, viz., at the start of the appendix portion. – Mico Jun 05 '16 at 19:44\addtocontents{toc}{\protect\renewcommand\protect\chaptername{\protect\appendixname}}after\appendix. For the short TOC issue, I don't know; maybe switching toetocinstead oftitletoc? – egreg Jun 05 '16 at 22:15titletoccauses much more problems than necessary. I don't say,that it's responsible for the current issues,but removing it might be a good idea. Of course neithercleverefnortcolorboxscrew up the ToC – Jun 06 '16 at 09:48\stopcontents[chapters]at the end of the chapter. – touhami Jun 06 '16 at 23:07\addtocontents{toc}...in the "magnum opus" and it worked beautifully there too … except the first Appendix is still calledChapterin theTOC. (The other ones are correctly calledAppendix.) Presumably because, in the magop, the chapter files are\includedin a file which is\inputin themaster file. After which\stopcontents[chapters],\appendix,\addtocontents{toc}...,\include{Appdx1}, … etc. But\addtocontents{toc}...still worked in the above MWE with a second appendix. Any idea? In any case, thanks: the magop now looks perfect anyhow. – schremmer Jun 07 '16 at 16:54\appendixand\includehas already been discussed on this site – egreg Jun 07 '16 at 17:30