This is a more proper way to do it:
\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amssymb,amsmath,amsthm}
\newtheorem{theorem}{Theorem}
\usepackage{mathtools} % Bonus
\DeclarePairedDelimiter\norm\lVert\rVert
\begin{document}
\section{Mathematical Methods}
\begin{theorem}[Placheral's Theorem]
\begin{equation*}
\norm{ F }^2_2 =2\pi \norm{ u }^2_2 .
\end{equation*}
\end{theorem}
\end{document}
As one might have guessed \newtheorem
constructs theorem environments. Use it to define your Theorem, Lemma, etc. environments. You might want to have a look at \theoremstyle
as well. Here is a handy method for defining an example env which is not italic.
\theoremstyle{definition} % amsthm only
\newtheorem{example}{Example}
As tohecz
mentions, you may want to read up on this subject. Details for amsthm
, can be found in amsthdoc.pdf
.
The \newtheorem
syntax should be covered by any standard LaTeX introduction.
The fellowship of \newenvironment
and \renewenvironment
commands
Yes, \renew...
will erase or redefine the previous definition (or eject an error message, if this has not been defined before.)
In many cases it's more suitable to make a wrapper environment, which does not attack the original environment.
\newenvironment{foo}{%
%startup code, i.e the \WritingHand and `\singlespacing`
\begin{quotation}
}{%
% end code
\ding{...}
\end{quotation}
}
Since environments use groups, the change of the line spacing within of foo
is safe outside, there is no need to explicitly switch back to \onehalfspacing
. This is true for all lengths/skips and colour settings.
\documentclass{article}
\usepackage{setspace}
\usepackage{pifont}
\usepackage{marvosym}
\onehalfspacing
\newenvironment{foo}{%
\singlespacing
\begin{quotation}
\WritingHand
}{%
\ding{47}
\end{quotation}
}
\begin{document}
% Compare the spacing outside and inside of foo environment
Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
\begin{foo}
Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
\end{foo}
\end{document}
![enter image description here](https://i.stack.imgur.com/9F3FY.jpg)
The renewenvironment
version
renewenvironment
is basically similar, but one has to keep in mind too design issues:
- Should the environment be extended/improved --> use the old definition
- Completely drop the old behaviour --> do not use the old definition (of course)
I assume that the old behaviour should be available still, so I tried the first approach:
- First store the old environment startup code, which is just the command
\quotation
, to something, say \latex@quotation
.
- Store the environment end code, which is
\endquotation
then, to \latex@endquotation
.
- Basically proceed as in the
\newenvironment
version and replace \begin{quotation}
with \latex@quotation
and \end{quotation}
with \latex@endquotation
.
The output is the same.
Important note: If the environment has optional arguments, it's better to use \LetLtxMacro
instead of \let
, you need the letltxmacro
package then.
\documentclass{article}
\usepackage{setspace}
\usepackage{pifont}
\usepackage{marvosym}
\onehalfspacing % for this document ....
\makeatletter
\let\latex@quotation\quotation
\let\latex@endquotation\endquotation
\renewenvironment{quotation}{%
\singlespacing
\latex@quotation
\WritingHand
}{%
\ding{47}
\latex@endquotation%
}
\makeatletter
\begin{document}
% Compare the spacing outside and inside of foo environment
Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
\begin{quotation}
Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
\end{quotation}
% And once again
Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
\end{document}
Edit The shortest version: Use the xpatch
command and its \xpretocmd
and \xapptocmd
macros.
\documentclass{article}
\usepackage{setspace}
\usepackage{pifont}
\usepackage{marvosym}
\usepackage{xpatch}
\onehalfspacing % for this document ....
\newcommand{\lotrtext}{%
Three Rings for the Elven-kings under the sky,
Seven for the Dwarf-lords in their halls of stone,
Nine for Mortal Men doomed to die,
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
}
% Append the `\singlespacing` etc. after the `\quotation` startup is called
\xapptocmd{\quotation}{\singlespacing%
\WritingHand%
}{}{}
% Prepend `\ding{47}` before `\endquotation` comes into action.
\xpretocmd{\endquotation}{\ding{47}}{}{}
\begin{document}
% Compare the spacing outside and inside of foo environment
\lotrtext
\begin{quotation}
\lotrtext
\end{quotation}
% And once again
\lotrtext
\end{document}
And the final (?) remark -- your possibilities:
- Refine a wrapper with
\newenvironment
- Change or completely erase the previous definition with
\renewenvironment
- Patch the commands with
\xpretocmd
, \xapptocmd
or \xpatchcmd
which is something between the 1st and 2nd. way.
All depends on the requested design, there is no general rule. (And if redefinition or new definition, I suggest to use \NewDocumentEnvironment
or \RenewDocumentEnvironment
from the very powerful xparse
package.
Update
Mico made an important comment:
The package etoolbox
provides the commands \AtBeginEnvironment
and \AtEndEnvironment
, \BeforeBeginEnvironment
and \AfterEndEnvironment
which do basically the same what I've done with \xpretocmd
and \xapptocmd
or the explicit \renewenvironment
, however, to an existing environment only -- which of the etoolbox
commands should be used depends on the precise requirements, what should be done before or after the group begins/ends.
As an alternative, there is NewEnviron
from the environ
package, which allows for the saving of the environment body into \Body
macro.
Best Answer
I don't really recommend this because there is not much benefit to get from the approach as desired by the O.P.
The command
\example
is defined already as soon theexample
environment has been declared with\newtheorem
, as is\endexample
in order to mark the end of the example and doing some 'clean-up' for the end of the environment.\renewcommand{\example}
is basically no problem as long as\example
does not appear again inside the redefined\example
environment, otherwise it will end in an recursive definition, finally exceeding TeX's memory.A solution is to save the old definition of
\example
and\endexamples
and use those in an redefinition of\example
, together with an extra\begingroup...\endgroup
pair in order to prevent the leaking of font etc. changes outside, which has been the case by using\example
only as reported by the O.P.The
\foo
count stuff is included only in order to show that the group feature is maintained and does not leak outside.