0

Have written the command teora that prints with the colour defined in \pigm. Could \teora be changed to accept the colour as an optional parameter? \newtheorem already accepts an optional theorem naming parameter, and most likley that I cannot have multiple optional parameters. But I am not sure.

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

How can a user change the colour for \pigm so that one can have a different colour when calling \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}

There is the possibility of doing \begin{teora}[\color{Green}Pythagorean theorem] but this only changes the name, with the theorem numbering keeping with the old colour.

1 Answer 1

1

You might use an optional argument in parentheses, so as not to conflict with the standard optional argument for the name.

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

enter image description here

12
  • Could I build it without \usepackage{amsthm}?
    – Veak
    Sep 29, 2022 at 22:59
  • With \newcommand{\pigm}{Green} in a style file, is there a way for users to change the value of \pigm to another taken from xcolor?
    – Veak
    Sep 29, 2022 at 23:06
  • \NewDocumentEnvironment is a latex built-in that is not associated with amsthm, right?
    – Veak
    Sep 29, 2022 at 23:16
  • @konmi I always use amsthm because it adds punctuation, but is not necessary for the job. You can use \pigm instead of the teora color, if you so prefer, but is it a sensible name?
    – egreg
    Sep 30, 2022 at 8:00
  • I have no problem using the colour you defined.
    – Veak
    Sep 30, 2022 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .