Open lvjr opened 2 years ago
From a comment of Phelype Oleinik
@pddzaic There's not really a bug to fix.
l3regex
uses toks registers to do its job, but there are only 65535 of those available in LuaTeX (half that amount in other engines) so you are facing a limitation of the engine.
we know that the LaTeX team doesn't consider it a bug of l3regex
, so we need to rewrite some code in tabularray
to make huge tables work.
From the code we see
\cs_new_protected:Npn \__tblr_split_table_to_lines:NN #1 #2
{
\__tblr_insert_braces:N #1
\seq_set_split:NnV \l_tmpa_seq { \\ } #1
...
}
I assume \seq_set_split
doesn't depend on l3regex
. So the real problem is \__tblr_insert_braces
:
\regex_const:Nn \c__tblr_insert_braces_regex
{
\c{begin} \cB\{ (\c[^BE].*) \cE\} (.*?) \c{end} \cB\{ (\c[^BE].*) \cE\}
}
\tl_const:Nn \c__tblr_insert_braces_tl
{
\c{begin} \cB\{ \cB\{ \1 \cE\} \2 \c{end} \cE\} \cB\{ \3 \cE\}
}
\cs_new_protected:Npn \__tblr_insert_braces:N #1
{
\regex_replace_all:NVN \c__tblr_insert_braces_regex \c__tblr_insert_braces_tl #1
\regex_replace_all:NVN \c__tblr_insert_braces_regex \c__tblr_insert_braces_tl #1
}
The code dates back to the first commit of tabularray.sty
, because we need to protect nesting subtables before splitting a table into rows by \\
.
(this just popped up in a recent TeX.SE question https://tex.stackexchange.com/questions/686028/how-to-solve-longtblr-error-bad-register-code-32768 )
Because l3regex is powerful it's also slow (which is extra worse because of TeX), but for this task -- assume you only need to replacing \begin
/\end
at top level with \begin{
and \end}
correspondingly I think the easiest way (and also takes linear time) is to
\begin
/\end
tokens at top level and assert that they're equal (otherwise step 3 below will give low-level TeX error)\tl_replace_all
to replace them with something like \specialmarker \specialmarkerbegin
and \specialmarker \specialmarkerend
{
and }
respectively.I am considering to solve this problem and \\ [abc]
problem (see https://github.com/lvjr/tabularray/discussions/321) at the same time.
Discussed in https://github.com/lvjr/tabularray/discussions/149