tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

The first cell of a `tblr` tabular cannot start with a square bracket

Open dbitouze opened this issue 7 months ago • 1 comments

The first cell of a tblr tabular cannot start with a square bracket:

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{}
  [a]
\end{tblr}
\end{document}

leads to:

! Missing number, treated as zero.
<to be read again> 
                   a
l.6 \end
        {tblr}

And that's worse with:

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{}
  [a
\end{tblr}
\end{document}

which triggers the following low level error:

Runaway argument?
a\q_stop \tl_if_empty:NF \l__tblr_saved_table_commands_before_cell_text_tl \ETC
.
! File ended while scanning use of \__tblr_extract_table_command_arg_o:w.
<inserted text> 
                \par 
<*> test-tabularray.tex

dbitouze avatar May 29 '25 21:05 dbitouze

To support usages \\* and \\[<dimen>], after splitting table content into rows at \\, tblr then detects * and [ at the beginning of each row.

IMHO such detection (and the following removal) should be skipped for the first row.

\documentclass{article}
\usepackage{tabularray}

\makeatletter
\ExplSyntaxOn
\cs_undefine:N \__tblr_split_table_to_lines:NN

%% Split table content to a sequence of lines
%% #1: tl with table contents, #2: resulting sequence of lines
\cs_new_protected:Npn \__tblr_split_table_to_lines:NN #1 #2
  {
    \__tblr_seq_set_split_keep_braces_envs:NnV \l_tmpa_seq { \\ } #1
    \seq_clear:N #2
    \seq_pop_left:NNT \l_tmpa_seq \l__tblr_a_tl
      {
        % skip detection for "*" and "[" for the 1st row (issue #598)
        \seq_put_right:NV #2 \l__tblr_a_tl
        % apply normal detection for following rows
        \seq_map_inline:Nn \l_tmpa_seq
          {
            \tl_if_head_eq_meaning:nNTF {##1} *
              {
                \tl_set:Nn \l__tblr_b_tl { \hborder { pagebreak = no } }
                \tl_set:Ne \l__tblr_c_tl { \tl_tail:n {##1} }
                \tl_trim_spaces:N \l__tblr_c_tl %% Ignore spaces between * and [dimen]
                \tl_if_head_eq_meaning:VNT \l__tblr_c_tl [
                  {
                    \tl_put_right:Nn \l__tblr_b_tl { \RowBefore@AddBelowSep }
                  }
                \tl_put_right:NV \l__tblr_b_tl \l__tblr_c_tl
                \seq_put_right:NV #2 \l__tblr_b_tl
              }
              {
                \tl_if_head_eq_meaning:nNTF { ##1 } [
                  { \seq_put_right:Nn #2 { \RowBefore@AddBelowSep ##1 } }
                  { \seq_put_right:Nn #2 { ##1 } }
              }
          }
      }
    \int_set:Nn \c@rowcount { \seq_count:N #2 }
  }
\ExplSyntaxOff
\makeatother

\begin{document}

\begin{tblr}{}
  [a]
\end{tblr}

\begin{tblr}{}
  *
\end{tblr}
\end{document}

muzimuzhi avatar Jun 03 '25 20:06 muzimuzhi

Thank you. Fixed.

lvjr avatar Sep 02 '25 12:09 lvjr