1

I have a large textbook written and I wish to add color boxes around my theorems, lemmas, etc without changing my main text too much. Currently, each theorem environment is defined in the usual way, e.g.,

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem*{proposition*}{Proposition}

To add color boxes, I could of course use tcolorbox as in this answer. My problem is that tcolorbox's theorems are defined like

\begin{theorem}{theorem name}{reference}

whereas my 1000-page textbook define theorems using

\begin{theorem}{theorem name}\label{reference}

So my question is:

Is there any way of getting around this. I.e., redefining the theorem-environment so that I would still be able to reference theorems using the usual \label{reference}?

Many thanks in advance!

2
  • Which editor are you using? If you use an editor capable to search and replace with regex, I would go this route. Hacks on a 1000-page document are not recommended, although Ignassi's solution will work, I would rather fix the manuscript. I use Sublime 3
    – yannisl
    Commented Feb 11, 2022 at 11:14
  • I would prefer to keep the main text as it is. (My coauthor does not like this boxed theorem format)
    – wnx
    Commented Feb 11, 2022 at 11:55

1 Answer 1

3

If you accept to rename your theorems to something different, you can use tcolorboxenvironment to change theorems aspect and keep previous labeling mechanism.

\documentclass{article}

\usepackage[skins]{tcolorbox}
\usepackage{amsmath, amsthm}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem*{proposition*}{Proposition}

\newenvironment{mytheorem}{\begin{theorem}}{\end{theorem}}

\tcolorboxenvironment{mytheorem}{colback=blue!30, colframe=blue!70!black}

\begin{document}

\section{One}

\begin{mytheorem}{One theorem}\label{OneTheorem}
some words
\end{mytheorem}

Reference to theorem~\ref{OneTheorem}

\end{document}

enter image description here

Update: muzimuzhi's simpler solution

it seems that any previous existing environment can be tcbcolorized, we don't need to rename it as I did in original answer.

\documentclass{article}

\usepackage[skins]{tcolorbox}
\usepackage{amsmath, amsthm}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem*{proposition*}{Proposition}

%\newenvironment{mytheorem}{\begin{theorem}}{\end{theorem}}

\tcolorboxenvironment{theorem}{colback=blue!30, colframe=blue!70!black}

\begin{document}

\section{One}

\begin{theorem}{One theorem}\label{OneTheorem}
some words
\end{theorem}

Reference to theorem~\ref{OneTheorem}

\end{document}

enter image description here

8
  • Thanks for your input! It would be ideal if I could keep the main text intact and keep the format "\begin{theorem}\label{}". Is there any chance of making this work?
    – wnx
    Commented Feb 11, 2022 at 11:52
  • @wnx I'm sorry but I don't know how to do it.
    – Ignasi
    Commented Feb 11, 2022 at 15:15
  • Ok, thank you anyway for taking the time to think about it - I appreciate it!
    – wnx
    Commented Feb 11, 2022 at 20:05
  • @wnx In any case you can try to make a new question showing my proposal and asking how to avoid changing the names.
    – Ignasi
    Commented Feb 11, 2022 at 20:46
  • Seems to be just \tcolorboxenvironment{theorem}{colback=blue!30, colframe=blue!70!black}. Commented Feb 25, 2022 at 5:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .