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

`capture=<mode>` added to `every box` style has no effect #246

Closed muzimuzhi closed 9 months ago

muzimuzhi commented 9 months ago

For tcolorbox environment, in \tcb@@icolorbox

For \tcbox and \tcboxfit, similar capture mode overwriting happen in \tcb@ox, where its #1, a comma-separated style list starting with capture=hbox|fitbox, is applied after \tcb@layer@inc.

This is a long-existing behavior, so long that it's reproducible with Overleaf's TeX Live 2014 mirror. If classified as a feature, only documentation refinement is needed.

\documentclass{article}
\usepackage{tcolorbox}

\tcbset{
  every box/.append style={
    capture=hbox
  }
}

\def\tcbEveryBoxCaptureModeTests{
  \begin{tcolorbox}
    Use \texttt{hbox} from \texttt{every box}
  \end{tcolorbox}

  \begin{tcolorbox}[hbox]
    Set \texttt{hbox} per box
  \end{tcolorbox}
}

\begin{document}

\subsection*{Before}
\tcbEveryBoxCaptureModeTests

% set "capture=<mode>" _before_ applying "every box on layer <n>"/"every box on higher layers"
% tcolorbox part only
\makeatletter
\long\def\tcb@@icolorbox[#1]{%
  \tcbset{capture=minipage}% or pass "capture=<mode>" to \tcb@layer@inc
  \tcb@layer@inc%
  \tcb@apply@box@options{#1}\tcb@height@adjust%
  \tcb@hasLowerfalse%
  \csname tcb@@capture@\kvtcb@capture\endcsname%
}
\makeatother

\subsection*{After \textnormal{(for display only, not really a proposal)}}
\tcbEveryBoxCaptureModeTests
\end{document}

image

T-F-S commented 9 months ago

I think the current behavior is not especially intended. I am not sure, if a global every box setting of a capture mode is a good idea, and, maybe, therefore I paid not attention to such a possibility until now.

Nevertheless, changing the code as you have proposed should do no harm to existing documents. So, I will do this (and also for \tcb@ox) for the next version.

muzimuzhi commented 9 months ago

I am not sure, if a global every box setting of a capture mode is a good idea

May be only handy in small document for testing. :)

T-F-S commented 9 months ago

Done with https://github.com/T-F-S/tcolorbox/releases/tag/v6.1.0