我使用的宏与命令混在一起\section
,\printindex
在使用时中断了进程imakeidx
。我很确定问题出在 中的第 252-253 行imakeidx.sty
:
\def\imki@indexlevel{%
\@ifundefined{chapter}{\section}{\chapter}*}
由于某种原因,我可以让其中一个\makeindex
(\printindex
正确的章节标题,无法编译\jobname.ind
) 工作,但不能同时工作。哪里出了问题?
\documentclass{ltxdoc}
\usepackage{etoolbox}
\usepackage{imakeidx}
\usepackage{fancyhdr}
\usepackage[pageanchor]{hyperref}
\newrobustcmd{\PreviousSectionTitle}{}%
\newrobustcmd{\CurrentSectionTitle}{}%
\newcounter{PreviousSectionCounter}%
\setcounter{PreviousSectionCounter}{0}%
\newcounter{NextSectionCounter}%
\setcounter{NextSectionCounter}{0}
\newcounter{CurrentSectionCounter}%
\setcounter{CurrentSectionCounter}{0}
\newcounter{LastSectionValue}
\newcounter{FirstSectionValue}
\fancypagestyle{FootLinks}{
\lfoot{
\ifnumequal%
{\number\value{CurrentSectionCounter}}{\number\value{FirstSectionValue}}{}
{
{\GeneratePreviousSectionHyperlink{CurrentSectionCounter}{PreviousSectionCounter}{1} }
}%
}%
\rfoot{
\ifnumequal%
{\number\value{CurrentSectionCounter}}{\number\value{FirstSectionValue}}%
{\GenerateNextSectionHyperlink{CurrentSectionCounter}{NextSectionCounter}{LastSectionValue}}%
{\ifnumequal%
{\number\value{CurrentSectionCounter}}{\number\value{LastSectionValue}} { }%
{ \GenerateNextSectionHyperlink{CurrentSectionCounter}{NextSectionCounter}{LastSectionValue} }%
}%
}%
}%
\newrobustcmd{\GenerateNextSectionHyperlink}[3]{\ifnumequal{\number\value{#1}}{\number\value{#3}}{}{\hyperlink{CurrentSection::\number\value{#2}}{\nameref*{CurrentSection::\number\value{#2}::Title}~\(\rightarrow\)}}}
\newrobustcmd{\GeneratePreviousSectionHyperlink}[3]{\ifnumequal{\number\value{#1}}{1}{}{\hyperlink{CurrentSection::\number\value{#2}}{\(\leftarrow\)~\nameref*{CurrentSection::\number\value{#2}::Title}}}}
\makeindex%%%%%%%%%%%%%%%%
\begin{document}
\let\LaTeXStandardSection\section%
\renewcommand{\section}[2][]{%
\stepcounter{CurrentSectionCounter}%
\ifnumequal{\number\value{CurrentSectionCounter}}{1}{%
\setcounter{PreviousSectionCounter}{1}%
\expandafter\renewrobustcmd{\CurrentSectionTitle}{%
#2}%
}{%
\makeatletter
\edef\@@oldtitle{\CurrentSectionTitle}
\expandafter\renewrobustcmd{\PreviousSectionTitle}{%
\@@oldtitle
}%
\expandafter\renewrobustcmd{\CurrentSectionTitle}{%
#2%
}%
\setcounter{PreviousSectionCounter}{\number\value{CurrentSectionCounter}}
\addtocounter{PreviousSectionCounter}{-1}
}%
\phantomsection
\hypertarget{CurrentSection::\number\value{CurrentSectionCounter}}{}%
\immediate\write1{%
\string\phantomsection%
\string\newlabel{CurrentSection::\number\value{CurrentSectionCounter}::Title}{{\thesection}{\thepage}{#2}}%
}%
\makeatother
\setcounter{NextSectionCounter}{\number\value{CurrentSectionCounter}}
\ifnumequal{\number\value{CurrentSectionCounter}}{\number\value{LastSectionValue}}{}{%
\addtocounter{NextSectionCounter}{1}
}%
\phantomsection
\LaTeXStandardSection[#2]{#2}%
}%
\pagestyle{FootLinks}
\newpage
\section{dummy1}
\index{text}{teeeeeeeeeeeeeeext}
\newpage
\section{dummy2}
\printindex%%%%%%%%%%%%%%%%%%%%%%
\newpage
\section{dummy4}
\newpage
\section{dummy5}
\newpage
\section{dummy6}
\newpage
\section{dummy7}
\end{document}