16

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 work:

\usepackage{setspace}
\makeatletter
\let\beginspacing\@undefined
\let\endspacing\@undefined    
\makeatother
n.r.
  • 4,942

2 Answers2

16

The macro \newenvironment{foo} defines the two macros

\foo
\endfoo

not \beginfoo.

Rather than undefine spacing, you could simply make it a noop:

\renewenvironment{spacing}{}{}

This is preferable because it will keep track of nested environments.

egreg
  • 1,121,712
  • What is an environment needs to be undefined, because it was predefined but conflicts with some package? Is there a better way than going through \makeatletter? – Alexey Jun 04 '20 at 14:45
  • @Alexey Where do you get to undefine the environment? – egreg Jun 04 '20 at 15:01
  • In my own class i defined an environment, and then i loaded a package that defines an environment with the same name :). I do not want to change my class, usually it is fine. – Alexey Jun 04 '20 at 15:03
  • @Alexey It mostly depends on which of the two conflicting definitions you want to keep. – egreg Jun 04 '20 at 15:04
  • I wanted to keep the one coming from a package (not mine). – Alexey Jun 04 '20 at 21:22
  • @Alexey Then say \let\whatever\relax and \let\endwhatever\relax before loading the package (if the environment is called whatever). – egreg Jun 04 '20 at 21:50
  • @egreg i want to undefine an environment to make using it produce an error and thereby enforce a policy. i have defined new environments based on this forbidden one and i want only to new ones to be used. the @undefined approach results in errors using the new ones because they use the forbidden one ... can this be achieved? – peter Feb 02 '21 at 13:01
  • @peter It's better if you ask a new question with the needed details. – egreg Feb 02 '21 at 13:25
2

Per this answer, use

\let\spacing\@undefined
\let\endspacing\@undefined 

to undefine the spacing environment. Note that \@undefined is not a special command, it simply is, itself, undefined.

Paul Wintz
  • 402
  • 2
  • 14