Modifying existing environments

15.2.1 Modifying existing environments

If you do not like the name of the proof environment and would prefer to use the name demo, define

\newenvironment{demo} {\begin{proof}} {\end{proof}}

Note that this does not change how the environment is typeset, only the way it is in- voked.

15.2 User-defined environments 381

To modify an existing environment, oldenv, type \newenvironment{name }

{begin_text } {end_text }

where begin text contains the command \begin{oldenv } and end text contains the command \end{oldenv }.

Tip Do not give a new environment the name of an existing command or environment.

For instance, if you define \newenvironment{parbox}

you get the error message ! LaTeX Error: Command \parbox already defined.

If there is an error in such a user-defined environment, the message generated refers to the environment that was modified, not to your environment. For instance, if you misspell proof as prof when you define

\newenvironment{demo} {\begin{prof}} {\end{proof}}

then at the first use of the demo environment you get the message ! LaTeX Error: Environment prof undefined.

l.13 \begin{demo} If you define

\newenvironment{demo} {\begin{proof}\em} {\end{prof}}

at the first use of demo you get the message ! LaTeX Error: \begin{proof} on input line 5

ended by \end{prof}. l.14 \end{demo}

382 Chapter 15 Customizing L A TEX Here are four more examples of modified environments.

1. The command \newenvironment{demo}

{\begin{proof}\em} {\end{proof}}

defines a demo environment that typesets an emphasized proof. Note that the scope of \em is the demo environment.

2. The following example defines a very useful environment. It takes an argument to

be typeset as the name of a theorem: \newtheorem*{namedtheorem}{\theoremname}

\newcommand{\theoremname}{testing} \newenvironment{named}[1]{

\renewcommand{\theoremname}{#1} \begin{namedtheorem}} {\end{namedtheorem}}

For example, \begin{named}{Name of the theorem}

Body of theorem. \end{named}

produces Name of the theorem. Body of theorem. in the style appropriate for the \newtheorem* declaration. This type of environ-

ment is often used to produce an unnumbered Main Theorem (see Section 15.4) or when typesetting an article or book in which the theorem numbering is already

fixed, for instance, when publishing a book in L A TEX that was originally typeset by another typesetting system.

3. In Sections 6.2.4 and 12.3.1, we came across the enumerate package, which allows you to customize the enumerate environment. If the enumerate package is loaded, you can invoke the enumerate environment with an optional argument specifying how the counter should be typeset, for instance, with the option [\upshape (i)],

\begin{enumerate}[\upshape (i)] \item First item\label{First} \end{enumerate}

items are numbered (i), (ii), and so on.

15.2 User-defined environments 383

So now we define \newenvironment{enumeratei}{\begin{enumerate}%

[\upshape (i)]}% {\end{enumerate}}

and we can invoke the new environment with (see Sections 15.3 and 15.4) \begin{enumeratei}

\item \label{ } \end{enumeratei} Reference items in the enumeratei environment with the \itemref com- mand introduced in Section 15.1.2.

4. If you want to define an environment for displaying text that is numbered as an equation, you might try

\newenvironment{texteqn}

{\begin{equation} \begin{minipage}{0.9\linewidth}} {\end{minipage} \end{equation}}

But there is a problem. If you use this environment in the middle of a paragraph, an interword space appears at the beginning of the first line after the environment. To remove this unwanted space, use the \ignorespacesafterend command, as in

\newenvironment{texteqn} {\begin{equation} \begin{minipage}{0.9\linewidth}} {\end{minipage} \end{equation} \ignorespacesafterend}

Examples 2 and 3 are included in the newlattice.sty command file (see Sec- tion 15.3). See the sample article, sampartu.tex in Section 15.4, for some instances of their use.

See Section 15.6.3 for custom lists as user-defined environments. Redefine an existing environment with the \renewenvironment command. It is

similar to the \renewcommand command (see Section 15.1.5). There are some environments you cannot redefine; for instance, verbatim and all the AMS multiline math environments.

Dokumen yang terkait

c. Bridging Teknik memanjat pada celah vertikal yang lebih besar (gullies). Caranya dengan menggunakan kedua tangan dan kaki sebagai pegangan pada kedua celah tersebut. Posisi badan mengangkang kaki sebagai tumpuan dibantu juga tangan sebagai penjaga kese

0 1 10

2. Marah: adalah kunci setiap kejahatan. Nabi saw. telah berpesan pada seseorang untuk menjauhi sikap marah dengan sabda beliau: "Janganlah engkau marah". Beliau mengulanginya berkali-kali. (H.R Bukhari). - Kebersihan Hati

2 5 14

Object Oriented Programming dengan Delphi (

1 4 75

E volusi dan aplikasi sistem informasi berbasis komputer

1 8 18

b. Data Manipulation Language (DML) : Digunakan untuk memanipulasi data dengan menggunakan perintah : select, - SISTEM BASIS DATA 1.rar (7,386Kb)

1 3 15

Hubungan Pola Asuh Orang Tua dan Kesiapan Psikologis Anak dengan Kebersihan Toilet Traning pada Anak Usia Prasekolah di Paud Ab-Arisalah Kota Lubuklinggau

0 1 8

Hubungan Pengetahuan dsn Sikap dengan Tindakan Hygiene Penjual makanan Jajanan di Lingkungan Sekolah Dasar Kaamatan Baturaja Timur Kabupaten Ogan Komering UIU Tahun 2013 A. Gani

1 3 14

Faktor faktor yang berhubungan dengan manfaatan Posyandu lansia oleh kelompok usia lanjut didesa Kemalara dalam wilayah kerja Puskesmas Kemalaraja OKU Tahun 2013. Saprianto, M.Kes

3 3 21

Korelasi umur, pekerjaan, dan keberadaan kontainer dengan kejadian penyakit malaria di desa simpang Martapura wilayah Kabupaten Ogan Komering Ulu Selatan tahun 2014 – A. Gani

0 0 18

Pengaruh Ekstrak Daun Jambu Biji (Psidiu Guajava Linn) dan Ekstrak daun Teh Hijau (Camelia Sinensis) terhadap Pertumbuhan Escherichia Coli In Vitro dan Perbandingannya dengan Kotrimoksazol

2 16 20