目录、章节目录和附录功能失灵

目录、章节目录和附录功能失灵

附图显示了几乎 MWE 中的问题:

  • 在 中TOC,附录被称为章节而不是附录
  • 更糟糕的是,附录中的章节出现在上一章的章节目录中。

使事情复杂化的是的构造Chapter TocOberdiek hack加载的showidx,以及允许显示数学的黑客showidx,比如说,

$\langle23\rangle$

(见图。)

在此处输入图片描述

代码如下:

% !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}

答案1

要在目录中使用appendixname而不是,请将以下几行添加到序言中:\chaptername

\usepackage{apptools, etoolbox}
\makeatletter
\patchcmd{\@chapter}{\protect {CHAPTER }}{\ifappendix{APPENDIX }\else{CHAPTER }\fi}{}{}
\makeatother

相关内容