Hello,

I've converted the amsthm style to the template system. The whole
process was extremely painless (except for reading the AMS code),
and the resulting code is much more readable than the original.

Achim
________________________________________________________________________
                                _                             | \_____/ |
    //  Achim Blumensath       | \  _                        \O/ \___/\ |
   //   [log in to unmask]   |-< /_\                       =o=  \ /\ \|
 \X/    (p^2 - m^2)\psi = 0    |_/ \_                        /"\   o----|
____________________________________________________________________\___|

=== xthm.sty ===

\RequirePackage{xparse}
\RequirePackage{template}
\IgnoreWhiteSpace

\DeclareTemplateType{theoremstyle}{3}

\newdimen\TSpre@skip
\newdimen\TSpost@skip
\newdimen\TShead@indent

\DeclareTemplate{theoremstyle}{AB}{3}
{
  pre-skip    =l  [\DelayEvaluation{\topsep}]  \TSpre@skip,
  post-skip   =l  [\DelayEvaluation{\topsep}]  \TSpost@skip,
  body-style  =f0 [\itshape]                   \TSbody@style,
  head-style  =f0 [\bfseries]                  \TShead@style,
  note-style  =f0 [\normalfont]                \TSnote@style,
  head-punct  =f0 [.]                          \TShead@punct,
  head-format =f3 [\IfNoValueF{#1}{#1\space}
                   \IfNoValueF{#2}{#2}
                   \IfNoValueF{#3}{\space{\TSnote@style(#3)}}]
                                        \TShead@format,
  head-indent      =l  [0pt]            \TShead@indent,
  post-head-action =f0 []               \TSpost@head@action
}
{
  \DoParameterAssignments
  \normalfont
  \trivlist
  \edef\@restorelabelsep{\labelsep\the\labelsep}
  \labelsep.5em\relax
  \let\thmheadnl\relax
  \@topsep\TSpre@skip
  \@topsepadd\TSpost@skip
  \IfNoValueF{#1}
    {\refstepcounter{#1}}
  \item[
    \normalfont
    \hskip\labelsep
    \TShead@style
    \hskip\TShead@indent
    \IfNoValueTF{#1}
      {\TShead@format{#1}{#2}{#3}}
      {\TShead@format{\csname the#1\endcsname}{#2}{#3}}
    \TShead@punct]
  \@restorelabelsep
  \TSpost@head@action
  \TSbody@style
  \ignorespaces
}

\DeclareInstance{theoremstyle}{plain}{AB}{}

\DeclareInstance{theoremstyle}{definition}{AB}
{
  body-style = \normalfont
}

\DeclareInstance{theoremstyle}{remark}{AB}
{
  pre-skip   = \DelayEvaluation{0.5\topsep},
  post-skip  = \DelayEvaluation{0.5\topsep},
  body-style = \normalfont,
  head-style = \itshape
}

\def\@endtheorem{\endtrivlist\@endpefalse }

% arguments: numbered, style, name, share counter with, label,
%            counter relative to

\DeclareDocumentCommand{\newtheorem}{smmomo}
{
  \expandafter\@ifdefinable\csname #3\endcsname
  {
    \global\expandafter\let\csname end#3\endcsname\@endtheorem
    \IfBooleanTF{#1}
    {
      \expandafter\DeclareDocumentCommand\csname #3\endcsname{o}
        {\UseInstance{theoremstyle}{#2}{\NoValue}{#5}{##1}}
    }
    {
      \IfNoValueTF{#4}
      {
        \IfNoValueTF{#6}
        {
          \newcounter{#3}
        }
        {
          \newcounter{#3}[#6]
          \expandafter\xdef\csname the#3\endcsname{
            \expandafter\noexpand\csname the#6\endcsname
            \@thmcountersep\@thmcounter{#3}}
        }
        \expandafter\DeclareDocumentCommand\csname #3\endcsname{o}
          {\UseInstance{theoremstyle}{#2}{#3}{#5}{##1}}
      }
      {
        \@ifundefined{c@#4}
        {
          \@nocounterr{#4}
        }
        {
          \expandafter\xdef\csname the#3\endcsname
            {\expandafter\noexpand\csname the#4\endcsname}
          \expandafter\DeclareDocumentCommand\csname #3\endcsname{o}
            {\UseInstance{theoremstyle}{#2}{#4}{#5}{##1}}
        }
      }
    }
  }
}

=== test-xthm.tex ===

\documentclass{article}

\usepackage{xthm}

\newtheorem{plain}{Thm}{Theorem}[section]
\newtheorem{plain}{Prop}[Thm]{Proposition}
\newtheorem{plain}{Lem}[Thm]{Lemma}
\newtheorem{plain}{Cor}[Thm]{Corollary}
\newtheorem{definition}{Def}[Thm]{Definition}
\newtheorem*{remark}{Rem}{Remark}
\newtheorem*{remark}{Exam}{Example}

\begin{document}

\section{First Section}

\begin{Def}
\emph{My package} is the \textsf{xthm} package.
\end{Def}
\begin{Thm}
My package works as advertised.
\end{Thm}
\begin{Cor}[Achim]
It can be used.
\end{Cor}
\begin{Rem}
This is good.
\end{Rem}

\section{Second Section}

\begin{Def}
\emph{My package} is the \textsf{xthm} package.
\end{Def}
\begin{Thm}
My package works as advertised.
\end{Thm}
\begin{Cor}[Achim]
It can be used.
\end{Cor}
\begin{Rem}
This is good.
\end{Rem}

\stop