Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction between saveto and newly introduced redirectlowerto #249

Closed
muzimuzhi opened this issue Sep 27, 2023 · 3 comments
Closed

Interaction between saveto and newly introduced redirectlowerto #249

muzimuzhi opened this issue Sep 27, 2023 · 3 comments
Assignees

Comments

@muzimuzhi
Copy link
Contributor

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 (4918308) is not.

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

  • a warning about saveto and savelowerto is thrown

    Package tcolorbox Warning: 'saveto' and 'savelowerto' cannot be combined. I deactivate 'savelowerto' on input line 22.

  • its savelowerto and no lower part typesetting features are deactivated
  • its lowerbox=ignored feature is retained.
\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
Copy link
Contributor Author

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)

\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
Copy link
Owner

T-F-S commented Sep 28, 2023

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

@T-F-S T-F-S self-assigned this Sep 28, 2023
@T-F-S
Copy link
Owner

T-F-S commented Jan 10, 2024

@T-F-S T-F-S closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants