A new environment can be made with:

\newenvironment{name}[1]{stuff at the beginning}{stuff at the end}

In the document the environment can be created with:

\begin{name} different stuff \end{name}

Now I want to call the same environment with different names. My solution is:


This is pretty dirty and makes my code confusing. Do you know a better solution? Something like this would be great:

\newenvironment{name1, name2,  ... , nameN}[1]{stuff1}{stuff2}
  • 2
    why use a different name not an argument? \begin{name2} looks weird, why not have \begin{name}[type=2]... or some other argument form to distinguish them? – David Carlisle Jul 28 at 10:33
  • @campa I don't think, that this is what I mean. – Titanlord Jul 28 at 10:40
  • @DavidCarlisle I'm working on Templates, that produce differen styled PDFs. But a TeX code with one template should work with all other templates. When doing math i often use \begin{theorem} etc. but when I do Pen and Paper I use \begin{MonsterBox} etc. The point is, that the TeX for math should work with Pen and Paper, too – Titanlord Jul 28 at 10:42
  • 1
    why change the environment name, the latex model would normally be you use the same name with different definitions – David Carlisle Jul 28 at 12:08
  • 1
    I still don't understand. What makes name1 different from name2? From what you've shown, they would have the same output. How is theorem different from MonsterBox? – Teepeemm Jul 28 at 13:14

Updated answer

The code below defines a new command \NewEnvironments that will define multiple copies of an environment using a comma separated list of names for the environments. The syntax is:

\NewEnvironments[#args]{comma separated list of names}{env beginning}{env end}

So the syntax is similar to \newenvironment except that the optional argument for the number of arguments must be first. For example, you can define a series of environments, name1, name2, name3, name4, that accept one argument using:

  {\textbf{Environment with one arg: ##1}\newline\itshape}% begin
  {\newline\textbf{End of 1 environment}\par}             % end

Note the use of ##1, rather than #1, for the parameter inside the environment definition. Of course, since all of these environments are the name you could only use name1. On the other hand, the code supports defining environments that depend on their name such as:

  {\textbf{Environment #1 with one arg: ##1}\newline\itshape}% begin
  {\newline\textbf{End of 1 environment}\par}                % end

Here is the MWE showing how to use the code:


% usage: \NewEnvironments[#args]{comma separated list of names}{env beginning}{env end}

% examples

% environments with no arguments
    {\textbf{Environment with no args}\newline\itshape}% begin
    {\newline\textbf{End of 0 environment}\par}        % end

% environments with one arguments
    {\textbf{Environment with one arg: ##1}\newline\itshape} %  begin
    {\newline\textbf{End of 1 environment}\par}              % end





Original answer

It seems unusual to me that the name environments are all exactly the same, but I accept that there may be good reasons for this. One way to do what you want without duplicating code is to have a "template" environment that contains the main code and then have the other environments use this. That is, a structure like:


The dots ... inside the \newenvironment definitions allow you to include extra code if you want but, as described in the OP, these dots should be omitted.

| improve this answer | |
  • This is a bit better, but still needs a lot of code. So there is no better way in doing that? E.g. using lists and for-loops, so that a list contains all the names, and the for-loop makes the newenvironment defines (for-loop as a sujective function)? – Titanlord Jul 28 at 13:21
  • @Titanlord See my update – Andrew Jul 29 at 1:15
  • This is a pretty good answer! Thank you very much! – Titanlord Jul 29 at 9:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.