How to remove line breaks before and after theorems?

By default, in the amsthm package, when you begin a theorem, LaTeX begins on a new line, and when you end the theorem, it also jumps to a new line. How can you prevent this behavior?

For example, I might want to display something like this.

Example text before theorem. \begin{thm}This is a theorem.\end{thm} Example text after theorem.


In this example, I would like the example text before and after to appear inline with the theorem.

-
it is a design decision that theorems in amsthm start a new line; the styling is roughly equivalent to that of \section. modifying this design to allow a theorem to start in the middle of a line would not be trivial. regarding text following the theorem text, this doesn't fit within the ams design paradigm either, but could be accomplished within the scope of the theorem environment using \textup{...} or {\normalfont\upshape ...}. –  barbara beeton Oct 16 '12 at 17:09

You could define your own shortthm environment:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsthm}% http://ctan.org/pkg/amsthm
\newtheorem{thm}{Theorem}
\makeatletter
\newenvironment{shortthm}
{\enskip\refstepcounter{thm}\textbf{Theorem~\thethm.\space}\itshape}% \begin{shortthm}
{\enskip}% \end{shortthm}
\makeatother
\begin{document}
\lipsum[1]
\begin{thm}
This is a theorem
\end{thm}
\lipsum[2]
Example text before theorem. \begin{shortthm}This is a theorem.\end{shortthm} Example text after theorem.
\end{document}​


Note that this usage might be confusing to readings, since there is no clear distinction between the theorem body and body text - provided by default when using the line break of amsthm.

The above shortthm is very crude, but could be extended to form part of the creation when issuing \newtheorem{<theorem>}{<title>}. Also, it could also be made a macro, but I kept it in an environment form. The preceding and following text is separated by \enskip; assuming of course that you're not starting a paragraph with it. However, that can also be modified.

-