I am fairly new to LaTeX, so I apologize if this is a beginner question, but I have not found a good way to query for it otherwise.

I have observed that when I use an environment like \begin{itemize}...\end{itemize}, I can place \newcommand inside the environment, which are scoped to the environment.




\item $\FFF$

%$\FFF$ %this is out of scope, so it would cause an error if it were commented back in.


However, environments like itemize and enumerate tend to have special effects (such as giving meaning to \item). My question is whether there exists an environment which has no "special effects", whose only role is to limit the scope of declarations.

  • 7
    You can enclose anything in braces {...} and this will limit the scope macro definitions within the braces. – Alan Munn Feb 25 '13 at 4:36
  • I accept this answer if you write it as one, but just out of curiosity, does this mean all LaTeX environments come with built-in {...}? – merlin2011 Feb 25 '13 at 4:40
  • @merlin2011 Essentially yes; LaTeX environments have their own scope. Anything defined (or renewed) inside of them won't be available outside of the environment. – Sam Whited Feb 25 '13 at 4:43

As Alan Munn said, using braces is one way to go. You an also simply define your own environment:


And then use it like you normally would:

  \newcommand*{\scopedcommand}{Do stuff}
  \scopedcommand % This works

The two arguments to newenvironment are the code to insert before the content of the environment, and after. Leaving them blank essentially defines an environment that does nothing.

Therefore, the following won't compile:



    \newcommand*{\dummycmd}{This is scoped}                                      

Unless you comment out the second dummycmd.

EDIT: Also, meant to say: You can also use the TeX primitives \begingroup and \endgroup for this. They form what TeX calls a 'semi-simple' group, and are not interchangeable with {...}.

EDIT 2: As @tohecz reminded me in the comments, the correct way to do this (if you really want an environment for whatever reason) is to use


Any of the other solutions will work too, however, this is cleaner than defining a new environment.

  • 4
    You can use \begin{@empty} for this. Just remember that you cannot use \begin{relax} because \relax behaves like a non-defined thingy in these contexts ;) – yo' Feb 25 '13 at 23:27
  • @tohecz Absolutely right; I forgot all about @empty. I'll update the answer — thanks! – Sam Whited Feb 25 '13 at 23:58
  • "semi-simple group"... HMMM 🤔 – Mateen Ulhaq Dec 25 '18 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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