Document ClassesHow to un-define a command or environment

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

How to un-define a command or environment

Post by kaiserkarl13 »

I am using a document class (in this case, the "iopart" class, intended for articles submitted to Institute of Physics journals) that contains the following commands:

Code: Select all

\@namedef{equation*}{\[}
\@namedef{endequation*}{\]}
These lines (which I'm certain are the result of someone attempting to be overly helpful) obviously break the amsmath package.

Is there a way to undefine an environment or command in LaTeX? I've tried something like

Code: Select all

\let\equation*\@undefined
or

Code: Select all

\let\equation*\undefined
but that still gives me errors. What I want to do is edit the class file and remove those two lines, but that isn't an option; the journal will preserve the original file when I submit the article, and I have no way to insist that they use the doctored file.
Last edited by kaiserkarl13 on Mon Apr 09, 2012 6:58 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to un-define a command or environment

Post by localghost »

It seems to work if you load the package right before the document class.

Code: Select all

\RequirePackage{amsmath}
Side effects cannot be ruled out.


Thorsten
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to un-define a command or environment

Post by cgnieder »

This is funny -- amsmath essentially does the opposite:

Code: Select all

\DeclareRobustCommand{\[}{\begin{equation*}}
\DeclareRobustCommand{\]}{\end{equation*}}
You can use etoolbox for undefining commands. It provides the command \csundef{<csname>}:

Code: Select all

\documentclass{iopart}
\usepackage{etoolbox}
\csundef{equation*}
\csundef{endequation*}

\usepackage{amsmath}
\begin{document}

\begin{equation*}
 x + y = z
\end{equation*}

\end{document}
Regards
site moderator & package author
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

How to un-define a command or environment

Post by kaiserkarl13 »

Great idea putting \RequirePackage{amsmath} before the document class. I don't actually use the equation* environment anywhere, so any side effects should be minimal. The etoolbox package is a good suggestion as well (though in this case I'm less comfortable with it, since the journal will probably not use eTex to process my files).

Thanks much!
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to un-define a command or environment

Post by cgnieder »

Without etex you could do sth like this:

Code: Select all

\documentclass{iopart}
\expandafter\let\csname equation*\endcsname\relax
\expandafter\let\csname endequation*\endcsname\relax
\usepackage{amsmath}
...
Regards
site moderator & package author
Post Reply