
여기 MWE가 있습니다. 토큰 목록을 사용하는데, 최종 PDF 파일에서 10과 10월을 얻을 수 있습니다.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_my_tl
\prop_new:N \l_my_prop
\NewDocumentCommand{\myset}{m}
{
\tl_set:Nn \l_my_tl { #1 }
\prop_put:Nnn \l_my_prop {test} {#1}
}
\NewDocumentCommand{\myget}{}
{
\tl_use:N \l_my_tl
%%% comment out the above line and uncomment the below lines
% \prop_get:NnN \l_my_prop {test} \l_tmpa_tl
% \tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff
\newcommand\MonthName[1]{%
\ifcase#1\relax\or
January \or Feburary \or March
\or April \or May \or June
\or July \or August \or September
\or October \or November \or December
\else#1\fi
}
\myset{10}
\begin{document}
\myget\\
\MonthName{\myget}
\end{document}
그런 다음 (댓글에서 알 수 있듯이) 소품 목록으로 전환하면, 즉,
\NewDocumentCommand{\myget}{}
{
\prop_get:NnN \l_my_prop {test} \l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
오류가 보고되었습니다\MonthName{\myget}
! Missing number, treated as zero.
\prop_get
test
속성 목록에서 키와 함께 저장된 값을 복구하고 \l_my_prop
이를 토큰 목록 변수에 배치합니다 \l_tmpa_tl
. 그리고 저는 이 변수를 사용합니다. 첫 번째 경우와 비교하면 할 일이 있다고 생각합니다 \prop_get
. 그러나 나는 그것을 고치는 방법을 모른다.
답변1
\prop_get:NnN
확장이 불가능하므로 에서 직접 사용할 수 없습니다 \ifcase
. \ifcase
확장을 시도 하면 \myget
(때문에 확장할 수 없음 \prop_get:NnN
) 실패하고 TeX는 다음과 같이 말합니다 Missing number, treated as zero
.
그러나 수행하려는 할당은 \l_tmpa_tl
기본적으로 쓸모가 없으므로 해당 단계를 건너뛰고 직접 사용할 수 있습니다. \prop_item:Nn
이는 확장 가능하며 다음 \myget
을 사용하여 확장 가능 하게 만듭니다 \NewExpandableDocumentCommand
.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_my_tl
\prop_new:N \l_my_prop
\NewDocumentCommand{\myset}{m}
{
\tl_set:Nn \l_my_tl { #1 }
\prop_put:Nnn \l_my_prop {test} {#1}
}
\NewExpandableDocumentCommand{\myget}{}
{
% \tl_use:N \l_my_tl
%%% comment out the above line and uncomment the below lines
\prop_item:Nn \l_my_prop {test}
}
\ExplSyntaxOff
\newcommand\MonthName[1]{%
\ifcase#1\relax\or
January \or Feburary \or March
\or April \or May \or June
\or July \or August \or September
\or October \or November \or December
\else#1\fi
}
\myset{10}
\begin{document}
\myget\\
\MonthName{\myget}
\end{document}
더 많은 것을 사용할 수 있습니다 expl3
-와이 \int_case:nn
또한:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_my_tl
\prop_new:N \l_my_prop
\NewDocumentCommand{\myset}{m}
{
\tl_set:Nn \l_my_tl { #1 }
\prop_put:Nnn \l_my_prop {test} {#1}
}
\NewExpandableDocumentCommand{\myget}{}
{
\prop_item:Nn \l_my_prop {test}
}
\NewExpandableDocumentCommand{\MonthName}{m}
{
\int_case:nnF { #1 }
{
{ 1 } { January }
{ 2 } { Feburary }
{ 3 } { March }
{ 4 } { April }
{ 5 } { May }
{ 6 } { June }
{ 7 } { July }
{ 8 } { August }
{ 9 } { September }
{ 10 } { October }
{ 11 } { November }
{ 12 } { December }
}
{ \int_eval:n {#1} }
}
\ExplSyntaxOff
\myset{10}
\begin{document}
\myget\\
\MonthName{\myget}
\end{document}