仅当我需要时,校样环境中才会出现不同的颜色

仅当我需要时,校样环境中才会出现不同的颜色

proof包中有环境amsmath。如果我想全局设置proof环境内的文本颜色,我可以使用命令

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

如图所示改变校样颜色

但是,假设我想改变校样里面的颜色只是有时。可能有两个(或更多)选项可以实现此目的。

选项 1:定义两个环境proofblueproof,其中proof是通常的环境,blueproof是定制的环境,它是的副本proof,只是校样内部的颜色为蓝色。

选项 2:在证明中放入适当的选项,例如,

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

对我来说两种选择都可以。如何在必要时将校样颜色设为蓝色?

编辑:遗憾的是,以下答案不起作用。

运行提供的代码,我得到:

在此处输入图片描述

带有错误消息Undefined control sequence. \begin{Proof}[blue],等等。

答案1

我建议去一个新的环境,因为可选参数已经为备用标题保留。

\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}

在此处输入图片描述

您还可以定义更短的键,例如blue代表color=blue!70(最好不要使用纯色)。

\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}

在此处输入图片描述

如果你还想给墓碑上色

\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}

在此处输入图片描述

相关内容