Theorem-like environment with optional title

amsthmenvironmentsspacingtheorems

I'm using the amsthm packages for theorems. I would like to define an environment paragraph which should resemble the look of a theorem environment (definition theoremstyle), but it shouldn't say 1.1 Paragraph.. Instead of Paragraph it should say nothing, or the content of an optional argument. Let me illustrate what I mean:

\begin{definition}
Lorem.
\end{definition}

\begin{paragraph}
Ipsum.
\end{paragraph}

\begin{paragraph}[Optional Title]
Dolor.
\end{paragraph}

This should produce output as follows:

1.1 Definition. Lorem.

1.2. Ipsum

1.3 Optional Title. Dolor.

Getting this done roughly isn't too difficult, but I would like to get it as close to the original theorem environments as possible. So the spacing after 1.2. should be exactly the same as the spacing after 1.1 Definition., and similarly for the space above and below the environments and whatever else subtle things are handled by amsthm, which I might not even recognize. How can this be done?

Best Answer

You want to define your own theorem styles.

\documentclass{article}
\usepackage{amsthm}

\makeatletter
\newtheoremstyle{swapdef}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\upshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {\thmnumber{#2} \thmname{#1}\thmnote{ (#3)}} % CUSTOM-HEAD-SPEC
\newtheoremstyle{para}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\upshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {\thmnumber{#2}\@ifnotempty{#3}{ \thmnote{#3}}} % CUSTOM-HEAD-SPEC
\makeatother

\theoremstyle{swapdef}
\newtheorem{definition}{Definition}[section]
\theoremstyle{para}
\newtheorem{para}[definition]{}

\begin{document}

\section{Test}

\begin{definition}
Lorem.
\end{definition}

\begin{para}
Ipsum.
\end{para}

\begin{para}[Optional Title]
Dolor.
\end{para}

\begin{definition}[Name]
Lorem.
\end{definition}

\end{document}

enter image description here