1

I would like to split a multiline content regarding \\ and then split each item regarding . .

Then I would like to iterate over each list in parallel such as to print their items together suchas to print for example a1i b2ii c3iii.

I am trying to pop from the left the first list to read it item by item but this doesn't work... I would like to see a-ok-b-ok-c but I just see a . b . c ... An expansion problem I think...

This question is a simplifcation of the real case of use indicated in this post.

\documentclass{article}

% Source : https://tex.stackexchange.com/a/475291/6880

\RequirePackage{xparse}

\ExplSyntaxOn

%\seq_new:N \l__pmbc_seq % Not useful here.

% #1 : line separator % #2 : cell separator % #3 : content \NewDocumentCommand{\splittab}{m m +m}{ \tnscalc_splittab:nnn{#1}{#2}{#3} }

% The internal version of the general purpose macro \cs_new_protected:Nn \tnscalc_splittab:nnn{ % #1 : line separator % #2 : cell separator % #3 : content

    % A group allows nesting
    \group_begin:
        % Split into parts
        \seq_set_split:Nnn \l__pmbc_seq { #1 } { #3 }

        %\int_zero_new:N \l_mbc_N_int  % Not useful here.
        %\int_set:Nn \l_mbc_N_int { \seq_count:N \l__pmbc_seq }  % Not useful here.
        %
        \seq_pop_left:NN \l__pmbc_seq {\l__temp}

        \seq_set_split:Nnn \l__pmbc_subseq { #2 } { \l__temp }

        \seq_use:Nn \l__pmbc_subseq { -ok- }
    \group_end:
} 

\ExplSyntaxOff

\begin{document} \splittab{\}{.}{ a . b . c \ 1 . 2 . 3 \ i . ii . ii } \end{document}

projetmbc
  • 13,315

1 Answers1

1

Please, use proper naming.

\documentclass{article}

% Source : https://tex.stackexchange.com/a/475291/6880

\usepackage{xparse}

\ExplSyntaxOn

\seq_new:N \l__tnscalc_splittab_seq \seq_new:N \l__tnscalc_subseq_seq \int_new:N \l__tnscalc_splittab_int \tl_new:N \l__tnscalc_temp_tl

% #1 : line separator % #2 : cell separator % #3 : content \NewDocumentCommand{\splittab}{m m +m} { \tnscalc_splittab:nnn{#1}{#2}{#3} }

% The internal version of the general purpose macro \cs_new_protected:Nn \tnscalc_splittab:nnn { % #1 : line separator % #2 : cell separator % #3 : content % A group allows nesting \group_begin: % Split into parts \seq_set_split:Nnn \l__tnscalc_splittab_seq { #1 } { #3 }

\int_set:Nn \l__tnscalc_splittab_int { \seq_count:N \l__tnscalc_splittab_seq } % why? \seq_pop_left:NN \l__tnscalc_splittab_seq \l__tnscalc_temp_tl \seq_set_split:NnV \l__tnscalc_subseq_seq { #2 } \l__tnscalc_temp_tl \seq_use:Nn \l__tnscalc_subseq_seq { -ok- } \group_end: } \ExplSyntaxOff

\begin{document}

\splittab{\}{.}{ a . b . c \ 1 . 2 . 3 \ i . ii . ii }

\end{document}

You need to split the contents of the token list where the popped item has been stored, so the right function is \seq_set_split:NnV.

It's not clear what's the function of the integer variable.

egreg
  • 1,121,712
  • For the integer, it is used in the post for the real use case. I forgot to remove it in my code (I will do it now)... Thanks for the clarification. – projetmbc Aug 11 '20 at 21:33
  • For the integer variable I will use it to print something and I would like to use it to pop all the elements by poping N times. Is there a best way to pop all the elements ? – projetmbc Aug 11 '20 at 21:39
  • @projetmbc I guess you want \seq_map_inline:Nn – egreg Aug 11 '20 at 21:43
  • Indeed I will pop the three lists splitted regarding \ in parallel and then apply a formatting to the poped elements of each line (the number of & is unbounded)... – projetmbc Aug 11 '20 at 21:50
  • I have post a small question about the way I use to iterate on my lists herer : https://tex.stackexchange.com/questions/558347/expl-3-is-there-a-good-way-to-pop-and-act-on-all-the-items-of-a-list . – projetmbc Aug 11 '20 at 22:25