首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LaTeX:重新定义星号命令

LaTeX:重新定义星号命令
EN

Stack Overflow用户
提问于 2010-03-10 16:13:56
回答 2查看 6K关注 0票数 11

我想重新定义\part*命令,以便它自动添加一个内容行。这证明很困难,因为我想在我的星型版本中重用原始的\part*命令。

通常(即对于非星型命令),我会这样做:

代码语言:javascript
复制
\let\old@part\part
\renewcommand\part[2][]{
  \old@part[#1]{#2}
  … rest of definition}

也就是说,我将把\part的原始定义保存在\old@part中并使用它。

但是,这并不适用于星型命令,因为它们没有定义一个lexeme (与上面示例中的\part命令不同)。这归结为以下问题:如何保存星型命令?

注意,我已经知道如何使用\WithSuffix包中的suffix命令重新定义星型命令本身。这不是问题所在。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-10 16:43:55

没有\part*命令。所发生的情况是,\part命令查看它后面的下一个字符(使用\@ifstar),并根据是否存在星号,向其他两个例程中的一个分配实际工作。

参考: TeX FAQ条目选项

票数 11
EN

Stack Overflow用户

发布于 2010-03-10 17:06:09

感谢@smg的回答,我拼凑出了一个完美的解决方案。这是完整的来源,以及解释性评论:

代码语言:javascript
复制
% If this is in *.tex file, uncomment the following line.
%\makeatletter

% Save the original \part declaration
\let\old@part\part

% To that definition, add a new special starred version.
\WithSuffix\def\part*{
  % Handle the optional parameter.
  \ifx\next[%
    \let\next\thesis@part@star%
  \else
    \def\next{\thesis@part@star[]}%
  \fi
  \next}

% The actual macro definition.
\def\thesis@part@star[#1]#2{
  \ifthenelse{\equal{#1}{}}
   {% If the first argument isn’t given, default to the second one.
    \def\thesis@part@short{#2}
    % Insert the actual (unnumbered) \part header.
    \old@part*{#2}}
   {% Short name is given.
    \def\thesis@part@short{#1}
    % Insert the actual (unnumbered) \part header with short name.
    \old@part*[#1]{#2}}

  % Last, add the part to the table of contents. Use the short name, if provided.
  \addcontentsline{toc}{part}{\thesis@part@short}
}

% If this is in *.tex file, uncomment the following line.
%\makeatother

(这需要包suffixifthen。)

现在,我们可以使用它:

代码语言:javascript
复制
\part*{Example 1}
This will be an unnumbered part that appears in the TOC.

\part{Example 2}
Yes, the unstarred version of \verb/\part/ still works, too.
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2418476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档