2010-03-10 265 views
9

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

通常情况下(即用于取消星号命令)我会做这样的:

\let\[email protected]\part 
\renewcommand\part[2][]{ 
    \[email protected][#1]{#2} 
    … rest of definition} 

也就是说,我将节省的\part\[email protected]原始定义和使用。

但是,这对于已加星号的命令不起作用,因为它们没有定义单个词位(与上例中的\part命令不同)。这可归结为以下问题:如何保存已加星标的命令?

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

回答

8

没有\part*命令。 \part命令会查看其后的下一个字符(使用\@ifstar),并根据是否存在星号来分派到执行实际工作的其他两个例程之一。

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=cmdstar

+0

“没有'\部分*'命令。“ - 我知道。 :-(否则我就不会有这个问题了 – 2010-03-10 16:50:49

+0

那么那么就像你有和处理两个版本那样重新定义'\ part'?或者挖掘到LaTeX源代码并重新定义潜在的星号“\ part”代码? – 2010-03-10 16:56:28

+0

...但是这个是一个重要的提示,我现在已经开始工作了,很快就会发布解决方案 – 2010-03-10 16:57:54

3

感谢@ SMG的答案,我拼凑的作品完美的解决方案。下面是完整的源代码,带解释性意见一起:

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

% Save the original \part declaration 
\let\[email protected]\part 

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

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

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

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

(这需要包suffixifthen

现在,我们可以用它:

\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.