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.)

1
  • 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
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

3
  • Thanks your answer.(and so fast reply) I use gpop beause used \int_do_while for pop items. I will append full work fine code. Thanks again.
    – sppmg
    Jan 30 '18 at 16:04
  • Sorry, forget a question, the 1st column work because \clist_gpop in the same cell , right ?
    – sppmg
    Jan 30 '18 at 16:24
  • @sppmg Yes, that's right
    – egreg
    Jan 30 '18 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.