{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.

learn more… | top users | synonyms (3)

25
votes
2answers
3k views

Label and caption without float

I’d like to have an environment that works much like a float, except that it doesn’t float. That is, in fact, I’d like to be able to define an environment that has a label and a caption. I ...
42
votes
9answers
2k views

Where do I find out how a command/environment is defined?

Say I want to redefine the itemize environment, or make a modified version of it. I want to know how it is currently defined. Where do I find this information? If it's some particular package command, ...
19
votes
4answers
6k views

Making a new environment combining equation and split

I'm trying to define a new environment that consists of a split environment inside an equation environment. But I'm getting an error. Here's what I'm doing: \documentclass[a4paper,12pt]{article} ...
44
votes
7answers
2k views

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 ...
23
votes
2answers
3k views

Definitive guide to trivlists

I create a lot of theorem-like environments, and I'm usually happy to employ a package (such as ntheorem, amsthm, etc) to do the work for me. After studying the ntheorem documentation, and reading ...
21
votes
1answer
238 views

Environments for visually setting text apart

I have a document consisting of alternating paragraphs from different voices. Because the paragraph blocks look too much alike, I need some way to give the different parts a different look. I have ...
14
votes
5answers
797 views

Command behavior depending on current environment

I would like to write a LaTeX macro whose code depends on the parent environment such as: \newcommand\test{ %if current_environment=env1 test1 %elseif current_environment=env2 test2 %else } ...
24
votes
2answers
567 views

Environment that counts words inside

How can I create the environment that could count words inside itself? More specifically, I want to write an enviroment called "assignment" such that the code \begin{assignment} Some words here. ...
25
votes
2answers
2k views

How to automatically add text immediately after \begin{document}

I attempted to redefine the document environment as follows, but get a complaint that: LaTeX Error: \begin{MYdocument} on input line 13 ended by \end{document}. \documentclass[12pt]{article} ...
8
votes
2answers
3k views

tabularx inside a \newenvironment

There's something wrong with this code: \newenvironment{Tbl} {\begin{tabularx}{\textwidth}{|l|X|} \hline} {\end{tabularx}} but this is fine: \newenvironment{Tbl} {\begin{tabular}{|l|l|} \hline} ...
14
votes
3answers
818 views

Extracting the contents of text in a specified environment into a new file

Imagine I have a complete latex file and I want to extract only the text that appears in a specified environment (i.e., within a custom hypothesis environment) For example: \begin{document} ... Lots ...
9
votes
2answers
14k views

Changing default width of blocks in beamer

I use a custom Beamer theme for my presentations. In my presentations I'd like to use blocks (\begin{block}…\end{block}). These blocks are rendered slightly too wide to fit into my theme. Is there a ...
20
votes
2answers
8k views

What does the titlepage environment do and what are its benefits?

I'm speaking about the article document class only, because report and book deal with titles in a different way. Obviously, the titlepage environment triggers a new page after it, and it resets the ...
13
votes
2answers
486 views

How to turn off an environment (e.g. tikzpicture) for faster draft compiling

I'm currently writing my thesis and have been looking for ways to speed up compile time. I can shave off a lot of time by using draft mode so that images aren't processed, but I have several TikZ ...
24
votes
4answers
1k views

Do all starred commands have anything in common?

\section* produces an unnumbered section, align* makes the environment unnumbered, which is comparable in a way. \newcommand* doesn't accept \par in its argument, which is different. Stefan Kottwitz ...
20
votes
2answers
5k views

How to modify spacing around quotation environment?

I am almost there in my quest to reproduce the rather compact layout of the book I'm translating... one thing to go, though: I successfully used the enumitem package to modify the vertical and ...
7
votes
3answers
697 views

Changing the catcode of _ in one command?

In the following code, I would like _ to be a simple letter. How can I achieve this ? % Source : http://forum.mathematex.net/latex-f6/forcer-le-retour-a-la-ligne-dans-texttt-t13246.html#p127511 ...
7
votes
1answer
1k views

Using minted to define a new environment

Can I define a newenvironment that has inside it a minted environment? eg and environment that would be a quickhand for the following code: \begin{figure}[htp] \centering ...
43
votes
1answer
2k views

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 ...
41
votes
3answers
11k views

Is it a bad idea to use \begin{section} … \end{section} in LaTeX?

In several discussions about relatives merits of LaTeX v. xml, a xml supporter complained that in LaTeX sections, subsections etc are not properly closed, so it is hard to tell where a section ends. ...
7
votes
3answers
940 views

Showing Solutions of the Questions “separately”

There is a class for LaTeX called exam. Using this class, one can write questions and answers for exams. The answers are displayed under (after) each question. My goal is to have all answers in the ...
5
votes
1answer
232 views

write contents of an environment to document and toc

I want to write the contents of an environment to the document and the toc. Here's a MWE hacked to look (almost) like what I need. \documentclass[pdftex,12pt]{book} \usepackage{hyperref} ...
24
votes
4answers
4k views

Numbers outside Math environment

Should numbers inside the text be placed inside a math environment? For example, if I am writing ...indent code by 4 spaces..., should I write it this way or ...indent code by $4$ spaces...? ...
13
votes
2answers
3k views

Split-like environment inside cases environment

I'd like to have a cases environment with some cases that are too long to fit on one line. I tried this: \begin{cases} \begin{split} long expression \\ second line of long expression ...
13
votes
3answers
2k views

Hide custom environment content based on boolean

I have a custom environment which adds some text around its content, but I also want it to be able to show or hide its contents depending on a boolean. I have tried doing the following: ...
8
votes
1answer
625 views

hide proof environment for restructuring

I am writing my thesis, and i am in restructuring phase - sorting theorems where they should belong thematically. And it would be helpful to have all the proofs hidden so i am not laden with the ...
23
votes
3answers
597 views

Does \newenvironment have a \provideenvironment cousin, as \newcommand has \providecommand?

To avoid the problem of having to decide whether to use \newcommand or \renewcommand, LaTeX has the option of \providecommand. Is there something corresponding to this for environments? I'd like to ...
16
votes
1answer
493 views

What exactly does \@doendpe do?

Quoting from the LaTeX2e sources: [\@endparenv, \@doendpe] To suppress the paragraph indentation in text immediately following a paragraph-making environment, \everypar is changed to remove ...
11
votes
2answers
617 views

How can I check if the current code is inside a certain environment?

I would like to define a command which checks if it is executed inside a certain environment. Like this: \documentclass{article} \newenvironment{myenv}[0]{at start}{ at end} ...
8
votes
2answers
164 views

How to ignore everything in the document environment?

Yes, you did read the title correctly! I want to ignore everything that is between \begin{document} and \end{document} when I \input a file. I thought that that would be very simple, just use the ...
8
votes
1answer
1k views

Defining a new type of floating environment

In a document, I need to provide some details about specific topics without disrupting the flow of the main document, so that the details may easily be omitted at first reading. To do so, I thought it ...
8
votes
1answer
1k views

How can one pass the contents of a LaTeX environment to a macro?

I'm working on an exam document class where the user enters in questions something like this: \multiplechoice{Question} {Answer #1} {Answer #2} {Answer #3} {Answer #4} {Correct answer} {Explanation} ...
7
votes
3answers
506 views

Insert text into a fixed size box

Is there a way to create a box which has fixed width and height? I tried \parbox and some similar things, but sometimes the text overflows. If the text inserted would overflow: it should be resized ...
7
votes
3answers
603 views

Generating lists of custom environment.

I've created my own environment example, similar to theorem. Now I want to generate a list of examples, similar to list of tables or list of figures. How can I achieve this?
5
votes
2answers
323 views

How can I ignore everything except a specified environment?

In other words, I'd like to have the comment environment of the verbatim package "inverted". I am pretty sure I read about some package allowing this some time ago, but I can't recall its name (nor ...
1
vote
1answer
1k views

bottomrule not working in a self-made environment

I have this environment for consistent tables in my LaTeX documents: \newenvironment{defaultTable}[2] { \@float{table}[h] \noindent \tabularx{\textwidth}{#1} \specialrule{0.5pt}{10pt}{0pt} ...
16
votes
2answers
346 views

Duplicating Environments

When I want to globally modify a command in my document, I will often use a duplicated version of the original in the stencil, with the help of the \let macro. For example, if I wanted to do ...
10
votes
3answers
332 views

Defining a list environment with multiple optional arguments

I'm trying to define a list environment with multiple optional arguments and with a default values for those arguments. For example, creating a new environment with a name newenv, which accepts two ...
7
votes
2answers
201 views

Solution environment via true/false switch

I would like to create a solution environment that prints a solution in the case where an optional argument is set to true (the default) and hides the solution in the case that the argument is false. ...
22
votes
2answers
2k views

Defining a new environment whose contents go in a TikZ node

I would like to define an environment which typesets the contents in a box, and I'd like to use TikZ (I'm aware of alternatives like fancybox). So I would like something like \newenvironment{abox}% ...
15
votes
2answers
2k views

How to create new table environment

I am working on a book that has many many such tables. Is there a way to create shortcut for the code shown below. I want to make table caption a variable, because in the MWE shown below except ...
13
votes
2answers
805 views

Format a verbatim paragraph

How can I format a verbatim paragraph? I.e. break, fill and join input lines to produce globally balanced output with the lengths of each line approaching the target \textwidth as closely as possible. ...
8
votes
1answer
796 views

Problem with environment expansion and the Tikz external library.

I've created my own environment mytikz, which basically looks like this (full MWE): \documentclass[a4paper]{article} \usepackage{tikz} \usetikzlibrary{external} \newenvironment{mytikz}{%begin code ...
7
votes
1answer
862 views

define a new Example environment

how can i define a new Example environment like the image shown in the following? this environment should have the following attributes: endmarks must be positioned at the last line, whether it ...
16
votes
5answers
8k views

Customizing theorem name

Suppose I have a series of theorems that I would like displayed as Jim's Theorem. Bob's Theorem. Will's Theorem. rather than as “Theorem (Jim).”, “Theorem (Bob).”, and “Theorem ...
5
votes
1answer
769 views

New environment with minted

I want to create a new environment to transform this: \begin{listing} \caption{some caption} \label{code:label} \begin{minted}[options]{language} My code here \end{minted} \end{listing} ...
13
votes
2answers
2k views

Define an “escape underscore” environment

I am writing a text document in LaTeX where I need a lot a words with underscores: foo_bar_1, more_bar_2_long_expression_3. I know about the underscore package, but for some reason the [strings] ...
11
votes
4answers
403 views

Is there a ready solution to typeset a diff file?

In a text about Git I want to typeset diffs similar to this visualization: Commit details on GitHub. Is there any ready-made solution to that, especially the coloring of the diff lines? (In other ...
3
votes
1answer
78 views

Extracting commands from environment

In Automatic scaling of tikz images in floatrow I was asking how to scale several images in one row to the same height and to scale the resulting row to linewidth. I would like to automate the ...
13
votes
4answers
284 views

What are the consideration when choosing either newcommand or newenvironment?

The first time I learnt LaTeX, I thought \newcommand properly fits for inline mode and \newenvironment for displayed mode. Later I noticed it is not correct. So the question is What is the rule of ...