[Tex/LaTex] Theorem style with name as argument

amsthmtheorems

Is there some way to get a theorem type which will make a theorem with the name passed as a parameter? In other words, is there a way to define "named" such that

\begin{named}[NAME]
text
\end{named}

will print

"NAME: text"?

I tried using the definition \newtheorem*{named}{}, but that results in

"(NAME): text", which is quite different from what I am trying to do.

I know that I could also create a new instance of \newtheorem for each named theorem I want to use, but that is clunky and inconvenient. Is there a better way?

Best Answer

Here's one possible solution using thmtools as a front-end for amsthm:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{lipsum}

\declaretheoremstyle[
spaceabove=\topsep, spacebelow=\topsep,
headfont=\normalfont\bfseries,
notefont=\bfseries, notebraces={}{},
bodyfont=\normalfont\itshape,
postheadspace=0.5em,
name={\ignorespaces},
numbered=no,
headpunct=:]
{mystyle}
\declaretheorem[style=mystyle]{named}

\begin{document}

\begin{named}[NAME]
\lipsum[4]
\end{named}

\begin{named}[OTHERNAME]
\lipsum[4]
\end{named}

\end{document}

enter image description here

And without using thmtools, you can say something like:

\documentclass{article}
\usepackage{amsthm}
\usepackage{lipsum}

\makeatletter
\newtheoremstyle{mystyle}%
{\topsep}{\topsep}
{\itshape}{}
{\bfseries}{:}
{0.5em}
{\thmname{\@ifempty{#3}{#1}\@ifnotempty{#3}{\MakeUppercase{#3}}}}
\makeatother

\theoremstyle{mystyle}
\newtheorem*{named}{NAME}% here the second argument is the default name

\begin{document}

\begin{named}
\lipsum[4]
\end{named}

\begin{named}[Othername]
\lipsum[4]
\end{named}

\end{document}

enter image description here

With the second approach, you can set the default name for the structure in the second argument of \newtheorem*.