Questions tagged [environments]

{environments} is for general questions related to (La)TeX environments. For questions about environment subcategories like {lists}, {quoting} environments, or {floats} use the appropriate tag instead.

LaTeX environments start with \begin{name} and end with \end{name}.
In TeX environments may start with \name and end with \endname.
ConTeXt environments start with \startname and end with \stopname.
(Here name represents the actual environment name.)

LaTeX environments can be defined, redefined or provided (i.e. only defined when they don't exist yet) using:

\newenvironment{<name>}{<code at begin>}{<code at end>}
\renewenvironment{<name>}{<code at begin>}{<code at end>}
\provideenvironment{<name>}{<code at begin>}{<code at end>}
3231 questions
114
votes
8 answers

Why can't the end code of an environment contain an argument?

Environments are allowed to have arguments, but reference to those arguments can only appear in the opening code of the environment, and not the closing code. What is the reason for this, and are there preferred ways around…
Alan Munn
  • 218,180
57
votes
1 answer

Defining environments based on other ones: What's the right way?

Assume that I want to define a new environment that is a variant of an existing one. For example, I seek an italicquote environment that acts like the quote environment but displays its contents in italic. The approach endorsed in section A.1.3 of…
lockstep
  • 250,273
27
votes
4 answers

Is there a reason to use \begin{environment} \end{environment} rather than \environment \endenvironment?

What reason (other than perhaps being easier for my syntax highlighter to parse) is there to write \begin{center} Here is centered text \end{center} rather than: \center Here is centered text \endcenter And likewise for other environments. Does…
Seamus
  • 73,242
20
votes
1 answer

Passing options to the newenvironment

I have a GrayBox environment defined as follows. It is used \begin{GrayBox}...\end{GrayBox} or \begin{GrayBox}[\textwidth]...\end{GrayBox}, that is, it can pass optional parameter to the environment. I guess #1 is the setup for default value, and #2…
prosseek
  • 6,033
20
votes
1 answer

How does LaTeX implement environments?

Do you know how LaTeX implements environments? To be more precise, what does \newenvironment{}[][]{}{} in terms of TeX commands (i.e., how is the LaTeX command \newenvironment defined in TeX)?
digital-Ink
  • 3,083
20
votes
2 answers

What is the problem with nested environments using \BODY (environ package)?

This question led to a new package: newenviron I want to define some environments, which place their content into multiple different other environments. To access the contents I used the environ package, which introduces the \BODY command. However…
grackkle
  • 549
19
votes
1 answer

What exactly does the \begin{document} command trigger?

Let us consider these two files first. \documentclass{article} \parindent 0.0mm \hyphenpenalty 500 \tolerance…
Masroor
  • 17,842
16
votes
2 answers

How can I undefine an environment?

How can I undefine an environment? This is how to undefine a command: \newcommand\foo \makeatletter \let\foo\@undefined \makeatother I need to undefine the spacing environment from the setspace package. This does not seem to…
n.r.
  • 4,942
15
votes
2 answers

How do I define new environments, and why would I want to?

I've read about defining new, custom environments that can be used like \begin{thisismyown} % do some funky stuff \end{thisismyown} How do I define thisismyown, and why would I want to?
Tomas Aschan
  • 15,528
15
votes
3 answers

Defining an Environment that Takes an Argument

I want to define a new environment that will take a text argument, and use it as a title. \documentclass{article} \usepackage{amsthm} \newenvironment{titleproof} {\begin{proof} \textbf{Title of the Proof} \newline} {\vspace*{0.5\baselineskip}…
jamaicanworm
  • 29,114
15
votes
1 answer

Environment for greyed-out (or otherwise color) text

Sorry for being as clueless as the last times I asked but also having done no research because I have to finish this overhead presentation for tomorrow... Is there a good way to create an environment which makes all text inside it colored in a…
15
votes
4 answers

How to change the font in the description environment?

How to change the font in the description environment, for the term word (e.g. First, Second...) and for its definition (The first item, The second item...)? How to restore the paragraph indentation after environment in the whole document? How to…
novice
  • 151
  • 1
  • 1
  • 3
14
votes
2 answers

Is it safe to abbreviate \begin{foo}...\end{foo} with something like \bfoo ... \efoo

Can I safely do this: \newcommand\bfoo{\begin{foo}} \newcommand\efoo{\end{foo}} where foo is a standard LaTeX environment? Probably the verbatim environment breaks, but others as well? That way one could write \bfoo inside the foo…
topskip
  • 37,020
14
votes
2 answers

How can I ensure that an environment always starts on a new line? (a new paragraph / horizontal box)?

Sometimes when creating environments, you want to ensure that they always start new paragraph when two environments appear immediately after one another eat up spaces generally idiot-proof (which, dare I say, might also be called "fully LaTeX…
14
votes
5 answers

Environment definition separates matching braces

Suppose I want to define an environment which is essentially a modification of an existing one. I tried something like that: \newenvironment{newenv}{% \formatcommand{\begin{oldenv}% }{% \end{oldenv}}% } I would expect…
Raphael
  • 5,983
1
2 3
22 23