Tabularray 有时会在 amsmath 中聚集错误

Tabularray 有时会在 amsmath 中聚集错误

在我的新 texlive 发行版(Ubuntu 20.04 上的 vanilla texlive 2021)上,tabularray 有时在 gather(来自 amsmath)中不起作用。例如

\begin{gather*}
 \begin{tblr}{l}
  a \\ b
 \end{tblr}
\end{gather*}

确实有效,但是

\begin{gather*}
 \begin{tblr}{ll}
  a & b
 \end{tblr}
\end{gather*}

不会。错误消息如下

! Undefined control sequence.
! Argument of \__tl_tl_head:w has an extra }.
<inserted text> 
                \par 
l.758     \end{gather*}
Runaway argument?
! Paragraph ended before \__tl_tl_head:w was complete.
<to be read again> 
                   \par 
l.758     \end{gather*}
! Incomplete \ifx; all text was ignored after line 758.
<inserted text> 
                \fi 
l.758     \end{gather*}
etc.

这是错误吗?需要将其提交到某个地方吗?

如果不是,如何更正我的代码?

答案1

添加大括号。

\documentclass{article}
\usepackage{amsmath,tabularray}

\begin{document}

\begin{gather*}
 \begin{tblr}{l}
  a \\ b
 \end{tblr}
\end{gather*}

\begin{gather*}
 {\begin{tblr}{ll}
  a & b \\
  x+y & u+v
 \end{tblr}}
\end{gather*}

\end{document}

在此处输入图片描述

实际上,这应该被视为中的一个错误tabularray,它应该具有\group_align_safe_begin:\group_align_safe_end:围绕其对齐。

这是修复方法,请注意不再需要括号。

\documentclass{article}
\usepackage{amsmath,tabularray}

\ExplSyntaxOn
\cs_set_protected:Npn \__tblr_environ_code:nnnn #1 #2 #3 #4
  {
    \group_align_safe_begin:               % <---- added
    \int_gincr:N \g__tblr_table_count_int
    \tl_set:Nn \l__tblr_env_name_tl {#1}
    \mode_if_math:TF
      { \bool_set_true:N \l__tblr_math_mode_bool }
      { \bool_set_false:N \l__tblr_math_mode_bool }
    \__tblr_builder:nnn {#2} {#3} {#4}
    \group_align_safe_end:                 % <---- added
  }
\ExplSyntaxOff

\begin{document}

\begin{gather*}
 \begin{tblr}{l}
  a \\ b
 \end{tblr}
\end{gather*}

\begin{gather*}
 \begin{tblr}{ll}
  a & b \\
  x+y & u+v
 \end{tblr}
\end{gather*}

\end{document}

相关内容