如何在乳胶文档类中创建条件?

如何在乳胶文档类中创建条件?

我正在尝试highschool.cls为我们学校的高中研究论文编写一个基于的文档类book.cls,以使论文的格式标准化。我正在尝试定义一个标题为“CERTIFICATION”的签名页,以便页面上显示以下文本。

在此处输入图片描述

为了实现这一点,我对 LaTeX 类做了如下定义highschool.cls

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{highschool}
                      [2012/08/22 v0.1e
         Standard LaTeX document class]

\newcommand\@ptsize{}
\newif\if@surnamea  \@surnameafalse
\newif\if@surnameb  \@surnamebfalse
\newif\if@surnamec  \@surnamecfalse
\newif\if@firstnamea    \@firstnameafalse
\newif\if@firstnameb    \@firstnamebfalse
\newif\if@firstnamec    \@firstnamecfalse
\newif\if@midinitiala    \@midinitialafalse
\newif\if@midinitialb    \@midinitialbfalse
\newif\if@midinitialc    \@midinitialcfalse

\setlength\paperheight {11in}%
\setlength\paperwidth  {8.5in}%
\setlength\textwidth   {6in}%

\def\defenseDate#1{\gdef\@defensedate{#1}}
\def\surnamea#1{\gdef\@surnamea{#1}}
\def\firstnamea#1{\gdef\@firstnamea{#1}}
\def\midinitiala#1{\gdef\@midinitiala{#1}}
\def\surnameb#1{\gdef\@surnameb{#1}}
\def\firstnameb#1{\gdef\@firstnameb{#1}}
\def\midinitialb#1{\gdef\@midinitialb{#1}}
\def\surnamec#1{\gdef\@surnamec{#1}}
\def\firstnamec#1{\gdef\@firstnamec{#1}}
\def\midinitialc#1{\gdef\@midinitialc{#1}}

\if@compatibility
  \renewcommand\@ptsize{0}
\else \DeclareOption{10pt}{\renewcommand\@ptsize{0}} \fi
\DeclareOption{11pt}{\renewcommand\@ptsize{1}}
\DeclareOption{12pt}{\renewcommand\@ptsize{2}}
\ExecuteOptions{12pt,oneside,final,openright} 
\ProcessOptions
\input{bk1\@ptsize.clo}

\def\signaturep{ %% signature page..
   \topmargin 0in \headsep 0in
   \begin{center}
   \textbf{CERTIFICATION}\\[6pt]
   \end{center}
   This is to certify that this research paper entitled,
   \textbf{``{\uppercase\expandafter{\@title}}''} and submitted by
  \textbf{\uppercase\expandafter{\@firstnamea} \uppercase\expandafter{\@midinitiala}. \uppercase\expandafter{\@surnamea}}, \textbf{\uppercase\expandafter{\@firstnameb} \uppercase\expandafter{\@midinitialb}. \uppercase\expandafter{\@surnameb}}, and \textbf{\uppercase\expandafter{\@firstnamec} \uppercase\expandafter{\@midinitialc}. \uppercase\expandafter{\@surnamec}} 
   to fulfill part of the requirements for
   the course Science and Technology Research II was successfully
   defended and approved on \expandafter{\@defensedate}.
}%% signature page

\def\prelim{%%prelim page
\typeout{Making SMCT preliminary headings...}%
   \pagestyle{plain}
   \pagenumbering{roman}
   \signaturep \newpage
   \baselineskip=20pt
} %%prelim

\endinput

在我的源 TeX 文件中,我会输入类似

\documentclass{highschool}

\defenseDate{18 August 2012}
\title{This is the Title of the Paper}
\surnamea{Author}
\firstnamea{First}
\midinitiala{N}
\surnameb{Author}
\firstnameb{Second}
\midinitialb{N}
\surnamec{Author}
\firstnamec{Third}
\midinitialc{N}

\begin{document}
\prelim %% Prints Preliminary chapters

\end{document}

我想要实现的是

  • 当没有\surnameb,\firstnameb,\midinitialb,\surnamec,\firstnamec,\midinitialc声明时,我收到以下文本:

在此处输入图片描述

  • 当没有\surnamec,\firstnamec,\midinitialc声明时,我收到以下文本:

在此处输入图片描述

  • 当所有内容都声明后,我得到了文本: 在此处输入图片描述

可以这样做吗?如果可以,我该怎么做?

答案1

以下解决方案基于这些假设:

  1. 你只能拥有

    • 作者 1; 或者
    • 作者 1, 和作者 2; 或者
    • 作者 1作者 2, 和作者 3

    例如,

    • 作者 1, 和作者 3; 或者
    • 作者 2, 和作者 3; 或者
    • 作者 2仅;或
    • 作者 3仅有的。
  2. 只需提供名字就足以区分作者是否“存在”。

第二个条件可以修改,但有一个名字似乎合乎逻辑姓氏和可能中间名首字母,但绝不不是名字。因此,您可以使用以下定义:

