2

I try to make a clist to table function. It's work fine in first column, but second column disappear.

Below is MWE (I removed loop part.):

\documentclass[12pt]{article}
\usepackage{expl3}
\ExplSyntaxOn

\begin{document}
    \clist_new:N \l_my_cl
    \clist_set:Nn \l_my_cl {A,B,C,D}
    \begin{tabular}{|c|c|}
        \hline
        \clist_gpop:NN \l_my_cl \l_tmpa_tl
        \l_tmpa_tl & ``\l_tmpa_tl'' \\ \hline
    \end{tabular}
\ExplSyntaxOff
\end{document}

And output :

enter image description here

Why ?? And how to fix ? Thanks.

update

Thanks egreg. This is finally code:

\documentclass[12pt]{article}
\usepackage{expl3}
\ExplSyntaxOn

\begin{document}
    \clist_new:N \g_sppmg_my_cl
    \clist_gset:Nn \g_sppmg_my_cl {}

    \int_compare:nNnTF {\clist_count:N \g_sppmg_my_cl} > {0}{
        \begin{tabular}{|c|c|}
            \hline
            \clist_gpop:NN \g_sppmg_my_cl \l_tmpa_tl
            \tl_gset_eq:NN \g_tmpa_tl \l_tmpa_tl     % copy to global var
            1st. \g_tmpa_tl & ``\g_tmpa_tl'' \\ \hline

            \int_while_do:nNnn {\clist_count:N \g_sppmg_my_cl} > {0} {
                \clist_gpop:NN \g_sppmg_my_cl \l_tmpa_tl
                \tl_gset_eq:NN \g_tmpa_tl \l_tmpa_tl
                other : \g_tmpa_tl &  ``\g_tmpa_tl'' \\ \hline
            }
        \end{tabular}
    }{}
\ExplSyntaxOff
\end{document}

output: enter image description here

For \g_tmpa_tl in the first column, I think I can use \g_tmpa_tl replace \l_tmpa_tl in egreg's example.( Actually, it is not necessary in my case.)

sppmg
  • 73
  • 1
    The token list is set in a cell, that forms a group; gpop only acts globally on the sequence, but the assignment to the token list variable is local. – egreg Jan 30 '18 at 15:44

1 Answers1

5

The function \clist_gpop:NN only acts globally on the clist, but the assignment to the token list variable is local.

Don't mix global and local assignments.

\documentclass[12pt]{article}
\usepackage{expl3}
\ExplSyntaxOn

\begin{document}
\clist_new:N \g_sppmg_my_cl
\clist_gset:Nn \g_sppmg_my_cl {A,B,C,D}

\begin{tabular}{|c|c|}
\hline
\clist_gpop:NN \g_sppmg_my_cl \l_tmpa_tl
\tl_gset_eq:NN \g_tmpa_tl \l_tmpa_tl
\l_tmpa_tl & ``\g_tmpa_tl'' \\
\hline
\end{tabular}
\ExplSyntaxOff

\end{document}

enter image description here

egreg
  • 1,121,712