小文字の文字列から大文字のCSを構築して使用する

小文字の文字列から大文字のCSを構築して使用する

私は次のことを実行する方法を探しています

私は命令を受けたい

\setcitation[2]

以下の定義で

\def\setcitation#1#2{\lowercase{\expandafter\gdef\csname mycommoncitation#1\endcsname}{#2}}

基本的に、引数xXxとyyyで呼び出されるたびに、新しいコマンドを作成します。

\mycommoncitationxxx

定義

\yyy

さて、入力xxXが与えられたら、yyyを出力したいとします。そのためには、xxXを小文字のxxxに変換し、\mycommoncitationxxxを呼び出します。

私は次のようにやってみました:

\newcommand\getcitation[1]{%
\lowercase{\csuse{mycommoncitation#1}}
}

そして次のようになります:

\newcommand\getcitation[1]{\lowercase{\expandafter\gdef\csname mycommoncitation#1\endcsname}}

しかし、どちらも機能しません。

最初の部分(私のsetcitationコマンドの定義)については、私の解決策は以下に基づいていました。小文字の文字列から大文字のCSを構築し、定義を与える

2 番目の部分については、まだ助けが見つかりません。

完全な例。これらのコマンドの使用方法も示します。

\documentclass{article} 
\usepackage{etoolbox} 
\newcommand{\setcitation}[2]{\lowercase{\csdef{mycommoncitation#1}}{#2}} 
\newcommand{\getcitation}[1]{\lowercase{\csuse{mycommoncitation#1}}} 

\newcommand{\getcitationifexistsotherwiseinput}[1]{\lowercase{\ifcsdef{mycommoncitation#1}{\getcitation{#1}}{#1}}}


\begin{document} 
\setcitation{Foo}{Bar} 
\getcitation{Foo} 
\mycommoncitationfoo
\getcitationifexistsotherwiseinput{Foo} %My expectation: Bar
\getcitationifexistsotherwiseinput{foo} %my expectation: Bar
\getcitationifexistsotherwiseinput{boo} %my expectation: boo
%Now I want a command that returns 
% \getcitation{FOO} 

\cite{\getcitation{foo}} %my expectaiton: "undefined citation Bar"
\end{document}

ここで、\cite{...} の行で問題が発生し始めます。

答え1

拡張可能なバージョンが必要です\lowercase:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\setcitation}{mm}
 {
  \prop_gput:Nxn \g_bartbog_citations_prop { \str_lowercase:n { #1 } } { #2 }
 }
\DeclareExpandableDocumentCommand{\getcitation}{m}
 {
  \prop_item:Nf \g_bartbog_citations_prop { \str_lowercase:n { #1 } }
 }

\cs_generate_variant:Nn \prop_gput:Nnn { Nx }
\cs_generate_variant:Nn \prop_item:Nn { Nf }
\prop_new:N \g_bartbog_citations_prop
\ExplSyntaxOff

\setcitation{Foo}{Bar} 

\begin{document}
\getcitation{Foo} 
\getcitation{foo} 
\getcitation{FOO} 

\cite{\getcitation{Foo}},
\cite{\getcitation{foo}},
\cite{\getcitation{FOO}}

\begin{thebibliography}{1}

\bibitem{Bar} Whatever

\end{thebibliography}

\end{document}

コンパクトさのためにプロパティ リストを使用しました。

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

答え2

私はもう一つの回答を投稿しました拡張的に大文字と小文字を変更し、パッケージなしで\csname内で使用する

その答えはhttps://tex.stackexchange.com/a/349895/118714

この回答には、2 つの拡張ステップでラテン アルファベットの 26 文字に対応する 26 個の catcode-11(文字) 文字トークンを小文字化するルーチンが含まれています\UD@ExpandableLowercase。このルーチンでは、eTeX などの拡張機能は必要ありません。

(!!!ラテン アルファベットの文字で構成される入力を TeX で読み取ってトークン化すると、通常は catcode-11(文字) 文字トークンが生成されますが\string、、、\meaningなど\jobmaneのプリミティブを展開すると catcode-12(その他) 文字トークンが生成されることに注意してください!!!)

(おそらく好ましくない)副作用として、そのルーチンは、一致する catcode-1-character-tokens と catcode-2-character-tokens のペアを、一致する中括弧付き catcode-1-brace-tokens と中括弧付き catcode-2-brace-tokens のペア、つまり{と に置き換えます}

通常、これらの形式では、カテゴリ コード 1 を持つ文字は開き中括弧のみであり、カテゴリ コード 2 を持つ文字は閉じ中括弧のみであるため、これはプレーン TeX および LaTeX2e では問題にならないと思い{ます}

関連情報