\def\defenseDate#1{\gdef\@defensedate{#1}}
\def\surnamea#1{\gdef\@surnamea{#1}\@surnameatrue}
\def\firstnamea#1{\gdef\@firstnamea{#1}\@firstnameatrue}
\def\midinitiala#1{\gdef\@midinitiala{#1}\@midinitialatrue}
\def\surnameb#1{\gdef\@surnameb{#1}\@surnamebtrue}
\def\firstnameb#1{\gdef\@firstnameb{#1}\@firstnamebtrue}
\def\midinitialb#1{\gdef\@midinitialb{#1}\@midinitialbtrue}
\def\surnamec#1{\gdef\@surnamec{#1}\@surnamectrue}
\def\firstnamec#1{\gdef\@firstnamec{#1}\@firstnamectrue}
\def\midinitialc#1{\gdef\@midinitialc{#1}\@midinitialctrue}

\def\signaturep{ %% signature page..
  \topmargin 0in \headsep 0in
  \begin{center}
  \textbf{CERTIFICATION}\\[6pt]
  \end{center}
  This is to certify that this research paper entitled,
  \textbf{``{\MakeUppercase{\@title}}''} and submitted by
  \textbf{\MakeUppercase{\@firstnamea} \MakeUppercase{\@midinitiala}.\ \MakeUppercase{\@surnamea}}%
  \if@firstnameb, \if@firstnamec\else and \fi
  \textbf{\MakeUppercase{\@firstnameb} \MakeUppercase{\@midinitialb}.\ \MakeUppercase{\@surnameb}}\if@firstnamec, \else\space\fi
  \if@firstnamec and \textbf{\MakeUppercase{\@firstnamec} \MakeUppercase{\@midinitialc}.\ \MakeUppercase{\@surnamec}} \fi\else\space\fi
  to fulfill part of the requirements for
  the course Science and Technology Research II was successfully
  defended and approved on \expandafter{\@defensedate}.
}%% signature page

我已经在每个相应的作者组件内添加了条件定义(这不是真正必要的,因为只\if@firstnameX使用)并在整个过程中放置​​条件\signaturep以根据条件的真实性包含/排除某些单词/短语/标点符号。

输入

\documentclass{highschool}

\defenseDate{18 August 2012}
\title{This is the Title of the Paper}
\surnamea{Author}
\firstnamea{First}
\midinitiala{N}
\surnameb{Author}
\firstnameb{Second}
\midinitialb{N}
%\surnamec{Author}
%\firstnamec{Third}
%\midinitialc{N}

\begin{document}
\prelim %% Prints Preliminary chapters

\end{document}

产量

在此处输入图片描述


\listauthors{{<first>},{<second>},{<third>},...}以下最小示例添加了一个选项,使用 CSV 列表将作者列表指定为单个宏。

在此处输入图片描述

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\def\@firstmiddlelast#1,#2,#3\@nil{%
  \gdef\@firstname{#1}% Extract first name
  \gdef\@middlename{#2}% Extract middle name
  \gdef\@lastname{#3}% Extract last name
}
\newcommand{\authorfml}{{\bfseries\MakeUppercase{\@firstname\ \@middlename\unskip\ \@lastname}}}% First Middle Last
\newcommand{\authorlfm}{\@lastname,\ \@firstname\ \@middlename\unskip}% Last, First Middle
\newcommand{\authorseq}{\authorfml}% Default author order
\newcounter{@list@item}\newcounter{@total@item}
\newcommand{\listauthors}[1]{%
  \setcounter{@total@item}{0}% Reset total count
  \renewcommand*{\do}[1]{\stepcounter{@total@item}}%
  \docsvlist{#1}% Count number of items in list
  \setcounter{@list@item}{1}% Start at first item
  \renewcommand*{\do}[1]{%
    \stepcounter{@list@item}% Move to next item
    \@firstmiddlelast##1\@nil% Extract first/middle/last names
    \authorseq% Print author names
    \ifnum\value{@list@item}=\value{@total@item}\relax
      , and % Second-to-last name
    \else
      \ifnum\value{@list@item}<\value{@total@item}\relax
        , % First set of names
      \fi
    \fi
  }%
  \docsvlist{#1}% Print list
}
\makeatother
\begin{document}
See \listauthors{{First1,Middle1,Last1},{First2,,Last2},{First3,Middle3,Last3},
  {First4,Middle4,Last4},{First5,,Last5},{First6,Middle6,Last6},
  {First7,Middle7,Last7},{First8,Middle8,Last8},{First9,,Last9}} from first to last. \par
\renewcommand{\authorseq}{\authorlfm}
See \listauthors{{First1,Middle1,Last1},{First2,,Last2},{First3,Middle3,Last3}} from first to last. \par
\end{document}

的定义\authorseq决定了标题的打印方式。\authorseq默认为\authorfml将作者列表打印为<first name>\ <middle name>\unskip\ <last name>(在删除前面的控制空间时\unskip会处理缺失/不存在的问题)。切换作者显示(如果需要,可以在摘要和介绍中使用)是通过重新定义来完成的,而格式则在所使用的宏中控制(或或其他)。<middle name>\\authorseq\authorfml\authorlfm

相关内容