11

\part*コンテンツ行が自動的に追加されるように、コマンドを再定義したいと考えています。\part*スター付きバージョン内で元のコマンドを再利用したいので、これは難しいことがわかります。

通常(つまり、スターの付いていないコマンドの場合)、次のようにします。

\let\old@part\part
\renewcommand\part[2][]{
  \old@part[#1]{#2}
  … rest of definition}

つまり、\partinの元の定義を保存して、\old@partそれを使用します。

ただし、これはスター付きコマンドでは機能しません。これは、(\part上記の例のコマンドとは異なり) 単一の語彙素を定義しないためです。これは、次の質問に要約されます:スター付きコマンドを保存するにはどうすればよいですか?

パッケージの\WithSuffixコマンドを使用して、スター付きのコマンド自体を再定義する方法を既に知っていることに注意してください。suffixこれは問題ではありません。

4

2 に答える 2

11

\part*コマンドはありません。何が起こるかというと、\partコマンドは ( を使用して) その後の次の文字を調べ、\@ifstarそこにアスタリスクがあるかどうかに基づいて実際の作業を行う 2 つの他のルーチンのいずれかにディスパッチします。

参考:TeX FAQエントリ*オプションで定義されたコマンド

于 2010-03-10T16:43:55.207 に答える
5

@smg の回答のおかげで、完全に機能するソリューションをまとめました。完全なソースと説明コメントは次のとおりです。

% 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

(これには、パッケージsuffixとが必要ifthenです。)

これで、次のように使用できます。

\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.
于 2010-03-10T17:06:09.647 に答える