2

I create one global clist and assign 4, 300 as the two elements to it. \clist_count:N shows its 2 elements. If I copy this clist to a local list the contents of the new list are identical but \clist_count:N shows only 1 element. Why is that?

\documentclass{scrlttr2}

\ExplSyntaxOn

\clist_clear_new:N \g__timelist_median_clist

\clist_new:N \l__timelist_median_clist

\NewDocumentCommand{\setlist}{m}
{
    \clist_gset:Nn \g__timelist_median_clist { #1 }
}

\NewDocumentCommand{\showlist}{}
{
    % set a comma separated list
    \clist_set:Nn \l__timelist_median_clist { \g__timelist_median_clist }
    
    g__timelist_median_clist:\ \clist_use:Nn \g__timelist_median_clist {,}\\
    count:\ \clist_count:N \g__timelist_median_clist\\
    
    l__timelist_median_clist:\ \clist_use:Nn \l__timelist_median_clist {,}\\
    count:\ \clist_count:N \l__timelist_median_clist\\
}

\ExplSyntaxOff

\begin{document}
    \setlist{4,300}
    \showlist
\end{document}
10
  • Use \clist_show:N\l__timelist_median_clist to inspect your clist. May 5, 2023 at 21:06
  • @UlrikeFischer: What would that change? Then the list is no longer showing in my document... Supposedly it will show up in the terminal which I cannot find in TeXstudio... But again: what will that change or show? May 5, 2023 at 21:12
  • 1
    you do not copy the list you make new 1-item list May 5, 2023 at 21:13
  • @mrCarnivore !!!!!! how do you manage to program anything in tex without constant access to the log and terminal?????? May 5, 2023 at 21:14
  • sorry but if you really want to program you will have to learn to read the log and the terminal. expl3 has lots of helper commands that show you the current state of variables. May 5, 2023 at 21:16

1 Answer 1

4

add debugging messages:

\documentclass{scrlttr2}

\ExplSyntaxOn

\clist_clear_new:N \g__timelist_median_clist

\clist_new:N \l__timelist_median_clist

\NewDocumentCommand{\setlist}{m}
{
    \clist_gset:Nn \g__timelist_median_clist { #1 }
}

\NewDocumentCommand{\showlist}{}
{
    % set a comma separated list
    \clist_set:Nn \l__timelist_median_clist { \g__timelist_median_clist }
    
    g__timelist_median_clist:\ \clist_use:Nn \g__timelist_median_clist {,}\\
    count:\ \clist_count:N \g__timelist_median_clist\\
    
    l__timelist_median_clist:\ \clist_use:Nn \l__timelist_median_clist {,}\\
    count:\ \clist_count:N \l__timelist_median_clist\\

\clist_show:N\l__timelist_median_clist
\clist_show:N\g__timelist_median_clist
}

\ExplSyntaxOff

\begin{document}
    \setlist{4,300}
    \showlist
\end{document}

you then see

The comma list \l__timelist_median_clist contains the items (without outer
braces):
>  {\g__timelist_median_clist }.

and

The comma list \g__timelist_median_clist contains the items (without outer
braces):
>  {4}
>  {300}.

as \clist_set:Nn \l__timelist_median_clist { \g__timelist_median_clist } does not copy the 2 element list, it makes a new 1-item list consisting of the csname token for the global list.

you want \clist_set_eq:NN

3
  • I now see the contents you mention in the log. I was not aware that the log is the terminal. Also there seem to be two different settings of logs in teXstudio: one that only shows very few messages and another that shows the whole log file which you have to skim for the terminal messages. Thank you for helping me! May 5, 2023 at 21:28
  • But where are the real line numbers of the problems? Or is that really hidden? May 5, 2023 at 21:29
  • @mrCarnivore the log has more information than the terminal, it is terminal output I showed there. texstudio's "summary" is worse than useless, I didn't show the line number above but in both cases it was logged as l.33 \showlist ie the message was triggered by \showlist on line 33 May 5, 2023 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .