lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
247 stars 22 forks source link

+cases does not work in align #314

Closed Firestar-Reimu closed 2 months ago

Firestar-Reimu commented 1 year ago

This is good

\documentclass{article}
\usepackage{amsmath}

\begin{document}
    \begin{align}
        a_n
        &= (-1)^n \\
        &=
        \begin{cases}
            1, & n\ \text{is even} \\
            -1, & n\ \text{is odd}
        \end{cases}
    \end{align}
\end{document}

This is bad

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

\begin{document}
    \begin{align}
        a_n
        &= (-1)^n \\
        &=
        \begin{+cases}
            1, & n\ \text{is even} \\
            -1, & n\ \text{is odd}
        \end{+cases}
    \end{align}
\end{document}
Extra }, or forgotten $.
<recently read> }
\begin{align} on input line 7 ended by \end{+cases}.
Misplaced alignment tab character &.
\@tempa ->\endgroup &&
...
Sophanatprime commented 1 year ago

Not only is the +cases, but those +matrix environments.

One can simply redefine them by using \RenewDocumentEnvironment (and its friends, in ltcmd or its old name xparse), such as:

\DeclareDocumentEnvironment{+cases}{+O{}b}
  {%
    \left\lbrace\begin{+array}{
      column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
      colspec = {ll}, stretch = 1.2, #1
    }#2%
    \end{+array}\right.%
  }
  {}

Maybe it is the environ package that causes this problem (I'm not pretty sure).

lvjr commented 1 year ago

Actually, the latest source code of tabularray doesn't use environ package.

antshar commented 2 months ago

Any updates on this?

UPD: nvm, apparently I'm using an old version where these environments are defined via \NewEnv which messes up \\. Redefining environments with xparse solves the problem. In newer versions of tabularray it's already the case, so it's fixed there and the issue can be closed.

muzimuzhi commented 2 months ago

Duplicate of #143