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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Consider the following situation.

  % Note the / *after* #1
% Error: Use of \mymacro@i doesn't match its definition.

I made a typo in the definition of \mymacro adding a / before \endcsname. The error shown made me believe that /test was improperly expanded by the three \expandafter but I was wrong. As /test/ is not defined, it silently expands to \relax and yes TeX is right saying that Use of \mymacro@i doesn't match its definition since I feed it with a \relax instead of a \foo.


This behavior of \csname defined control sequence (that is expanding to \relax when undefined) is really handy but sometimes I'd like to deactivate it and maybe issue an Undefined control sequence error. Is it possible?

share|improve this question
up vote 8 down vote accepted

You cannot alter the behaviour of \csname, but you can use e-TeX's \ifcsname to issue an error:


where \UndefinedName is deliberately not defined. TeX will then issue an error complaining about Undefined control sequence, followed by #1 (which is what you actually want to complain about).

(Unlike \@ifundefined, \ifcsname is expandable and does not add to the hash table.)

share|improve this answer
Thanks Joseph. That fits exactly my needs since i need it in an expandable context. – cjorssen Jan 27 '12 at 13:25

You can check the command for existence and invoke the error yourself.

    Command /#1/ undefined!
    See the definition of \protect\mymacro!

The \@ifundefined macro uses \csname so it will define the macro as \relax. I don't think that this is an issue (we invoke the error anyways), but you can surround the code by \begingroup ... \endgroup to make the definition local.

share|improve this answer
LaTeX2e's \@ifundefined will leave the macro equal to \relax unless you use grouping, if it was previously undefined. – Joseph Wright Jan 27 '12 at 9:21
@JosephWright I know, but I don't think it is that an issue as we invoke the error message. However, I should have mentioned it, thanks! – yo' Jan 27 '12 at 9:36
Thanks. However I prefer Joseph's solution since it is expandable. – cjorssen Jan 27 '12 at 13:27

Your Answer


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.