Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}%
 }
share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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
add comment

2 Answers

up vote 4 down vote accepted

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

\let\chapter\undefined
share|improve this answer
    
I use now \undef\chapter instead, but both work. –  Matthias Pospiech Oct 15 '12 at 20:14
1  
@MatthiasPospiech \undef\chapter does a similar thing, precisely \let\chapter\etb@undefined. –  egreg Oct 15 '12 at 20:25
add comment

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
share|improve this answer
add comment

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