这种计数器和 \ifnum 条件的组合是否有效,还是需要修改?有没有更好的方法?

这种计数器和 \ifnum 条件的组合是否有效,还是需要修改?有没有更好的方法?

我正在用 LaTeX 制作论文的最终产品。我在处理论文的前言时遇到了麻烦,特别是如何让 LaTeX 识别出如果前言在一定页数处停止,那么它就会执行命令\beginthesis

我尝试生成计数器,以便如果某个计数器组合产生了某个数字,并且该数字大于 X,它将通过 生成一个新的前置页面\newpage,但如果小于 X,它将执行\beginthesis

因此,以简化的形式,整个过程看起来像这样,摘要是可以出现的绝对最后一页:

\newcounter{frontmattercounter}
\newcounter{frontmattercheck}
\newcounter{frontmatterabstract}
\newcounter{frontmatterepigraph}

\newcommand{frontmattercheck}{%
\addtocounter{frontmattercheck}{\value{frontmatterabstract}}
\addtocounter{frontmattercheck}{\value{frontmatterepigraph}}
}

\frontmattercheck
\setcounter{frontmattercounter}{\value{frontmattercheck}}

\newcommand{epigraph}
\setcounter{frontmatterepigraph}{1}
.
.
.
\ifnum\value{frontmattercounter} > 1
\@restonecolfalse\newpage
\else
\beginthesis\fi

\newcommand{abstract}
\setcounter{frontmatterabstract}{10}
.
.
.
\beginthesis

我已经以这种方式设置了大约 6 或 7 页,但出于某种原因,LaTeX 似乎无法正确识别这些值。有没有更好的方法来做到这一点,或者我是否可以修改我的流程以获得预期的结果?提前致谢。

答案1

我将盲目地思考“有没有更好的方法?”我大学的论文风格要求前页包含某些页面,而其他页面则是可选的。前页中的页面采用一种类型的页眉和页脚,而正文和后页中的页面采用另一种样式。以下是我使用的基本结构,学生需要提供自己的摘要和其他前页内容,并注释掉他们不使用的页面:

\documentclass[oneside]{book}
\usepackage[english]{babel} \usepackage{blindtext} % For filler text
%%% Things that should go in a .sty file the student doesn't normally touch

% Use \somethingpage commands to define the layout of a frontmatter page,
% and include the content of the student's \thesissomething command.
\newcommand{\epigraphpage}{\cleardoublepage \thesisepigraph \cleardoublepage}
\newcommand{\abstractpage}{\cleardoublepage \thesisabstract \cleardoublepage}
\newcommand{\beginthesis}{\pagestyle{headings}}
% Provide default \thesissomething commands to prompt the student in case
% they forgot to enter their own content.
\newcommand{\thesisepigraph}{%
This is the default epigraph. You need to change it by editing the
thesisepigraph command in your own thesis.tex file
}
\newcommand{\thesisabstract}{%
This is the default abstract. You need to change it by editing the
thesisabstract command in your own thesis.tex file
}
%%%

%%% Things that should go in each student's .tex file
\renewcommand{\thesisepigraph}{%
This is my epigraph.
}

\renewcommand{\thesisabstract}{%
This is my abstract.
}
%%%

\begin{document}
\frontmatter \pagestyle{plain}

\tableofcontents
\listoffigures
\epigraphpage % Comment this out if there's no epigraph to include
\abstractpage % Don't comment this out, abstract is required

\mainmatter \beginthesis

\chapter{One}
\section{First}
\blindmathpaper
\begin{figure}
\centering
\fbox{Figure content goes here}
\caption{Some caption goes here}
\end{figure}

\backmatter

\chapter{Something Else}
Here goes the back matter.

\end{document}

还有一些更复杂的技术可用(例如,修补\mainmatter命令以自动执行\beginthesis),但也许这是一个弄清楚真正需要的起点。

相关内容