I have a prop list
in which I save items using the \addtoprop
command and then loop through the prop list
and print it with the
\foreachinprop
command. The \foreachinprop
command has several
keys, but the wrapper
key does not work as it should (does nothing).
\documentclass{article}
\ExplSyntaxOn
% Add to prop
\tl_new:N \l__prop_list_name_tl
\NewDocumentCommand \addtoprop { m +m }
{
\tl_set:Nn \l__prop_list_name_tl {#1}
\prop_if_exist:cF { g_ \l__prop_list_name_tl _prop }
{ \prop_new:c { g_ \l__prop_list_name_tl _prop } }
\prop_gput_if_not_in:cen { g_ \l__prop_list_name_tl _prop }
{
\int_eval:n
{ \prop_count:c { g_ \l__prop_list_name_tl _prop } + 1 }
}{ #2 }
}
% foreach
\seq_new:N \l__foreach_print_seq
\tl_new:N \l__foreach_name_prop_tl
\tl_new:N \g__foreach_temp_tl
\keys_define:nn { foreach }
{
before .tl_set:N = \l__foreach_before_tl,
after .tl_set:N = \l__foreach_after_tl,
start .int_set:N = \l__foreach_start_int,
start .initial:n = 1,
stop .int_set:N = \l__foreach_stop_int,
step .int_set:N = \l__foreach_step_int,
step .initial:n = 1,
wrapper .cs_set_protected:Np = \__foreach_wrapper:n #1,
wrapper .initial:n = {#1},
sep .tl_set:N = \l__foreach_sep_tl,
sep .initial:n = {},
}
\NewDocumentCommand \foreachinprop { o m }
{
\__foreach_code:nn {#1} {#2}
}
\cs_new_protected:Npn \__foreach_code:nn #1 #2
{
\group_begin:
\tl_if_novalue:nF {#1}
{
\keys_set:nn { foreach } {#1}
}
\tl_set:Nn \l__foreach_name_prop_tl {#2}
\seq_clear:N \l__foreach_print_seq
\int_compare:nNnT { \l__foreach_stop_int } = { 0 }
{
\int_set:Nn \l__foreach_stop_int
{ \prop_count:c { g_ \l__foreach_name_prop_tl _prop } }
}
\int_step_function:nnnN
{ \l__foreach_start_int }
{ \l__foreach_step_int }
{ \l__foreach_stop_int }
\__foreach_prop:n
\tl_gset:Ne \g__foreach_temp_tl
{
\exp_args:NNV \seq_use:Nn
\l__foreach_print_seq \l__foreach_sep_tl
}
\group_end:
\exp_after:wN \tl_gclear:N
\exp_after:wN \g__foreach_temp_tl \g__foreach_temp_tl
}
\cs_new_protected:Npn \__foreach_prop:n #1
{
\seq_put_right:Ne \l__foreach_print_seq
{
\tl_if_empty:NF \l__foreach_before_tl
{ \exp_not:V \l__foreach_before_tl }
% wrapper
\__foreach_wrapper:n
{
\prop_item:cn { g_ \l__foreach_name_prop_tl _prop }{#1}
}
\tl_if_empty:NF \l__foreach_after_tl
{ \exp_not:V \l__foreach_after_tl }
}
}
\ExplSyntaxOff
\begin{document}
\addtoprop{test}{The first} \addtoprop{test}{The second}
\addtoprop{test}{The third} \addtoprop{test}{The fourth}
\foreachinprop[sep={\\}, before=FOO, after= BAZZ]{test} % OK
\foreachinprop[wrapper={\fbox{#1}}]{test} % NOT WORK
\end{document}
What should I modify so that the \__foreach_wrapper:n
function works properly?
\g_test_prop
isn't a good idea.