T-F-S / tcolorbox

A LaTeX package to create highly customizable colored boxes.
http://www.ctan.org/pkg/tcolorbox
LaTeX Project Public License v1.3c
213 stars 15 forks source link

/tcb/ams align in a tcolorbox with lower part throws errors #282

Open hafid68 opened 1 week ago

hafid68 commented 1 week ago

the following snippet throws errors

\documentclass{article}
\usepackage[theorems]{tcolorbox}
\begin{document}
\begin{tcolorbox}[ams align]
\alpha&=\beta\\
\theta&=\gamma
\tcblower 
a&=b\\
c&=d
\end{tcolorbox}
\end{document}
muzimuzhi commented 1 week ago

I doubt this (ams align + \tcblower) ever worked. None of overleaf's images, from texlive 2014 to texlive 2024 complied your example.

align and several other amsmath displayed equation environments need to collect the content of environment. Thus with ams align or ams align upper, the whole content of current tcolorbox environment, not just the upper part, would be collected (by the \align inserted at beginning of upper part), which when typeset, will raise errors if \tcblower is included.

Example below patches an amsmath internal macro to show what's collected.

\documentclass{article}
\usepackage[theorems]{tcolorbox}

\makeatletter
% amsmath.sty v2.17q, 2024/05/23, line 1413:
\def\addto@envbody#1{%
  % added debugging error
  \PackageError{debug}{collect: \detokenize{#1}}{}%
  \global\@envbody\@xp{\the\@envbody#1}}
\makeatother

\begin{document}

\begin{tcolorbox}[ams align upper]
  \alpha &= \beta \\
  \theta &= \gamma
\tcblower
  abc
\end{tcolorbox}
\end{document}

which raises an debugging error

! Package debug Error: collect:  \alpha &= \beta \\ \theta &= \gamma \tcblower 
abc .
T-F-S commented 1 week ago

I doubt this (ams align + \tcblower) ever worked. None of overleaf's images, from texlive 2014 to texlive 2024 complied your example.

I think that is true. The example was supposed to work like expected, but never did. Years ago I had the plan to fix it somehow or the adapt the documentation, but then it dimmed away with other things to do ...

I should adapt the documentation for ams align and friends, maybe even change the code of ams align to be an alias for ams align upper only, to prevent users to find out what works and what works not themselves.

Of course, you can have align for both the upper and the lower part, if you change the example code. The following shows working environments. The last two are variants to achieve the desired goal:

\documentclass{article}
\usepackage[theorems]{tcolorbox}

\begin{document}

\begin{tcolorbox}[ams align,title=Upper only with 'ams align']
  \alpha &= \beta \\
  \theta &= \gamma
\end{tcolorbox}

\begin{tcolorbox}[ams align upper,title=Upper only with 'ams align upper']
  \alpha &= \beta \\
  \theta &= \gamma
\end{tcolorbox}

\begin{tcolorbox}[ams align lower,title='ams align lower']
  abc
\tcblower
  \alpha &= \beta \\
  \theta &= \gamma
\end{tcolorbox}

\begin{tcolorbox}[ams nodisplayskip upper,ams align lower,title=Upper and lower variant 1]
\begin{align}
  \alpha &= \beta \\
  \theta &= \gamma
\end{align}
\tcblower
  abc
\end{tcolorbox}

\begin{tcolorbox}[ams nodisplayskip,title=Upper and lower variant 2]
\begin{align}
  \alpha &= \beta \\
  \theta &= \gamma
\end{align}
\tcblower
\begin{align}
  abc
\end{align}
\end{tcolorbox}

\end{document}

grafik

T-F-S commented 1 week ago

grafik

The same goes for ams align*, ams gather, and ams gather*.