如果我用\cfoot
它来评估并打印此部分计数器,它会在我的附录中显示正确的部分编号。
然而,当我使用 评估节计数器时\ifnumequal
,它表明平等的表达式是绝不遇到了。为什么?
一个不那么简单的例子:
\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage[heightrounded]{geometry}
\usepackage[toc,titletoc,page]{appendix}
\usepackage{blindtext}
\usepackage[pageanchor]{hyperref}
\newrobustcmd{\PreviousSectionTitle}{}%
\newrobustcmd{\CurrentSectionTitle}%
\newcommand{\Contentsname}{Inhoudsopgave}
\newcommand{\LinkToContentsName}{inhoudsopgave}
\newcommand{\LinkToIndexName}{Index}
\newrobustcmd{\GotoName}{Naar}
\newrobustcmd{\DoIfNumInequal}[3]{%
\ifnumequal{#1}{#2}{}{#3}% Drop last
}%
\newrobustcmd{\IfNumInequal}[4]{%
\ifnumequal{#1}{#2}{#3}{#4}%
}%
\newcounter{PreviousSectionCounter}% No resetting%%%
\setcounter{PreviousSectionCounter}{0}%
\newcounter{NextSectionCounter}% No resetting%%%
\setcounter{NextSectionCounter}{0}
\newcounter{CurrentSectionCounter}% No resetting%%%
\setcounter{CurrentSectionCounter}{0}
\newcounter{LastSectionValue}
\usepackage{fancyhdr}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{.4pt}
\lfoot{\CurrentSectionTitle}
\fancypagestyle{FootLinks}{
}%
\AtEndDocument{%
\makeatletter
\def\LastSectionInFile{%
\immediate\write\@auxout{\string
\setcounter{LastSectionValue}{\number\value{CurrentSectionCounter}}%
}%
}%
\makeatother
}%
\newrobustcmd{\NextSectionHyperLinkFormat}[1]{\GotoName~#1~\(\rightarrow\)}%
\newrobustcmd{\PreviousSectionHyperLinkFormat}[1]{\(\leftarrow\)~\GotoName~#1}%
\begin{document}
\tableofcontents
\cleardoublepage
\newpage
\let\LaTeXStandardSection\section%
\renewcommand{\section}[2][]{%
\stepcounter{CurrentSectionCounter}%
%%%%% Check first whether there is a already a previous section
\ifnumequal{\number\value{CurrentSectionCounter}}{1}{% Yes, section number is zero
\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}
}% CurrentSectionCounter > 1
% Set Target to current section
\phantomsection
\hypertarget{CurrentSection::\number\value{CurrentSectionCounter}}{}%
%\makeatletter
\immediate\write1{%
\string\phantomsection%
\string\newlabel{CurrentSection::\number\value{CurrentSectionCounter}::Title}{{\thesection}{\thepage}{#2}}%
}%
\makeatother
% Set Link to previous section%
\setcounter{NextSectionCounter}{\number\value{CurrentSectionCounter}}
\ifnumequal{\number\value{CurrentSectionCounter}}{\number\value{LastSectionValue}}{}{%
\addtocounter{NextSectionCounter}{1}
}%
\phantomsection
\LaTeXStandardSection[#2]{#2}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% This code is behaving weird? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\ifnumequal{\number\value{CurrentSectionCounter}}{2}{\cfoot{\number\value{CurrentSectionCounter}}}{\cfoot{Wrong number}}% This line always yields "wrong number"
\cfoot{Current section number is: \number\value{CurrentSectionCounter}}% This line displays the counter value correctly
\section{test}
\newpage
\blindtext
\newpage
\begin{appendices}
\pagestyle{FootLinks}
\section{Section Number A}
\blindtext
\clearpage
\section{B}
\blindtext
\clearpage
\section{Section Number C}
\blindtext
\clearpage
\section{D}
\blindtext
\end{appendices}
\end{document}
答案1
这个例子太长了。至少可以分析一下这个问题:
\ifnumequal{\number\value{CurrentSectionCounter}}{2}{%
\cfoot{\number\value{CurrentSectionCounter}}%
}{%
\cfoot{Wrong number}%
}% This line always yields "wrong number"
比较只在执行时进行一次。显然此时\ifnumequal
的值不同,因此所有后续页面的页脚均设置为。CurrentSectionCounter
\cfoot{Wrong number}