# make command undefined [duplicate]

Possible Duplicate:
How to undo a \def (i.e., Need a \undef capability)

In my template I test for chapter defined to prevent that code section only valid for a chapter class are executed. However if I load titlesec chapter is always defined regardless of the class in use.

So how can I make \chapter undefined after the execution of titlesec?

So far I tried this which did not work:

 \ifcsdef{chapter}{%
\usepackage{titlesec}%
% make chapter undefined again
\let\chapter\relax%
}{
\usepackage{titlesec}%
}

-

## marked as duplicate by Werner, diabonas, cgnieder, lockstep, Harish KumarOct 15 '12 at 23:36

What happens if you \let\chapter\UnDeFiNED instead of \relax? –  Marco Oct 15 '12 at 20:02
\undef\chapter seems to work with etoolbox package. Test case:Chapter is \ifcsdef{chapter}{defined}{undefined}. And @Marco's suggestion also works. –  Peter Grill Oct 15 '12 at 20:05

Instead of setting \chapter to \relax, you can set it to an undefined sequence:

\let\chapter\undefined

-
I use now \undef\chapter instead, but both work. –  Matthias Pospiech Oct 15 '12 at 20:14
@MatthiasPospiech \undef\chapter does a similar thing, precisely \let\chapter\etb@undefined. –  egreg Oct 15 '12 at 20:25

The following should do the trick, it keeps the definition of \chapter (defined or undefined) that was active before package titlesec is loaded:

\makeatletter
\@ifdefinable{\saved@chapter}{%
\let\saved@chapter\chapter
\usepackage{titlesec}%
\let\chapter\saved@chapter
}
\makeatother

-