3

There is the proof environment in the amsmath package. If I want to globally set the text color inside the proof environment, I can use the command

\AtBeginEnvironment{proof}{\color{blue}}

as illustrated in Change Color of Proof.

However, suppose that I want to change the color inside the proof only sometimes. There may be two (or more) options to achieve this.

Option 1: Define two environments proof and blueproof, where proof is the usual environment and blueproof is a custom-made environment that is a copy of the proof except that the color inside the proof is blue.

Option 2: Put appropriate options inside the proof, for example,

\begin{proof}[here my options to change the color]
...
\end{proof}

Either option is fine for me. How can I make the proof color blue when necessary?

Edit: Sadly, the below answer does not work.

Running the provided code, I instead obtain:

enter image description here

with error messages that Undefined control sequence. \begin{Proof}[blue], etc.

Laplacian
  • 960
  • amsmath doesn't define any proof environment;, but amsthm does. But you haven't said what theorem package you are using, if any. So this question can't be answered without more information. Please supply a small compilable example, beginning with \documentclass and ending with \end{document}, that shows what you've tried. – barbara beeton Aug 30 '22 at 15:49

1 Answers1

4

I suggest going to a new environment, because the optional argument is already reserved for an alternative header.

\documentclass{article}
\usepackage{amsthm}

\ExplSyntaxOn

\NewDocumentEnvironment{Proof}{O{}} { \color_group_begin: \keys_set:nn { eigenvalue/proof } { #1 } \tl_if_empty:VF \l__eigenvalue_proof_color_tl { \color_select:V \l__eigenvalue_proof_color_tl } \tl_if_empty:VTF \l__eigenvalue_proof_name_tl { \proof } { \proof[\l__eigenvalue_proof_name_tl] } } { \color_group_end: \endproof }

\keys_define:nn { eigenvalue/proof } { color .tl_set:N = \l__eigenvalue_proof_color_tl, name .tl_set:N = \l__eigenvalue_proof_name_tl, }

\cs_generate_variant:Nn \color_select:n { V }

\ExplSyntaxOff

\begin{document}

\begin{Proof} This is a proof. \end{Proof}

\begin{Proof}[name=Proof of the main theorem] This is a proof. \end{Proof}

\begin{Proof}[color=blue!70] This is a proof. \end{Proof}

\begin{Proof}[name=Proof of the main theorem,color=red!60!blue] This is a proof. \end{Proof}

\end{document}

enter image description here

You may also define shorter keys, for instance blue to stand for color=blue!70 (it's best to never use pure colors).

\documentclass{article}
\usepackage{amsthm}

\ExplSyntaxOn

\NewDocumentEnvironment{Proof}{O{}} { \color_group_begin: \keys_set:nn { eigenvalue/proof } { #1 } \tl_if_empty:VF \l__eigenvalue_proof_color_tl { \color_select:V \l__eigenvalue_proof_color_tl } \tl_if_empty:VTF \l__eigenvalue_proof_name_tl { \proof } { \proof[\l__eigenvalue_proof_name_tl] } } { \color_group_end: \endproof }

\keys_define:nn { eigenvalue/proof } { color .tl_set:N = \l__eigenvalue_proof_color_tl, name .tl_set:N = \l__eigenvalue_proof_name_tl, blue .meta:n = { color = blue!70 }, }

\cs_generate_variant:Nn \color_select:n { V }

\ExplSyntaxOff

\begin{document}

\begin{Proof} This is a proof. \end{Proof}

\begin{Proof}[name=Proof of the main theorem] This is a proof. \end{Proof}

\begin{Proof}[color=blue!70] This is a proof. \end{Proof}

\begin{Proof}[blue] This is a proof. \end{Proof}

\begin{Proof}[name=Proof of the main theorem,color=red!60!blue] This is a proof. \end{Proof}

\end{document}

enter image description here

If you want to color also the tombstone

\documentclass{article}
\usepackage{amsthm}

\ExplSyntaxOn

\NewDocumentEnvironment{Proof}{O{}} { \keys_set:nn { eigenvalue/proof } { #1 } \tl_if_empty:VF \l__eigenvalue_proof_color_tl { \cs_set:Npx \qedsymbol { \color_select:V \exp_not:N \l__eigenvalue_proof_color_tl \exp_not:o { \qedsymbol } } } \color_group_begin: \tl_if_empty:VF \l__eigenvalue_proof_color_tl { \color_select:V \l__eigenvalue_proof_color_tl } \tl_if_empty:VTF \l__eigenvalue_proof_name_tl { \proof } { \proof[\l__eigenvalue_proof_name_tl] } } { \color_group_end: \endproof }

\keys_define:nn { eigenvalue/proof } { color .tl_set:N = \l__eigenvalue_proof_color_tl, name .tl_set:N = \l__eigenvalue_proof_name_tl, blue .meta:n = { color = blue!70 }, }

\cs_generate_variant:Nn \color_select:n { V }

\ExplSyntaxOff

\begin{document}

\begin{Proof} This is a proof. \end{Proof}

\begin{Proof}[name=Proof of the main theorem] This is a proof. \end{Proof}

\begin{Proof}[color=blue!70] This is a proof. \end{Proof}

\begin{Proof}[blue] This is a proof. \end{Proof}

\begin{Proof}[name=Proof of the main theorem,color=red!60!blue] This is a proof. \end{Proof}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks a lot for your answer, but sadly your code does not work on my environment (see my edited post). Is there any requirement for your code to run? – Laplacian Sep 01 '22 at 00:50
  • @eigenvalue Update your TeX system. Please, show also the error messages you get. – egreg Sep 01 '22 at 08:16