# Abridging \begin{} ... \end{}

Is it possible to abbreviate the cumbersome commands \begin{}...\end{} once and for all?

I mean, except for \begin{document} ... \end{document}, I would like to have the environments such as \begin{theorem}...\end{theorem} become simply one-line command.

• Wrap it up in an outer macro, but I am not sure this is possible for any environment. You have to use {} for the environment content then, however.
– user31729
Jan 18 '15 at 6:41
• Updated with 'Generic' approach
– user31729
Jan 18 '15 at 7:09
• I'd really recommend learning how to do this easily with your editor rather than trying to teach TeX how to do it. There's a fluid way to insert an environment (or wrap your selection with one) in most (if not all) editors made for LaTeX. Jan 18 '15 at 7:29
• Don't do this; it seems practical, but it isn't in the long run. Jan 18 '15 at 10:59
• there are some environments for which this is absolutely impossible. verbatim looks for the exact string end{verbatim} so it knows where to stop. there are others, including the amsmath multi-line environments. experimenting to find out which is mostly a waste of time. Jan 18 '15 at 14:34

This uses an environment - wrapper, via \NewDocumentCommand from xparse package for possible better configurability (and \par content as argument values).

Possible vertical spacing issues are not addressed.

It's however not possible to say \mytheorem{Title} content ... since the environment needs a clear end.

\documentclass{article}

\usepackage{xparse}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}[section]

\renewcommand{\thetheorem}{\arabic{theorem}}

\NewDocumentCommand{\mytheorem}{+m+m}{%
\begin{theorem}{#1}
#2
\end{theorem}
}

\begin{document}

\section{First}

\mytheorem{Theory on Brontosaurs, by Miss Ann Elk}{%

Brontosaurs are thin at one end, thick in the middle and thin again at the other end.
}

\end{document}


Edit: Update ... a 'generic' wrapper command for such theorem environments

This defines a generic wrapper command for such newtheorem issues:

\GenericWrapper[section]{theoremname}{Theoremname} will generate a command \mytheoremname with is wrapper for \begin{theoremname}...\end{theoremname} and reset every section (default value of the optional 1st. argument). (xparse is used with \NewDocumentCommand for this, in order to facilitate the usage of optional arguments in contrast to the \newcommand[][] way.)

The command changes the theorem label to \arabic{theoremname}.

\documentclass{article}

\usepackage{xparse}
\usepackage{amsthm}

\NewDocumentCommand{\GenerateWrapper}{+O{section}+m+m}{%
\newtheorem{#2}{#3}[#1]

\expandafter\renewcommand\csname the#2\endcsname{\arabic{#2}}%

\expandafter\DeclareDocumentCommand\csname my#2\endcsname{+m}{%
\begin{#2}%
##1%
\end{#2}
}%
}%

\GenerateWrapper{theorem}{Theorem}%
\GenerateWrapper{exercise}{Exercise}%

\GenerateWrapper{question}{Question}%

\begin{document}

\section{First}

\mytheorem{%
Theory on Brontosaurs, by Miss Ann Elk%
Brontosaurs are thin at one end, thick in the middle and thin again at the other end.
}%

\myexercise{Find a Brontosaur%

Excavate a Brontosaur
}%

\myquestion{Mathematics

Prove that
$\int\limits_{-\pi}^{\pi} e^{-x^2} = \sqrt{\pi}$
}%

\end{document}


• There's no point in using xparse for this. You use none of its features. I can't understand why you define \mytheorem with two arguments. Jan 18 '15 at 11:01
• @egreg: \xparse for providing optional arguments? And some features not yet introduce, but later on.
– user31729
Jan 18 '15 at 11:03