# How can I wipe TeX's memory of a user-defined control sequence?

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}

-
\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

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.
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