根据字符串参数更改 maketitle

根据字符串参数更改 maketitle

我想将命令更改\maketitle如下:如果没有给出参数,则 maketitle 应定义为

\renewcommand{\maketitle}{%
  \vspace*{-70pt}
  {\sffamily\slshape\bfseries faculty, }{\textsf{chair}}\\
  {\textsf{author}}
  \vspace*{6pt}

  {\huge\textsf{title}}

  \hrule
  \vspace*{6pt}
}

现在我想根据不同的参数字符串更改标题。如果参数等于字符串“lecture”,则间距应该更改,标题应该是“Lecture”,日期应该出现在标题页上,例如,如果我输入 \maketitle{lecture},它应该更改为

  \vspace*{-70pt}
  {\sffamily\slshape\bfseries faculty, }{\textsf{chair}}\\
  {\textsf{author}}
  \vspace*{6pt}

  {\huge\textsf{Lecture title}}
  \vspace*{6pt}

  {\textsf{\today}}
  \vspace*{12pt}

  \hrule
  \vspace*{24pt}
}

我想用更多参数来做到这一点,但这是基本想法。我读过 etoolbox 包的文档,但我无法很好地理解。

答案1

一个非常简单且易于扩展的解决方案是将不同版本存储在宏中,然后检查是否存在该名称的宏。如果存在,则使用它,如果它不抛出错误。

\documentclass[]{article}

\makeatletter
\renewcommand\maketitle[1]
  {%
    % use \detokenize to make sure the argument is handled as a string, hence no
    % macros are expanded in #1.
    \ifcsname maketitle@\detokenize{#1}\endcsname
      % the \expandafter there expands the \else and this way only executes the
      % title macro after the \ifcsname check is completely done.
      \csname maketitle@\detokenize{#1}\expandafter\endcsname
    \else
      \PackageError{Maketitle}
        {Requested maketitle version \detokenize{#1} is not defined.}%
        {}%
    \fi
  }
% the default version, with an empty argument.
\newcommand\maketitle@
  {%
    \vspace*{-70pt}
    {\sffamily\slshape\bfseries faculty, }\textsf{chair}\\
    \textsf{author}%
    \vspace*{6pt}%
    \par
    {\huge\textsf{title}\par}%
    \hrule
    \vspace*{6pt}%
  }
% the lecture version
\newcommand\maketitle@lecture
  {%
    \vspace*{-70pt}%
    {\sffamily\slshape\bfseries faculty, }\textsf{chair}\\
    \textsf{author}%
    \vspace*{6pt}%
    \par
    {\huge\textsf{Lecture title}\par}%
    \vspace*{6pt}%
    \par
    \textsf{\today}%
    \vspace*{12pt}%
    \par
    \hrule
    \vspace*{24pt}%
  }
\makeatother

\begin{document}
\maketitle{}

\vspace{10cm}

\maketitle{lecture}
\end{document}

在此处输入图片描述

除了这个之外,\ifcsname你也可以使用

\@ifundefined{maketitle@\detokenize{#1}}
  {%
    \PackageError{Maketitle}
      {Requested maketitle version \detokenize{#1} is not defined.}%
      {}%
  }
  {\csname maketitle@\detokenize{#1}\endcsname}%

答案2

在您的问题中,并非所有要检查/分叉的字符串都有命名。

这种情况意味着无论如何您都需要根据答案中提供的示例来调整您的需求。

因此,我认为你的问题的重点不是受访者为\maketitle你重新定义,而是受访者展示分支/分叉的技术,这些技术可以应用于一般的宏编程,你可以在自己做事情时应用\maketitle

因此,下面我不提供可能的重新定义\maketitle

相反,我提供了分叉机制的例子,其中展示了一些技术,您也可以在重新定义时应用这些技术\maketitle


您可以根据分隔参数实现分叉机制:

\documentclass{article}

\makeatletter
\@ifdefinable\gobbletoexclam{\long\def\gobbletoexclam#1!{}}%
\newcommand\fork[1]{%
  \ifcat$\detokenize\expandafter{\gobbletoexclam#1!}$% <- Check whether #1 is empty after removing stuff till first ! of the sequence "#1!"
  \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {%
    \selectcase
    !#1! !lecture!presentation!speech!talk!interview!{We have emptiness}%
    !!#1!lecture!presentation!speech!talk!interview!{We have space token}%
    !! !#1!presentation!speech!talk!interview!{We have lecture}%
    !! !lecture!#1!speech!talk!interview!{We have presentation}%
    !! !lecture!presentation!#1!talk!interview!{We have speech}%
    !! !lecture!presentation!speech!#1!interview!{We have talk}%
    !! !lecture!presentation!speech!talk!#1!{We have interview}%
    !! !lecture!presentation!speech!talk!interview!{We have something else without exclamation-mark}%
    !!!!%
  }{We have something else with exclamation-mark}%
}%
\@ifdefinable\selectcase{%
  \long\def\selectcase#1!! !lecture!presentation!speech!talk!interview!#2#3!!!!{#2}%
}%
\makeatother

\begin{document}

\fork{}

\fork{ }

\fork{lecture}

\fork{presentation}

\fork{speech}

\fork{talk}

\fork{interview}

\fork{whatsoever}

\fork{!whatsoever}

\end{document}

在此处输入图片描述


如果您愿意,可以将其与从参数列表中选择元素的例程相结合 - 这样,如果您想要拥有不同的字符串组,您可以很容易地“合并”案例,其中来自不同组的字符串触发不同的操作,而来自同一组的字符串会触发相同的操作:

\documentclass{article}

\makeatletter
%% Code for \ExtractKthArg
%%=============================================================================
%% Paraphernalia:
%%    \UD@firstoftwo, \UD@secondoftwo, \UD@PassFirstToSecond, \UD@Exchange,
%%    \UD@stopromannumeral, \UD@CheckWhetherNull
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
\newcommand\UD@Exchange[2]{#2#1}%
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is empty>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
  \romannumeral\expandafter\UD@secondoftwo\string{\expandafter
  \UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
  \UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
  \UD@secondoftwo\string}\expandafter\UD@stopromannumeral\UD@secondoftwo}{%
  \expandafter\UD@stopromannumeral\UD@firstoftwo}%
}%
%%=============================================================================
%% Extract K-th inner undelimited argument:
%%
%% \ExtractKthArg{<integer K>}%
%%               {<tokens in case list of undelimited args doesn't have a k-th argumnent>}%
%%               {<list of undelimited args>} %
%% 
%% In case there is no K-th argument in <list of indelimited args> : 
%%   Does deliver <tokens in case list of undelimited args doesn't have a k-th argumnent.
%% In case there is a K-th argument in <list of indelimited args> : 
%%   Does deliver that K-th argument with one level of braces removed.
%%
%% Examples:
%%
%%   \ExtractKthArg{0}{not available}{ABCDE} yields: not available
%%
%%   \ExtractKthArg{3}{not available}{ABCDE} yields:  C
%%
%%   \ExtractKthArg{3}{not available}{AB{CD}E} yields:  CD
%%
%%   \ExtractKthArg{4}{not available}{{001}{002}{003}{004}{005}} yields: 004
%%
%%   \ExtractKthArg{6}{not available}{{001}{002}{003}} yields: not available 
%% 
%%=============================================================================
\newcommand\ExtractKthArg[2]{%
  \romannumeral%
  % #1: <integer number K>
  % #2: <action if there is no K-th argument>
  \expandafter\UD@ExtractKthArgCheck
  \expandafter{\romannumeral\number\number#1 000}{#2}%
}%
\newcommand\UD@ExtractKthArgCheck[3]{%
  \UD@CheckWhetherNull{#1}{\UD@stopromannumeral#2}{% empty
    \expandafter\UD@ExtractKthArgLoop\expandafter{\UD@firstoftwo{}#1}{#2}{#3}%
  }%
}%
\begingroup
\def\UD@ExtractFirstArgLoop#1{%
  \endgroup
  \@ifdefinable\UD@RemoveTillFrozenrelax{%
    \long\def\UD@RemoveTillFrozenrelax##1##2#1{{##1}}%
  }%
  \newcommand\UD@ExtractKthArgLoop[3]{%
    \expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo##3{}.}{\UD@stopromannumeral##2}{%
      \UD@CheckWhetherNull{##1}{%
        \UD@ExtractFirstArgLoop{##3#1}%
      }{%
        \expandafter\UD@PassFirstToSecond\expandafter{\UD@firstoftwo{}##3}%
        {\expandafter\UD@ExtractKthArgLoop\expandafter{\UD@firstoftwo{}##1}{##2}}%
      }%
    }%
  }%
}%
\expandafter\expandafter\expandafter\UD@ExtractFirstArgLoop
\expandafter\expandafter\expandafter{%
\expandafter\expandafter\ifnum0=0\fi}%
%% Usage of frozen-\relax as delimiter is for speeding things up by reducing the
%% amount of iterations needed. I chose frozen-\relax because David Carlisle 
%% pointed out in   <https://tex.stackexchange.com/a/578877>
%% that frozen-\relax cannot be (re)defined in terms of \outer and cannot be
%% affected by \uppercase/\lowercase.
%%
%% \UD@ExtractFirstArg's argument may contain frozen-\relax:
%% The only effect is that internally more iterations are needed for
%% obtaining the result.
\newcommand\UD@ExtractFirstArgLoop[1]{%
  \expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
  {\expandafter\UD@stopromannumeral\UD@firstoftwo#1{}}%
  {\expandafter\UD@ExtractFirstArgLoop\expandafter{\UD@RemoveTillFrozenrelax#1}}%
}%
%% End of code for \ExtractKthArg.
%%-----------------------------------------------------------------------------
%%-----------------------------------------------------------------------------
%% Code for forking mechanism
\@ifdefinable\gobbletoexclam{\long\def\gobbletoexclam#1!{}}%
\newcommand\fork[1]{%
  \ExtractKthArg{%
    \expandafter\UD@CheckWhetherNull\expandafter{\gobbletoexclam#1!}%
    {%
      \selectcase
      !#1! !lecture!presentation!speech!talk!interview!{1}% We have emptiness
      !!#1!lecture!presentation!speech!talk!interview!{1}% We have space token
      !! !#1!presentation!speech!talk!interview!{2}% We have lecture
      !! !lecture!#1!speech!talk!interview!{3}% We have presentation
      !! !lecture!presentation!#1!talk!interview!{4}% We have speech
      !! !lecture!presentation!speech!#1!interview!{5}% We have talk
      !! !lecture!presentation!speech!talk!#1!{6}% We have interview
      !! !lecture!presentation!speech!talk!interview!{7}% We have something else without exclamation-mark
      !!!!%
    }{7}% We have something else with exclamation-mark
  }{}{%
    {We have emptiness or space token}%1
    {We have lecture}% 2
    {We have presentation}% 3
    {We have speech}% 4
    {We have talk}% 5
    {We have interview}% 6
    {We have something else}% 7
  }%
}%
\@ifdefinable\selectcase{%
  \long\def\selectcase#1!! !lecture!presentation!speech!talk!interview!#2#3!!!!{#2}%
}%
%% End of code for forking mechanism
\makeatother

\begin{document}

\fork{}

\fork{ }

\fork{lecture}

\fork{presentation}

\fork{speech}

\fork{talk}

\fork{interview}

\fork{whatsoever}

\fork{!whatsoever}

\end{document}

在此处输入图片描述


如果您希望有一个可以动态提供参数的分叉机制,我建议使用略有不同的例程从参数列表中选择一个元素:

\documentclass{article}

\makeatletter
%% Code for \KeepKthOfLArguments: 
%%=============================================================================
%% Paraphernalia:
%%    \UD@firstoftwo, \UD@secondoftwo, \UD@PassFirstToSecond, 
%%    \UD@stopromannumeral, \UD@CheckWhetherNull
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is empty>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
  \romannumeral\expandafter\UD@secondoftwo\string{\expandafter
  \UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
  \UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
  \UD@secondoftwo\string}\expandafter\UD@stopromannumeral\UD@secondoftwo}{%
  \expandafter\UD@stopromannumeral\UD@firstoftwo}%
}%
%%=============================================================================
%% Keep only the K-th of L consecutive undelimited arguments.
%%   ( IF K < 1 OR K > L just remove L consecutive undelimited arguments. )
%%=============================================================================
%% \KeepKthOfLArguments{<integer number K>}%
%%                     {<integer number L>}%
%%                     <sequence of L consecutive undelimited arguments>
%%
%% If L < 1 yields nothing.
%% Else:
%%   If K >= 1 and K < L  yields:
%%     <K-th undelimited argument from <sequence of L consecutive undelimited 
%%      arguments>>
%%   If K < 1 or K > L
%%     (-> there is no K-th argument in the
%%         <sequence of L consecutive undelimited arguments> )
%%   yields nothing  but removal of <sequence of L consecutive 
%%          undelimited arguments>
\newcommand\KeepKthOfLArguments[2]{%
  \romannumeral
  % #1: <integer number K>
  % #2: <integer number L>
  \expandafter\UD@KeepKthOfLArgumentsKSmallerOneFork
  \expandafter{\romannumeral\number\number#1 000\expandafter}%
  \expandafter{\romannumeral\number\number#2 000}%
}%
%%-----------------------------------------------------------------------------
\newcommand\UD@KeepKthOfLArgumentsKSmallerOneFork[2]{%
  % #1: <K letters m>
  % #2: <L letters m >
  \UD@CheckWhetherNull{#1}{% K is smaller than one:
    \UD@KeepKthOfLArgumentsRemoveNArguments{#2}{\UD@stopromannumeral}{}%
  }{% K is not smaller than one:
    \expandafter\UD@PassFirstToSecond
    \expandafter{%
      \UD@firstoftwo{}#1%
    }{%
      \UD@KeepKthOfLArgumentsEvaluateLMinusKDifferenceLoop{#1}{#2}%
    }{#2}%
  }%
}%
%%-----------------------------------------------------------------------------
\newcommand\UD@KeepKthOfLArgumentsEvaluateLMinusKDifferenceLoop[4]{%
  % #1: <K letters m>  
  % #2: <L letters m>
  % (For detecting whether K>L or K<=L, during the loop letters m will
  %  be removed both from #1 and #2 until at least one of these arguments 
  %  is empty.
  %  When the loop terminates with 0<K<=L, #1 will be empty and #2
  %  will hold an amount of letters m corresponding to the the 
  %  difference L-K.
  %  When the loop terminates with K>L, #1 will not be empty and #2
  %  will be empty.
  % )
  % #3: <K-1 letters m>
  % #4: <L letters m>
  % (#3 and #4 will be left untouched during the loop so they can be 
  %  used for performing appropriate action when loop terminates as
  %  it is known whether K>L.)
  \UD@CheckWhetherNull{#1}{% We have K<=L:
     \UD@KeepKthOfLArgumentsRemoveNArguments{%
       #3%
      }{%
       \UD@KeepKthOfLArgumentsRemoveNArguments{#2}{\UD@stopromannumeral}%
      }{}%
  }{%
    \UD@CheckWhetherNull{#2}{% We have K>L:
      \UD@KeepKthOfLArgumentsRemoveNArguments{#4}{\UD@stopromannumeral}{}%
    }{% We don't know yet whether K<=L or K>L, thus remove letters m and 
      % do another iteration:
      \expandafter\UD@PassFirstToSecond
      \expandafter{%
        \UD@firstoftwo{}#2%
      }{%
        \expandafter\UD@KeepKthOfLArgumentsEvaluateLMinusKDifferenceLoop
        \expandafter{%
          \UD@firstoftwo{}#1%
        }%
      }{#3}{#4}%
    }%
  }%
}%
%%-----------------------------------------------------------------------------
%% \UD@KeepKthOfLArgumentsRemoveNArguments{<N letters m>}%
%%                                        {<argument 1>}%
%%                                        {<argument 2>}%
%%                                        <sequence of consecutive 
%%                                         undelimited arguments>
%%.............................................................................
%% Removes the first N undelimited arguments from the <sequence of 
%% consecutive undelimited arguments>, then inserts  
%% <argument 1><argument 2>
%%
%% On the one hand when providing <argument 2> empty, you can use 
%% <argument 1> for nesting calls to \UD@KeepKthOfLArgumentsRemoveNArguments.
%% On the other hand you can provide a <space token> for stopping
%% \romannumeral-expansion as  <argument 1> and have the
%% macro grab the <K-th undelimited argument> from the <sequence of L 
%% consecutive undelimited arguments> as <argument 2>.
%%
\newcommand\UD@KeepKthOfLArgumentsRemoveNArguments[3]{%
  %% #1: <N letters m>  
  %% #2: <Argument 1>   
  %% #3: <Argument 2>
  \UD@CheckWhetherNull{#1}{#2#3}{%
    \UD@firstoftwo{%
      \expandafter\UD@KeepKthOfLArgumentsRemoveNArguments
      \expandafter{%
        \UD@firstoftwo{}#1%
      }{#2}{#3}%
    }%
  }%
}%
%%-----------------------------------------------------------------------------
%% End of code for \KeepKthOfLArguments.
%%-----------------------------------------------------------------------------
%%-----------------------------------------------------------------------------
%% Code for forking mechanism
\@ifdefinable\gobbletoexclam{\long\def\gobbletoexclam#1!{}}%
\newcommand\fork[1]{%
  \KeepKthOfLArguments{%
    \expandafter\UD@CheckWhetherNull\expandafter{\gobbletoexclam#1!}%
    {%
      \selectcase
      !#1! !lecture!presentation!speech!talk!interview!{1}% Case: We have emptiness
      !!#1!lecture!presentation!speech!talk!interview!{1}% Case: We have space token
      !! !#1!presentation!speech!talk!interview!{2}% Case: We have lecture
      !! !lecture!#1!speech!talk!interview!{3}% Case: We have presentation
      !! !lecture!presentation!#1!talk!interview!{4}% Case: We have speech
      !! !lecture!presentation!speech!#1!interview!{5}% Case: We have talk
      !! !lecture!presentation!speech!talk!#1!{6}% Case: We have interview
      !! !lecture!presentation!speech!talk!interview!{7}% Case: We have something else without exclamation-mark
      !!!!%
    }{7}% Case: We have something else with exclamation-mark
  }{7}% <- 7 arguments holding tokens for 7 cases follow from which to select.
}%
\@ifdefinable\selectcase{%
  \long\def\selectcase#1!! !lecture!presentation!speech!talk!interview!#2#3!!!!{#2}%
}%
%% End of code for forking mechanism
\makeatother

\begin{document}

\fork{}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7


\fork{ }%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{lecture}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{presentation}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{speech}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{talk}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{interview}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{whatsoever}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\fork{!whatsoever}%
     {In the first argument we have emptiness or space token}%1
     {In the first argument we have lecture}% 2
     {In the first argument we have presentation}% 3
     {In the first argument we have speech}% 4
     {In the first argument we have talk}% 5
     {In the first argument we have interview}% 6
     {In the first argument we have something else}% 7

\end{document}

在此处输入图片描述

如果你重新定义的第一部分\maketitle总是

\vspace*{-70pt}
{\sffamily\slshape\bfseries faculty, }{\textsf{chair}}\\
{\textsf{author}}
\vspace*{6pt}

,那么你可以这样做:

\renewcommand\maketitle[1][]{% Now \maketitle has an optional argument whose default is "empty". You could as well provide "lecture" or one of the other strings/cases as default.
  \vspace*{-70pt}%
  {\sffamily\slshape\bfseries faculty, }{\textsf{chair}}\\
  {\textsf{author}}%
  \vspace*{6pt}%
  \fork{#1}%
       {<tokens in case #1 is empty (which is the default) or a single explicit space token>}%1
       {<tokens in case #1 is "lecture">}% 2
       {<tokens in case #1 is "presentation">}% 3
       {<tokens in case #1 is "speech">}% 4
       {<tokens in case #1 is "talk">}% 5
       {<tokens in case #1 is "interview">}% 6
       {<tokens in case #1 is something else>}% 7
}%

,其中
{<tokens in case #1 is empty (which is the default) or a single explicit space token>}=

{%

  {\huge\textsf{title}}%

  \hrule
  \vspace*{6pt}%
}%

,并且
{<tokens in case #1 is "lecture">}=

{%

  {\huge\textsf{Lecture title}}%
  \vspace*{6pt}%

  {\textsf{\today}}%
  \vspace*{12pt}%

  \hrule
  \vspace*{24pt}%
}%

-thingies<tokens in case #1 is...>也可以由对任何其他辅助宏的调用组成,这些宏依次从 .tex-input-file 中抓取和处理(不同)的参数组合/数量。这样,您可以根据\maketitle's给出的情况获得不同的后续参数集#1

您还可以让其\maketitle自身抓取多个参数。然后在<tokens in case #1 is...>-thingies 中,这些参数可以被称为#1#2、 ... #9

在 LaTeX 的标准文档类文章/报告/书籍字符串中,包含有关标题、作者、日期和感谢对象的信息,通常存储为内部宏\@title/ \@author/ \@date/ \@thanks

用户宏\title/ \author/ \date/\thanks用于重新定义这些内部宏。


评论:

  1. \ExtractKthArg上面介绍的例程\KeepKthOfLArguments可以处理九个以上的参数/案例。

  2. 上面介绍的例程\fork\ExtractKthArg\KeepKthOfLArguments仅基于扩展。不会发生任何临时分配(定义临时宏或类似操作)。
    因此,这些例程也可以在扩展上下文中使用,例如,在 之间\csname..\endcsname、与\edef/\xdef和变体、与\message\write与 、与\number\romannumeral与 expl3 的 c/o/x/e/f 类型参数、与 expl3 的\exp:w..\exp_end:等。

  3. 在由 形成的机制下\gobbletoexclam\selectcase假设\fork要分叉的字符串中不包含!。您可以选择任何非空的标记序列
    来代替!

    • 不出现在任何要分叉的字符串中,并且
    • 它既不包含\outer-token,也不包含
    • 类别 1、2 或 6 的显式字符标记

    用于分离要分叉的字符串。

    我建议使用不以控制字标记结尾的标记序列 - 这样 TeX 的读取装置就不会处于状态 S(跳过空格),并且具有前导空格标记的单个字符串不会成为问题。

  4. 在现实生活中,您可能希望在应用(第一个)参数之前\fork对其进行预处理,例如,
    \uppercase{\fork{#1}}{...}{...}
    \lowercase{\fork{#1}}{...}{...}
    \expanded{\unexpanded{\fork}{#1}}{...}{...}
    \uppercase\expandafter{\expanded{\unexpanded{\fork}{#1}}}{...}{...}
    \lowercase\expandafter{\expanded{\unexpanded{\fork}{#1}}}{...}{...}或其他。



如果您选择使用 expl3,那么函数\str_case:nn/ \str_case:nnTF/ \str_case_e:nn/\str_case_e:nnTF expl3l3str你可能会感兴趣

例如,你可以做类似的事情

\documentclass{article}

\ExplSyntaxOn
\let\MyStringCase=\str_case:nnTF
\ExplSyntaxOff

\renewcommand\maketitle[1][]{% Now \maketitle has an optional argument whose default is "empty". You could as well provide "lecture" or one of the other strings/cases as default.
  \vspace*{-70pt}%
  {\sffamily\slshape\bfseries faculty, }{\textsf{chair}}\\
  {\textsf{author}}%
  \vspace*{6pt}%
  \MyStringCase{#1}{%
    {}{<tokens in case #1 is empty (which is the default)>}%
    { }{<tokens in case #1 is a single explicit space token>}%
    {lecture}{<tokens in case #1 is "lecture">}%
    {presentation}{<tokens in case #1 is "presentation">}%
    {speech}{<tokens in case #1 is "speech">}%
    {talk}{<tokens in case #1 is "talk">}% 
    {interview}{<tokens in case #1 is "interview">}%
  }%
  {%
    <tokens to append in any of the cases listed above>%
  }%
  {%
    <tokens in case #1 is something else>%
  }%
}%

\begin{document}

\maketitle

\maketitle[]

\maketitle[ ]

\maketitle[lecture]

\maketitle[presentation]

\maketitle[speech]

\maketitle[talk]

\maketitle[interview]

\maketitle[whatsoever]

\end{document}

如果<tokens to append in any of the cases listed above>为空,那么 -thingies也可以包含对任何其他辅助宏的调用,这些宏依次从 .tex-input-file 中抓取和处理(不同)的参数组合/数量。这样,您可以根据的<tokens in case #1 is...>给出的情况获得不同的后续参数集。\maketitle#1

您还可以让其\maketitle自身抓取多个参数。然后在<tokens in case #1 is...>-thingies 和<tokens to append in any of the cases listed above>这些参数中可以引用为#1, #2, ..., #9

在 LaTeX 的标准文档类文章/报告/书籍字符串中,包含有关标题、作者、日期和感谢对象的信息,通常存储为内部宏\@title/ \@author/ \@date/ \@thanks

用户宏\title/ \author/ \date/\thanks用于重新定义这些内部宏。



大卫·卡斯特鲁普的\strequal您可能也感兴趣:

David Kastrup:
比较两个已知仅由字符组成的字符串

\def\strequal#1{\number\strequalstart{}{}#1\relax}
\def\strequalstart#1#2#3{\if#3\relax\strequalstop\fi
  \strequalstart{\if#3#1}{#2\fi}}
\def\strequalstop\fi\strequalstart#1#2#3{\fi#1#3\relax'#213 }

\if\strequal{junk}{#1}如果是“垃圾”,则为真#1,否则为假。

还有很多 TeX 珍品收集于GUST (Polska Grupa Użytkowników Systemu TeX) 的主页

相关内容