Obviously, the \seq_set_split:Nnn
function allows the delimiter to be used explicitly; for example the statement \seq_set_split:Nnn \Args_seq {,} {x,y,z}
will put x
, y
and z
into the first three locations in \Args_seq
.
Or, wrapping this functionality into a \NewDocumentCommand
the delimiter can be passed as a parameter, see for example \myMacroA
in the MWE below, where in \seq_set_split:Nnn \Args_seq #2 {#1}
parameter #1
is split into \Args_seq
using the delimiter specified in parameter #2
.
However, in one of my gizmos I wanted to pop delimiters off a stack (implemented by an L3seq
of course), store them in a _tl
type variable and then use that variable in the \seq_set_split
function. All attempts failed miserably; the \myMacroB_Main
control sequence below illustrates the point. What type of variable does the delimiter require?
Much obliged, as usual.
\documentclass{minimal}
% --------------------
\usepackage[check-declarations]{expl3}
\usepackage{xparse}
\usepackage{amsmath}
% --------------------
\ExplSyntaxOn
% VARIABLE DECLARATIONS:
\seq_new:N \Args_seq
\int_new:N \ItemCount_int
\int_new:N \index_i
\tl_new:N \aux_tl
\tl_new:N \sep_tl
% --------------------
\NewDocumentCommand\myMacroA{O{}O{,}}{\myMacroA_Main:nn {#1}{#2}}
\cs_new:Npn \myMacroA_Main:nn #1 #2
{
\seq_clear:N \Args_seq
\seq_set_split:Nnn \Args_seq #2 {#1}
\myShowArgs{\Args_seq}
}
\NewDocumentCommand\myMacroB{O{}O{,}}{\myMacroB_Main:nn {#1}{#2}}
\cs_new:Npn \myMacroB_Main:nn #1 #2
{
\seq_clear:N \Args_seq
\tl_set:Nn \sep_tl {#2}
\seq_set_split:Nnn \Args_seq \sep_tl {#1} %does not accept the delimiter as a _tl variable.
\myShowArgs{\Args_seq}
}
\cs_new:Npn \myShowArgs #1
{
\tl_clear:N \aux_tl
\int_set:Nn \ItemCount_int {\seq_count:N #1}
\int_set:Nn \index_i {1}
\int_do_until:nNnn \index_i > \ItemCount_int
{
\tl_set:Nx \aux_tl {\seq_item:Nn #1 {\index_i}}
\tl_use:N \aux_tl \text{~}
\int_incr:N \index_i
}
}
\ExplSyntaxOff
\begin{document}
1. \verb+\myMacroA[a,b,c,1,2,3]+\\
\myMacroA[a,b,c,1,2,3]
2. \verb+\myMacroA[1;2;3;a;b;c][;]+\\
\myMacroA[1;2;3;a;b;c][;]
3. \verb+\myMacroB[a,b,c,1,2,3]+\\
\myMacroB[a,b,c,1,2,3]
4. \verb+\myMacroB[1;2;3;a;b;c][;]+\\
\myMacroB[1;2;3;a;b;c][;]
\end{document}
expl3
'compliance': do you details? BTW, is there a reason that\myMacroA/B
don't take the list as a mandatory argument and don't have the 'truly' optional argument first?\myMacroA
and\myMacroB
? Both split a string into its parts, don't they?