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

Interaction between `saveto` and newly introduced `redirectlowerto` #249

Closed muzimuzhi closed 6 months ago

muzimuzhi commented 9 months ago

The interaction between saveto and savelowerto is well documented and handled in code base, but the interaction between saveto and redirectlowerto which was newly introduced in v6.1.0 (https://github.com/T-F-S/tcolorbox/commit/4918308ef96e482e4ee0f1343e6fe8c96984bf71) is not.

Currently in v6.1.0, if redirectlowerto is used along with saveto,

\documentclass{article}
\usepackage{tcolorbox}

\begin{document}
\setcounter{enumi}{1}
Test counter: \theenumi

\begin{tcolorbox}[saveto=\jobname_mysave1, savelowerto=\jobname_mysave2,
  title={\texttt{saveto} and \texttt{savelowerto}}]
  upper part
  \tcblower
  lower part \stepcounter{enumi}
\end{tcolorbox}
New value of test counter: \theenumi.

\IfFileExists{\jobname_mysave1}
  {\verbatiminput*{\jobname_mysave1}}
  {non-existent}
\IfFileExists{\jobname_mysave2}{}{\texttt{savelowerto} file doesn't exist.}

\begin{tcolorbox}[saveto=\jobname_mysave3, redirectlowerto=\jobname_mysave4,
  title={\texttt{saveto} and \texttt{redirectlowerto}}]
  upper part 2
  \tcblower
  lower part 2 \stepcounter{enumi}
\end{tcolorbox}
New value of test counter: \theenumi.

\IfFileExists{\jobname_mysave3}
  {\verbatiminput*{\jobname_mysave3}}
  {non-existent}
\IfFileExists{\jobname_mysave4}{}{\texttt{redirectlowerto} file doesn't exist.}
\end{document}

image

muzimuzhi commented 9 months ago

Assuming the current behavior is expected (except for the warning message), below is an attempt for better warning message(s). Documentation still need adaptions.

BTW, although it can be inferred from key descriptions "no default, initially empty", that an empty <file name> passed to one of saveto, savelowerto, and redirectlowerto will deactivate (or partially deactivate, for the last one) the effect of corresponding option, do users need a direct statement like "An empty <file name> deactivates ... ."?

Example patching \tcb@set@@upper@and@lower to give better warning message(s)

```tex \documentclass{article} \usepackage{tcolorbox} \usepackage{xpatch} \makeatletter \xpatchcmd\tcb@set@@upper@and@lower {% \ifx\kvtcb@savelowerto\@empty% \else% \tcb@warning{'saveto' and 'savelowerto' cannot be combined. I deactivate 'savelowerto'}% \tcbset{savelowerto=}% \fi% } {% \ifx\kvtcb@savelowerto\@empty% \else% \iftcb@redirectlowerto% \tcb@warning{% 'saveto' and 'redirectlowerto' cannot be combined.\MessageBreak I deactivate 'redirectlowerto' but retain its\MessageBreak 'lowerbox' setting}% \tcb@redirectlowertofalse% \tcbset{savelowerto=}% \else% \tcb@warning{% 'saveto' and 'savelowerto' cannot be combined.\MessageBreak I deactivate 'savelowerto'}% \tcbset{savelowerto=}% \fi% \fi% } {}{\PatchFailed} \makeatother \begin{document} \setcounter{enumi}{1} Test counter: \theenumi \begin{tcolorbox}[saveto=\jobname_mysave1, savelowerto=\jobname_mysave2, title={\texttt{saveto} and \texttt{savelowerto}}] upper part \tcblower lower part \stepcounter{enumi} \end{tcolorbox} New value of test counter: \theenumi. \IfFileExists{\jobname_mysave1} {\verbatiminput*{\jobname_mysave1}} {non-existent} \IfFileExists{\jobname_mysave2}{}{\texttt{savelowerto} file doesn't exist.} \begin{tcolorbox}[saveto=\jobname_mysave3, redirectlowerto=\jobname_mysave4, title={\texttt{saveto} and \texttt{redirectlowerto}}] upper part 2 \tcblower lower part 2 \stepcounter{enumi} \end{tcolorbox} New value of test counter: \theenumi. \IfFileExists{\jobname_mysave3} {\verbatiminput*{\jobname_mysave3}} {non-existent} \IfFileExists{\jobname_mysave4}{}{\texttt{redirectlowerto} file doesn't exist.} \end{document} ```

PDF output is the same as before, and the new warning message is

Package tcolorbox Warning: 'saveto' and 'redirectlowerto' cannot be combined.
(tcolorbox)                I deactivate 'redirectlowerto' but retain its
(tcolorbox)                'lowerbox' setting on input line 54.
T-F-S commented 9 months ago

OK, I will update the warning code and also add additional documentation for the next version. Thank you.

T-F-S commented 6 months ago

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