
これが 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}
次に、(コメントにあるように)propリストに切り替えると、
\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
展開しようとすると失敗し、TeX は と出力します。\myget
\prop_get:NnN
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}