parentesi graffa extra quando si usa \csname in \clist_set:No
clist non è impostato correttamente con \cs_if_exist_use:c
o \csname ... \endcsname
, sembra che ci siano parentesi graffe extra. Se uso \clist_set:Nx
, si verifica un errore.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\expandafter\def\csname test-1\endcsname{a,$\alpha\dotsb$,b}
\ExplSyntaxOn
\clist_new:N \l_test_clist
\NewDocumentCommand {\test} {}
{
\clist_set:No \l_test_clist {\cs_if_exist_use:c {test-1}}
\clist_use:Nn \l_test_clist {*}
}
\ExplSyntaxOff
\begin{document}
\test
\end{document}
Risposte
Prima di tutto, dovrebbe essere usato con a , non a (funziona perché la loro implementazione sembra essere simile, ma non puoi fare affidamento su questo). Inoltre, a meno che non sia documentato che una funzione si espanda completamente in n passaggi, non hai alcuna garanzia che si espanda in n passaggi e, in tal caso, potrebbe cambiare alla fine (ad esempio e sono documentati per espandersi in due passaggi, quindi puoi fare affidamento su quello).\cs_if_exist_use:c
cs
clist
\char_generate:nn
\prg_replicate:nn
Per ottenere ciò che desideri puoi utilizzare x
un'espansione su \clist_if_exist:cT
, quindi proteggere il valore dell'espansione clist
dall'espansione utilizzando \exp_not:v
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\expandafter\def\csname test-1\endcsname{a,$\alpha\dotsb$,b}
\ExplSyntaxOn
\clist_new:N \l_test_clist
\NewDocumentCommand {\test} {}
{
\clist_set:Nx \l_test_clist
{
\clist_if_exist:cT {test-1}
{ \exp_not:v { test-1 } }
}
\clist_use:Nn \l_test_clist {*}
}
\ExplSyntaxOff
\begin{document}
\test
\end{document}
La o
variante eseguirà un singolo passaggio di espansione. Hai bisogno di molto di più per arrivare alla Clist.
Se vuoi usare nomi simbolici per le clist, fallo in un modo più appropriato. Non dovresti contare su \def\zzz{a,b,c}
di essere un "vero" expl3
clist.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\defineclist}{mm}
{
\clist_clear_new:c { l__zhiyuanlck_#1_clist }
\clist_set:cn { l__zhiyuanlck_#1_clist } { #2 }
}
\NewDocumentCommand {\test} {m}
{
\clist_if_exist:cTF { l__zhiyuanlck_#1_clist }
{
\clist_use:cn { l__zhiyuanlck_#1_clist } {*}
}
{OOPS}
}
\ExplSyntaxOff
\defineclist{test-1}{a,$\alpha\dotsb$,b}
\begin{document}
\test{test-1}
\test{test-2}
\end{document}
