% Fix the various theorem-like environments so that the optional comment
% can be broken across lines to avoid horrible problems in twocolumn mode.

% Apparently, this also fixes the problem where
% ``\begin{theorem}\begin{enumerate}\item ...'' does not put a line break
% before the first item.

% First, fix the one from LaTeX2e.

% Modified from \@opargbegintheorem from "ltthm.dtx"
% [1995/10/10 v1.0f LaTeX Kernel (Theorems)]
%
\def\@opargbegintheorem#1#2#3{\trivlist
      \item[\hskip \labelsep{\bfseries #1\ #2}]%
      {\bfseries(#3)\penalty-100\ \penalty-100}\itshape}
%
% Original definition was:
%
%   \def\@opargbegintheorem#1#2#3{\trivlist
%         \item[\hskip \labelsep{\bfseries #1\ #2\ (#3)}]\itshape}

% Second, fix the one from the "amsthm" package.

% Here, we need two different fixes, depending on the version.  One
% version (amsthm.dtx 1.2a 1995/02/01) uses \theoremXXX for XXX in
% {headfont, indent, headpunct, notefont}.  The other version
% (amsthm.dtx 1.2d 1996/10/29) uses \thm@XXX.
\@ifundefined{theoremheadfont}{%
  \def\theoremheadfont{\thm@headfont}
  \def\theoremindent{\thm@indent}
  \def\theoremheadpunct{\thm@headpunct}
  \def\theoremnotefont{\thm@notefont}
}{\relax}

% Modified from "amsthm.dtx" version 1.2a.
\def\thmhead@plain#1#2{%
  \thmname{#1}\thmnumber{ #2}%
  % old:
  %   \thmnote{ {\the\theoremnotefont(#3)}}
}
\let\thmhead\thmhead@plain
\def\swappedhead#1#2{%
  \thmnumber{#2}\thmname{. #1}%
  % old:
  %   \thmnote{ {\the\theoremnotefont(#3)}}
}
\def\@begintheorem#1#2[#3]{%
  % new: moved these outside the optional argument to \item.
  \@ifempty{#1}{\let\thmname\@gobble}{\let\thmname\@iden}%
  \@ifempty{#2}{\let\thmnumber\@gobble}{\let\thmnumber\@iden}%
  \@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
  \item[\normalfont % reset in case body font is abnormal
  \hskip\labelsep
  \the\theoremheadfont
  \theoremindent
  % old: The above \@ifempty tests used to be here.
  \thm@swap\swappedhead\thmhead{#1}{#2}%
  % old:
  %   \the\theoremheadpunct
  % new:
  \@ifempty{#3}{\the\theoremheadpunct}{}%
  ]%
  % new:
  \thmnote{{\normalfont
            \the\theoremheadfont
            { }{\the\theoremnotefont(#3)}%
            \the\theoremheadpunct}}%
  % new: added a space:
  { }%
  \thmheadnl % possibly a newline.
  \ignorespaces
}
