proof
包中有环境amsmath
。如果我想全局设置proof
环境内的文本颜色,我可以使用命令
\AtBeginEnvironment{proof}{\color{blue}}
如图所示改变校样颜色。
但是,假设我想改变校样里面的颜色只是有时。可能有两个(或更多)选项可以实现此目的。
选项 1:定义两个环境proof
和blueproof
,其中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}