15

I am wondering how to create a new theorem environment / style which allows me to insert the theorem number manually. That is, I am imagining something like

 \begin{newtheorem}{2.3'}[title]
      This is a theorem.
 \end{newtheorem}

to translate into

Theorem 2.3' (title). This is a theorem.

As a second example,

 \begin{newtheorem}{A}[title]
      This is a theorem.
 \end{newtheorem}

should give

Theorem A (title). This is a theorem.

How would one be able to define such a theorem environment with argument which is (apart from the manual insertion of the "number") identical to the usual theorem environment?

Note, if I add a \label to a theorem of this type, I would like the corresponding \ref command to print the theorem number defined in the argument. That is, in the above example \ref should print 2.3'.

I would be grateful for any help with this! Many thanks in advance!

3 Answers 3

25

Quite easy! ;-) 1

\documentclass{article}
\usepackage{amsthm}

\newtheorem{manualtheoreminner}{Theorem}
\newenvironment{manualtheorem}[1]{%
  \renewcommand\themanualtheoreminner{#1}%
  \manualtheoreminner
}{\endmanualtheoreminner}

\begin{document}

\begin{manualtheorem}{2.3'}[title]\label{foo}
This is a theorem.
\end{manualtheorem}

\begin{manualtheorem}{A}[title]\label{baz}
This is a theorem.
\end{manualtheorem}

Here is \ref{foo} and \ref{baz}.

\end{document}

enter image description here


1 Been there, done that.

6
  • Pronto, prontissimo... mamma mia! :)
    – Ruben
    Sep 14, 2017 at 22:06
  • @Ruben Son come il fulmine :-D
    – egreg
    Sep 14, 2017 at 22:08
  • prime would be better than apostrophe. (just being pedantic.) Sep 15, 2017 at 2:56
  • 1
    @barbarabeeton That's left to the OP to decide.
    – egreg
    Sep 15, 2017 at 8:06
  • Note: does not work with cleveref out of the box.
    – Bach
    Dec 15, 2019 at 4:01
4

First of all, you can't define a theorem-like environment newtheorem as there is alredy the \newtheorem macro that defines those environments simply due to the name clash. Assume we have an environment theorem. Then you can locally change \thetheorem:

\documentclass{article}
\usepackage{amsmath,amsthm}
  \newtheorem{theorem}{Theorem}

\begin{document}
\begingroup
\renewcommand\thetheorem{2.3'}
\begin{theorem}[title]
  This is a theorem.
\end{theorem}
\endgroup
\end{document}

When wrapping this into an own environment you don't need to group explicitly as the \begin and \end definitions take care of this:

\newenvironment{Apollo13theorem}[1]{%
  \renewcommand\thetheorem{#1}
  \theorem
}{\endtheorem}

The custom environment would then be used as requested by the OP:

\begin{Apollo13theorem}{A}[title]
  This is a theorem.
\end{Apollo13theorem}

examples

1

A version using \NewDocumentEnvironment:

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\NewDocumentEnvironment{mytheorem}{m}%
  {\renewcommand{\thetheorem}{$\mathbf{#1}$}%
   \begin{theorem}
  }%
  {\end{theorem}}
\begin{document}

\begin{mytheorem}{2.3'}[note]\label{foo}
  This is a theorem.
\end{mytheorem}

\begin{mytheorem}{A}[note]\label{baz}
  This is a theorem.
\end{mytheorem}

\ref{foo} and \ref{baz}.

\end{document}

enter image description here

You must log in to answer this question.

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