-
Notifications
You must be signed in to change notification settings - Fork 16
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
Don't define \tcbcounter
in \newtcolorbox[auto counter]...
#203
Comments
I just took a quick glance and - as always - your proposal sounds reasonable to me. The next days I'm very busy, but I will look into it with more time next week. |
I examined the matter and came to the conclusion that this proposal cannot be taken over as I thought at first glance.
Nevertheless, I tried to do some replacements of |
Oh I didn't know it's a documented/in-use feature until just now. Then as a last resort appending \documentclass{article}
\usepackage{tcolorbox}
\usepackage{shortvrb} \MakeShortVerb\|
\makeatletter
\pretocmd\tcb@proc@counter@autoanduse
{\let\tcb@tcbcounter@temp=\tcbcounter}
{}{\PatchFailed}
\apptocmd\tcb@proc@counter@autoanduse
{\let\tcbcounter=\tcb@tcbcounter@temp}
{}{\PatchFailed}
\makeatother
\def\tcbcounter{init}
\def\thetcbcounter{the init}
\newtcolorbox[auto counter, number within=section,
number freestyle={(Q/\noexpand\thesection/\noexpand\Alph{\tcbcounter})}
]{phbox}[2][]{
colback=yellow!15!white,
colframe=blue!75!black,
fonttitle=\bfseries,
title=Question~\thetcbcounter: #2,#1
}
\begin{document}
\ttfamily
\meaning\tcbcounter \par
\meaning\thetcbcounter
\normalfont
\section{title}
\begin{phbox}[label={myfreestyle}]{Title with freestyle number}
This box is automatically numbered with \ref{myfreestyle} on page\pageref{myfreestyle}. Inside the box, the \thetcbcounter\ canalso be referenced by |\thetcbcounter|.The real counter name is \texttt{\tcbcounter}.
\end{phbox}
\end{document} |
I will do that for the next version. |
Ideally, box counter wrappers
\tcbcounter
and\thetcbcounter
should only be (re)defined locally in a tcolorbox.But when
auto counter
oruse counter=<counter>
is used,\tcbcounter
is defined and used as a temp macro in\tcb@proc@counter@autoanduse
. Hence after a\newtcolorbox[auto counter]...
,\tcbcounter
is always defined while\thetcbcounter
is untouched.This inconsistency misled me, see my answer to this TeX-SX question, revision 4. I first found
\thetcbcounter
undefined, then tried\tcbcounter
. The fact that it's defined by\newtcolorbox
and holds the last counter name happen to work for minimal example which contains only one\newtcolorbox
.It would be better to not use
\tcbcounter
as a temp macro, but either use another (standard) temp macro or just compose the counter name and pass it to\tcb@proc@counter@autoanduse
. This will not only help others not to make the same mistakes I did, but also allow different global definitions of\tcbcounter
and\thetcbcounter
(though not recommended).Proposal
I find in all the
\tcb@proc@counter@xxx
(actual macros\tcb@proc@counter
will be let to), its#1
is used either astcb@cnt@#1
orthetcb@cnt@#1
as a whole. Therefore in the following proposal,\tcb@proc@options@init
,\tcb@proc@counter{#2}
is changed to\tcb@proc@counter{tcb@cnt@#2}
,\tcb@proc@counter@newanduse
,\letcs\tcbcounter{tcb@cnt@#1}
is removed and\tcbcounter
is replaced by#1
where its value is used in place, and\tcb@proc@counter@xxx
variants,tcb@cnt@#1
andthetcb@cnt@#1
are changed to#1
andthe#1
, respectively.GitHub's comparing page provides a cleaner
git diff
result (sth like--word-diff
), see master...muzimuzhi:tcolorbox:dont-define-tcbcounter.I have a feeling that the maintainer may want to rewrite these in LaTeX3. 😄
Full git diff
The text was updated successfully, but these errors were encountered: