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

More meaningful error message in case of \Declare(d)TColorBox(es) with same name and both with auto counter #276

Closed
dbitouze opened this issue Apr 2, 2024 · 3 comments
Assignees

Comments

@dbitouze
Copy link
Contributor

dbitouze commented Apr 2, 2024

The following MCE:

\documentclass{article}
\usepackage{tcolorbox}
\DeclareTColorBox[auto counter]{pabox}{}{}
\DeclareTColorBox[auto counter]{pabox}{}{}
\begin{document}
\end{document}

fails to compile with the following cryptic message:

! LaTeX Error: Command \c@tcb@cnt@pabox already defined.
Or name \end... illegal, see p.192 of the manual.

Maybe it is worth to provide a more meaningful message in such a case.

@muzimuzhi
Copy link
Contributor

The error was raised by \newcounter{<conter name>} on an existing <counter name>. Not sure if it's feasible for LaTeX2e to make that general message more specific for counters.

Possible patch on tcolorbox side

\documentclass{article}
\usepackage{tcolorbox}

\makeatletter
\def\tcb@proc@counter@auto#1{%
  %% begin patch
  \ifcsdef{c@tcb@cnt@#1}
    {\tcb@error{Auto counter for environment '#1' already defined}{}}
    {}%
  %% end patch
  \newcounter{tcb@cnt@#1}%
  \csxdef{tcb@cnt@#1}{tcb@cnt@#1}%
  \tcb@proc@counter@autoanduse{#1}%
}
\makeatother

\DeclareTColorBox[auto counter]{pabox}{}{}
\DeclareTColorBox[auto counter]{pabox}{}{}
\begin{document}
\end{document}

Now compile it will throw two errors

! Package tcolorbox Error: Auto counter for environment 'pabox' already defined
.

! LaTeX Error: Command \c@tcb@cnt@pabox already defined.
               Or name \end... illegal, see p.192 of the manual.

@T-F-S
Copy link
Owner

T-F-S commented Apr 8, 2024

I think this is a useful patch and I will add it to the next version. Thank you.

@T-F-S T-F-S self-assigned this Apr 8, 2024
@T-F-S
Copy link
Owner

T-F-S commented Jul 10, 2024

@T-F-S T-F-S closed this as completed Jul 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

3 participants