具有可选参数的彩色定理

具有可选参数的彩色定理

teora已经编写了使用 中定义的颜色进行打印的命令\pigm。是否可以\teora更改为接受颜色作为可选参数? \newtheorem已经接受可选的定理命名参数,并且很可能我不能有多个可选参数。但我不确定。

\newcommand{\pigm}{Green}
\newtheorem{teora}{\color{\pigm}Theorem}[section]

用户如何改变颜色,\pigm以便在呼叫时可以使用不同的颜色\teora

\begin{teora}[Pythagorean theorem]
  To prove it by contradiction try and assume that the statement is
  false, proceed from there and at some point you will arrive to a
  contradiction.
\end{teora}

有这样做的可能性\begin{teora}[\color{Green}Pythagorean theorem],但这只是改变名称,定理编号保留旧的颜色。

答案1

您可以在括号中使用可选参数,以免与名称的标准可选参数冲突。

\documentclass{article}
\usepackage{xcolor}
\usepackage{amsthm}

\newcommand{\teoracolor}{}% initialize
\newtheorem{teorainner}{\color{\teoracolor}Theorem}[section]
\NewDocumentEnvironment{teora}{D(){teora}}
 {\renewcommand{\teoracolor}{#1}\teorainner}
 {\endteorainner}

\colorlet{teora}{green!80!blue}

\begin{document}

\section{Title}

\begin{teora}
This theorem is green, with no name.
\end{teora}

\begin{teora}[Name]
This theorem is green, with a name.
\end{teora}

\begin{teora}(red!80)
This theorem is red, with no name.
\end{teora}

\begin{teora}(red!80)[Name]
This theorem is red, with a name.
\end{teora}

\end{document}

在此处输入图片描述

相关内容