소문자 문자열에서 대문자 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를 작성하고 정의를 제공합니다.

두 번째 부분에서는 아직 도움을 찾을 수 없습니다.

완전한 예는 다음 명령을 사용하는 방법도 보여줍니다.

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

\UD@ExpandableLowercase해당 답변 에는 두 가지 확장 단계 내에서 라틴 알파벳 26자에 해당하는 26개의 catcode-11(문자)-문자 토큰을 소문자로 전달하는 루틴이 포함되어 있습니다 . 해당 루틴에는 eTeX 또는 유사한 확장이 필요하지 않습니다.

(!!! TeX가 라틴 알파벳 문자로 구성된 입력을 읽고 토큰화하면 일반적으로 catcode-11(문자) 문자 토큰이 생성되는 반면 , 등 \string의 기본 요소를 확장하면 catcode-12(기타) 문자 토큰이 전달됩니다. !!!)\meaning\jobmane

(아마도 싫어하는) 부작용으로 루틴은 일치하는 catcode-1-character-tokens 및 catcode-2-character-token 쌍을 일치하는 curly catcode-1-brace-tokens 및 curly catcode-2-brace- 쌍으로 대체합니다. 토큰, 즉 {}.

나는 이것이 일반 TeX 및 LaTeX2e에서는 문제가 되지 않아야 한다고 생각합니다. 이러한 형식에서는 일반적으로 범주 코드 1이 있는 유일한 문자는 여는 중괄호 {이고 범주 코드 2가 있는 유일한 문자는 닫는 중괄호입니다 }.

관련 정보