I have two sequences: \l_words_seq containing: { dans, [DP, la, maison, ]foc } and \l_glosses_seq containing: { in, the, house }. I would like to create another sequence \l_final_seq from \l_glosses_seq that inserts the items from \l_words_seq matching the regex ^(\[(DP|NP)|\]\w* ) at the corresponding positions. The result should be { in, [DP, the, house, ]foc }

\int_new:N \l_counter_glosses_int

\seq_const_from_clist:Nn \l_words_seq {dans, [DP, la, maison, ]foc}
\seq_const_from_clist:Nn \l_glosses_seq {in, the, house}

\seq_new:N \l_final_seq

\int_zero:N \l_counter_glosses_int

\seq_map_inline:Nn \l_words_seq  {
    \regex_match:nnTF {^(\[(DP|NP)|\]\w* )} { #1 } 
    { \seq_put_right:Nn \l_final_seq {#1} }             
        \int_incr:N  \l_counter_glosses_int 
        \seq_put_right:No \l_final_seq { \seq_item:Nn  \l_glosses_seq  {\int_use:N \l_counter_glosses_int}} 

\seq_map_inline:Nn \l_final_seq  {  #1~ }

But my result is

house [DP house house ]foc

How could I fix this? I tried \seq_put_right:No but it only works when I append the integer and not the item corresponding to that integer.

  • 4
    always show a small but complete example. That makes testing easier. And please stick to the naming scheme, there should always be a module prefix in the variable and command names, so e.g. \l_words_seq should be \l_jupiterjones_words_seq Commented Feb 6 at 11:18
  • Thank you for your quick response :) Could you please elaborate on how my example isn't small enough or not complete so that I can make more efficient posts in the future? What should my example have looked like instead? And I'll definitely take your advice on the naming scheme since I haven't given naming variables much thought. Commented Feb 6 at 12:07
  • 2
    There should be a full document that I can copy & paste in my editor and compile directly. Commented Feb 6 at 12:58

1 Answer 1


The solution is to use \seq_put_right:Ne (or Nx) instead, to fully expand the inserted item before adding it to the sequence.

The o type performs a single expansion, which isn't enough where you are trying to get an item from a sequence by an index that is itself stored in a variable.

Using e type (or x type) will expand the item, including the integer value, which will give you the expected results.


\int_new:N \l_mymodule_glosses_int

\seq_const_from_clist:Nn \l_mymodule_words_seq {dans, [DP, la, maison, ]foc}
\seq_const_from_clist:Nn \l_mymodule_glosses_seq {in, the, house}

\seq_new:N \l_mymodule_final_seq

\int_zero:N \l_mymodule_glosses_int

\seq_map_inline:Nn \l_mymodule_words_seq  {
    \regex_match:nnTF {^(\[(DP|NP)|\]\w*)} { #1 } 
    { \seq_put_right:Nn \l_mymodule_final_seq {#1} }             
        \int_incr:N  \l_mymodule_glosses_int 
        \seq_put_right:Ne \l_mymodule_final_seq { \seq_item:Nn  \l_mymodule_glosses_seq  {\l_mymodule_glosses_int}}

\seq_use:Nn \l_mymodule_final_seq { ~ }

I have replaced the last part by \seq_use:Nn instead of using inline mapping.

Alternatively, you can use \seq_pop:NN to pop the value from the sequence to a token list. Then, o type expansion (or V, which is preferred over o) will work fine to expand the token list variable.

\seq_pop:NN \l_mymodule_glosses_seq \l_tmpa_tl
\seq_put_right:NV \l_mymodule_final_seq \l_tmpa_tl
  • is there a reason you are using x and not just e?
    – daleif
    Commented Feb 6 at 13:33
  • @daleif No. Using e expansion will work fine in this example.
    – JSLee
    Commented Feb 6 at 13:38
  • 2
    I think the Expl3 team is suggesting using e and only use x then really needed.
    – daleif
    Commented Feb 6 at 13:40
  • I didn't know that. I actually preferred x over e for no reason. Thanks for pointing out anyway.
    – JSLee
    Commented Feb 6 at 13:50
  • @JSLee Thank you for your answer and also thank you guys for the comments. I'll need to read up on this concept of expansion. Commented Feb 6 at 14:12

You must log in to answer this question.

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