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.

I know I can redefine a control sequence to be empty or \relax, as in my example below. However, doing so doesn't prevent one from using that control sequence , because it is still defined.

To add some safeguards in my code, I'd like to wipe TeX's memory of a user-defined control sequence, so that, if I subsequently use that control sequence, I get the usual Undefined control sequence error. How can I do that?

\documentclass{article}
\begin{document}
\newcommand\foo{foo}
\renewcommand\foo{}
\foo % no error
\end{document}
share|improve this question
4  
\let\foo\undefined –  Bordaigorl Nov 19 '13 at 14:52
    
So simple, yet I didn't know about it. Thanks. Let's wait to see if my question is a duplicate. Otherwise, you should post an answer. –  Jubobs Nov 19 '13 at 14:54
    
related to (but not a duplicate of) tex.stackexchange.com/questions/12339/… –  Jubobs Nov 19 '13 at 14:55

1 Answer 1

up vote 13 down vote accepted

The trick is to bind the macro to something which is not defined. Traditionally, the macro \undefined is left undefined (!) so you can simply do

\let\foo\undefined

If, for some (probably wrong) reason you or some package defines \undefined then this trick won't work.

In any case, if you later want to manually check whether \foo is defined or not, you can use LaTeX's \@ifundefined test which will detect whether \foo is undefined OR \relax.

share|improve this answer
2  
Yes, there's no \undef primitive. There's \undef in etoolbox, but it relies on the same method: it does \let\foo\etb@undefined, trusting that \etb@undefined remains globally undefined. –  egreg Nov 19 '13 at 18:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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