新しいコマンドの順序を変更する方法

新しいコマンドの順序を変更する方法

私は LaTeX に関してはまったくの素人なので、全体の経緯を説明せずに質問する方法がわかりません。

大きな文書で、私は現代の著者を引用する場合(BibTeX などを使用する)に使用するのとは異なる規則に従って、(古典ラテン語の)著者を引用するためのかなり単純なコマンドを作成しました。これは私が使用するコマンドです。

\newcommand{\citeCL}[3]{#1, \emph{#2}, \textbf{#3}}
%\citeCL{author}{text}{chapter}

最初の2つの引数として、著者名とテキストタイトルのリストからさらに他のコマンドを使用します(すべての名前を複数回使用するため、毎回フルネームで書くと一貫性がなくなる可能性があるため)。例:

\newcommand{\Per}{N. Per.}
\newcommand{\PerRud}{Rud. gram.}

ドキュメント内では、次のように cite コマンドを呼び出すことができます。

\citeCL{\Per}{\PerRud}{1117}

この cite コマンドは、脚注とこの引用環境の両方で使用します。

\newcommand{\QuoteCL}[4]{
\vspace{5pt}
\begin{quote}\itemsep1pt\parskip0pt\parsep0pt\begin{spacing}{1}
#4 \par\hspace*{\fill}\footnotesize{\citeCL{#1}{#2}{#3}}
\end{spacing}
\end{quote}
\vspace{-20pt}
}

ドキュメントでは、 と同じ3つの引数と\citeCL、引用するテキストを追加してコマンドを呼び出します。例:

\QuoteCL{\Per}{\PerRud}{§ 1119}{Quis maxime proponendus est quem studeant adolescentes imitari? Marcus Cicero.}

これらはすべてうまく機能し、私は論文全体を通してこれを使用しました。今度は、脚注と引用文での著者名とタイトルの書き方を区別し、脚注では省略形を使用し、引用文では新しい長い形式を使用したいと思います。私の直感的で素朴なアプローチは次のとおりです。

\newcommand{\citeCL}[3]{#1, \emph{#2}, \textbf{#3}}
% Original command now used for footnotes

\newcommand{\citeCLLong}[3]{#1Long, \emph{#2Long}, \textbf{#3}}
% New command to be called by the \quoteCL command.

\newcommand{\Per}{N. Per.}
\newcommand{\PerLong}{Niccolò Perotti}
\newcommand{\PerRud}{Rud. gram.}
\newcommand{\PerRudLong}{Rudimenta grammatices}
% Duplicating the list of names and titles, adding a long version to be called by the \citeCLLong:

\newcommand{\QuoteCL}[4]{
\vspace{5pt}
\begin{quote}\itemsep1pt\parskip0pt\parsep0pt\begin{spacing}{1}
#4 \par\hspace*{\fill}\footnotesize{\citeCLLong{#1}{#2}{#3}}
\end{spacing}
\end{quote}
\vspace{-20pt}
}
% The command is changed to call the new \citeCLLong

\begin{document}
\QuoteCL{\Per}{\PerRud}{§ 1119}{Quis maxime proponendus est quem studeant adolescentes imitari? Marcus Cicero.}
\end{document}

さて、私の質問ですが、引数 を指定してコマンドを呼び出しても、( )Longの引数に追加することで、LaTeX が、著者リストからだけではなく、たとえば を選択するようになることを期待していました。または のどちらを読み取るかが決定される前に、その部分が追加されるということです。 しかし、 = "Niccolò Perotti"を選択する代わりに、たとえば "N. Per.Long" と書き込まれます。\citeCLLong#1Long, \emph{#2Long}\PerLong\Per\quoteCL\PerLong\Per\PerLong\PerLong

これを何とか実現することはできますか、それとも、論文全体を調べてすべての引用のすべての議論を変更する必要がなく、序文から制御できる、もっとスマートな解決策はありますか? また、脚注の引用は元の形式のままですか?

答え1

条件文を使用します。新しいコマンドを使用すると、コマンドを「短い」形式と「長い」形式で一貫して定義できます。次に、およびを\citeCL使用\citeCLLongできます。

\documentclass{article}
\usepackage[utf8]{inputenc}

\newif\ifCLLong

\newcommand{\citeCL}[3]{\CLLongfalse #1, \emph{#2}, \textbf{#3}}

\newcommand{\citeCLLong}[3]{\CLLongtrue #1, \emph{#2}, \textbf{#3}}

\newcommand{\QuoteCL}[4]{%
\begin{quote}
#4 \par\hspace*{\fill}\footnotesize\citeCLLong{#1}{#2}{#3}
\end{quote}
}

% Abstraction for easing the definition    
\newcommand{\newshortlongcommand}[3]{\newcommand{#1}{\ifCLLong #3\else #2\fi}}

\newshortlongcommand{\Per}{N. Per.}{Niccolò Perotti}
\newshortlongcommand{\PerRud}{Rud. gram.}{Rudimenta grammatices}

\begin{document}

Testo introduttivo\footnote{\citeCL{\Per}{\PerRud}{§ 1119}}

\QuoteCL{\Per}{\PerRud}{§ 1119}{Quis maxime proponendus est quem studeant adolescentes imitari? Marcus Cicero.}
\end{document}

\end{document}

(私は、不必要な事柄\QuoteCLから逃れるために、の定義を簡略化しました。)spacing

この方法では、心配することなく引数を直接入力することもできます。たとえば、

\QuoteCL{Niccolò Perotti}{Rudimenta Grammatices}{§ 1119}{...}

同じように動作します。

ここに画像の説明を入力してください

答え2

最初の 2 つの引数を単なるテキスト文字列に変更し、\csname \endcsname構造を使用して目的を達成します。(注: どのパッケージにスペース環境が含まれているかがわからなかったため、スペース環境をオフにしました)

\documentclass{article}
\usepackage[utf8]{inputenc}

\newcommand{\citeCL}[3]{\csname#1\endcsname, \emph{\csname#2\endcsname}, \textbf{#3}}
% Original command now used for footnotes

\newcommand{\citeCLLong}[3]{\csname#1Long\endcsname,
\emph{\csname#2Long\endcsname}, \textbf{#3}}
% New command to be called by the \quoteCL command.

\newcommand{\Per}{N. Per.}
\newcommand{\PerLong}{Niccolò Perotti}
\newcommand{\PerRud}{Rud. gram.}
\newcommand{\PerRudLong}{Rudimenta grammatices}
% Duplicating the list of names and titles, adding a long version to be called by the \citeCLLong:

\newcommand{\QuoteCL}[4]{
\vspace{5pt}
\begin{quote}\itemsep1pt\parskip0pt\parsep0pt%
%\begin{spacing}{1}%
#4 \par\hspace*{\fill}\footnotesize{\citeCLLong{#1}{#2}{#3}}
%\end{spacing}
\end{quote}
\vspace{-20pt}
}
% The command is changed to call the new \citeCLLong

\begin{document}
\QuoteCL{Per}{PerRud}{§ 1119}{Quis maxime proponendus est quem studeant adolescentes imitari? Marcus Cicero.}

\vspace{6em}
\citeCL{Per}{PerRud}{§ 1119}
\end{document}

ここに画像の説明を入力してください

関連情報