3

When the following LaTeX code:

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{}0&1&2&3\end{tblr}
\end{document}

is compiled in Overleaf using the 2022 LuaLaTeX engine, the following output is produced: 0 1 2 3.

However, if the table is constructed piecemeal in an expl3 token list, as follows:

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\ExplSyntaxOn
\tl_new:N\mytl
\tl_set:Nn\mytl{\begin{tblr}{}}
\tl_put_right:Nx\mytl{0\int_step_inline:nnn{1}{3}{&#1}}
\tl_put_right:Nn\mytl{\end{tblr}}
\mytl
\ExplSyntaxOff
\end{document}

the following error message results:

\__int_map_4:w #1->&
                    #1
l.9 \mytl
       
I can't figure out why you would want to use a tab mark
here.

Why did the expl3 program fail? How can I correct it?

4
  • tblr needs to see an explicit & and `\` in the input stream.
    – Udi Fogiel
    Feb 9, 2023 at 22:16
  • @UdiFogiel Why doesn't it see it, then?
    – Evan Aad
    Feb 9, 2023 at 22:18
  • 3
    move the int_step to the outside: \int_step_inline:nnn{1}{3}{ \tl_put_right:Nn\mytl{0&#1}} Feb 9, 2023 at 22:22
  • 1
    the function \int_step_inline:nnn is protected, thus not getting expanded.
    – Udi Fogiel
    Feb 9, 2023 at 23:08

1 Answer 1

5

There are two problems with the line \tl_put_right:Nx\mytl{0\int_step_inline:nnn{1}{3}{&#1}}. The first one is that when using nested macro definitions you must double the number of # tokens for each level of nesting (see this post).

Changing \tl_put_right:Nx\mytl{0\int_step_inline:nnn{1}{3}{&#1}} to \tl_put_right:Nx\mytl{0\int_step_inline:nnn{1}{3}{&##1}} still won't solve the problem. Consider the following code

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\ExplSyntaxOn
\tl_new:N\mytl
\tl_set:Nn\mytl{\begin{tblr}{}}
\tl_put_right:Nx\mytl{0\int_step_inline:nnn{1}{3}{&#1}}
\tl_put_right:Nn\mytl{\end{tblr}}
\tl_log:N\mytl
\ExplSyntaxOff
\end{document}

Take a look at the log file after compiling this file and you will see the line > \mytl=\begin {tblr}{}0\int_step_inline:nnn {1}{3}{&##1}\end {tblr}.. As we can see the function \int_step_inline:nnn did not get expanded (because it is protected, write in your document \ShowCommand\int_step_inline:nnn and check the log file), thus the tblr did not see any explicit & tokens.

Following Ulrike's suggestion you can move the function \int_step_inline:nnn outside

\documentclass{article}
\usepackage{tabularray}
\begin{document}
    \ExplSyntaxOn
    \tl_new:N\mytl
    \tl_set:Nn\mytl{\begin{tblr}{}0}
        \int_step_inline:nnn{1}{3}{ \tl_put_right:Nn\mytl{&#1}}
        \tl_put_right:Nn\mytl{\end{tblr}}
    \mytl
    \ExplSyntaxOff
\end{document}
6
  • Thanks, but I think the diagnosis given in your first paragraph is wrong, since my code did not use nested macro definitions. If that diagnosis were correct, wouldn't it apply also to your last piece of code?
    – Evan Aad
    Feb 9, 2023 at 23:43
  • @EvanAad, the parameter that marked as #1 is of the function \int_step_inline:nnn which is not nested in the last piece of code, but it is in yours.
    – Udi Fogiel
    Feb 9, 2023 at 23:45
  • I fail to see how it is nested in my code but not in yours.
    – Evan Aad
    Feb 9, 2023 at 23:47
  • @EvanAad, In the line \tl_put_right:Nx\mytl{0\int_step_inline:nnn{1}{3}{&#1}} the function \int_step_inline:nnn is inside an argument of the function \tl_put_right. Since both of those functions do some kind of definition assignment, the first parameter argument of \int_step_inline:nnn should be used as ##1. On the other hand, in the line \int_step_inline:nnn{1}{3}{ \tl_put_right:Nn\mytl{&#1}} the function \int_step_inline:nnn is not nested inside any macro definition. When compiling your code, don't you get the error Illegal parameter number in definition of \mytl?
    – Udi Fogiel
    Feb 9, 2023 at 23:51
  • @EvanAad, try to replace only #1 with ##1 in your original code and see that this error message is gone.
    – Udi Fogiel
    Feb 9, 2023 at 23:52

You must log in to answer this question.

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