好的,事情是这样的。我想存储属性值对,然后稍后将其用作查找表,将值输入到另一个函数中。这是我想到的,但我不知道如何解决这个问题:
\documentclass{article}
\usepackage{expl3,xparse}
\ExplSyntaxOn
% Create a new sequence.
\prop_clear_new:N {\MyLookupTable}
\prop_put:Nnn {\MyLookupTable} {key1} {intermediate1}
\prop_put:Nnn {\MyLookupTable} {key2} {intermediate2}
\cs_generate_variant:Nn \str_case:nnF {xn}
\NewDocumentCommand{\DoSomething}{m}{%
\str_case:xnF {\str_fold_case:n{#1}}
{
{intermediate1} {Result~1}
{intermediate2} {Result~2}
}
{Unknown~intermediate}
}
\ExplSyntaxOff
\begin{document}
Test1: \ExplSyntaxOn\prop_if_in:NnTF {\MyLookupTable} {key1} {\DoSomething{\prop_item:Nn {\IconNameToUnicodeList} {key1}}} {key1~not~in~list}\ExplSyntaxOff ~However: \DoSomething{intermediate1}
Test2: \ExplSyntaxOn\prop_if_in:NnTF {\MyLookupTable} {key1} {key1~found} {key1~not~in~list}\ExplSyntaxOff ~And: \DoSomething{intermediate1}
Final: \ExplSyntaxOn
\prop_get:NnNTF {\MyLookupTable} {key1} {\answer} {TRUE: \DoSomething{\answer}} {FALSE}
\ExplSyntaxOff
\end{document}
我尝试过\cs_generate_variant:Nn \DoSomething:m {V}
,但是 LaTeX 不喜欢它,而且我对 LaTeX3 结构仍然不太熟悉。
答案1
请使用正确的推荐命名方案。顺便说一句,您的代码中有一个错误的名称。
请注意,x
-expansion 是不可扩展的,但有\str_case_e:nnF
“可扩展的扩展”。
此外,您需要e
扩展传递给的参数\DoSomething
。
\documentclass{article}
%\usepackage{expl3,xparse}
\ExplSyntaxOn
% Create a new sequence.
\prop_clear_new:N \l_tobibs_lookup_prop
\prop_put:Nnn \l_tobibs_lookup_prop {key1} {intermediate1}
\prop_put:Nnn \l_tobibs_lookup_prop {key2} {intermediate2}
\NewExpandableDocumentCommand{\DoSomething}{m}
{
\tobibs_dosomething:e { #1 }
}
\cs_new:Nn \tobibs_dosomething:n
{
\str_case_e:nnF {\str_foldcase:n{#1}}
{
{intermediate1} {Result~1}
{intermediate2} {Result~2}
}
{Unknown~intermediate}
}
\cs_generate_variant:Nn \tobibs_dosomething:n { e }
\ExplSyntaxOff
\begin{document}
Test1:
\ExplSyntaxOn
\prop_if_in:NnTF \l_tobibs_lookup_prop {key1}
{\DoSomething{\prop_item:Nn \l_tobibs_lookup_prop {key1}}}
{key1~not~in~list}
\ExplSyntaxOff
However: \DoSomething{intermediate1}
\bigskip
Test2:
\ExplSyntaxOn
\prop_if_in:NnTF \l_tobibs_lookup_prop {key1}
{key1~found}
{key1~not~in~list}
\ExplSyntaxOff
And: \DoSomething{intermediate1}
\bigskip
Final:
\ExplSyntaxOn
\prop_get:NnNTF \l_tobibs_lookup_prop {key1} \answer {TRUE: \DoSomething{\answer}} {FALSE}
\ExplSyntaxOff
\end{document}
避免支撑N
论点(尽管这并不是什么问题)。
注:\str_fold_case:n
应该是\str_foldcase:n
(后者曾是正式名称,但为了与其他名称保持一致而被重新命名)。