[Tex/LaTex] Change background color across different environments

colorenvironmentstcolorboxtheorems

I have a long .tex document and I want to change the background color of the parts I have already checked for typos to a light green. I am looking for an easy command that can be used like

\HIGHLIGHT{

<here I want to put a part of my tex file that contains different environments like theorems, figures...>

}

But the \hl{} command cannot contain other environments, the following example does not work:

\documentclass[10pt]{article}         
\usepackage[english]{babel}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{xcolor,soul}

\newtheorem{theorem}{Theorem}
\begin{document}
\section{Introduction}
\hl{
    \begin{theorem}
    A theorem.
    \end{theorem}
}
\end{document}

Do you have any suggestions which command could be used here (the typesetting shall not be changed, only the color)?

Best Answer

As suggested in one of my comments to the question, I would use tcolorbox and its \newtcbtheorem macros, having two basically identical environments, where one uses the checkedstyle and the other one the uncheckedstyle. If a theorem is not checked yet, use \begin{uctheorem}...\end{uctheorem} and edit it later to \begin{theorem}...\end{theorem} or just remove the colback={green!50!white} statement from the definition of uncheckedstyle.

In the very end, a search-and-replace of all uctheorem occurrences by theorem would be the best way, in my point of view, but that is a matter of taste, of course.

Another option is to use a 'real' tcolorbox environment which allows local specification of options, which is not possible with the tcbtheorem environments.

\documentclass[10pt]{article}         
\usepackage[english]{babel}
\usepackage{amssymb,amsmath,amsthm,amsfonts}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{%
  checkedstyle/.style={breakable,enhanced, sharp corners,colback={yellow!50!white}},
  uncheckedstyle/.style={checkedstyle,colback={green!50!white}}
}

\newtcbtheorem{theorem}{Theorem}{checkedstyle}{theo}

\newtcbtheorem{uctheorem}{Theorem}{uncheckedstyle}{theo}




\begin{document}
\section{Introduction}
\begin{theorem}{My theorem}{foo}
  A theorem.
\end{theorem}

\begin{uctheorem}{My other theorem}{foobar}
  An unchecked theorem
\end{uctheorem}

\end{document}

enter image description here