I'm trying to understand and modify this code:
\newtheorem*{nonamethm}{\nonamethmname}
\newcommand{\nonamethmname}{}
\newenvironment{genthm}[1]
{\renewcommand{\nonamethmname}{#1}\nonamethm}
{\endnonamethm}
\newenvironment{genthm*}[1]
{\renewcommand{\nonamethmname}{#1}\nonamethmcheck}
{\endnonamethm}
\newcommand\nonamethmcheck[1][]{%
\if\relax\detokenize{#1}\relax
\nonamethm\relax
\else
\nonamethm[#1]%
\fi
\mbox{}%
}
It was proposed by @egreg in one of my previous questions. It works perfectly, but I don't understand why and now I'd like to extend its functionality.
With this code I can just write
\begin{genthm}
Theorem statement
\end{genthm}
instead of
\newtheorem{arbitraryname}
\begin{arbitraryname}
Theorem statement
\end{arbitraryname}
I'd like to understand how this code works. As far as I know \relax
effectively does nothing, but I'm having troubles understanding the other pieces. For example, does the %
symbol do anything, or is it just an "empty" comment? What about the empty command \newcommand{\nonamethmname}{}
?
Finally I'd like to know what's the best way to extend the above commands in such a way that I can optionally specify the theorem style. Ideally, I could do
\begin{genthm}{definition}
Definition statement.
\end{genthm}
to avoid having to write \theoremstyle{definition}
. If the second argument is omitted, it should be defaulted to \theoremstyle{plain}
, which is the default.
Is this possible?
\newcommand{\nonamethmname}{}
just provides the empty macro\nonamethmname
, which expands to nothing since it's empty, but it's there such that the compiler does not complain. Your code seems to generate theorem - environment definitions on the fly.xparse
package for optional arguments.