TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

In typing up some small examples that might create errors in LaTeX (for Documents with typical LaTeX errors), I tried the following:

\def\my@macro#1{-#1-}% This is magic
\my@macro{hi}% Print -hi-

Since I almost religiously encompass @-symbol definitions and/or usage with \makeatletter and \makeatother (see What do \makeatletter and \makeatother do?), and since latex.ltx issues \makeatother at literally the 4th-to-last line, I thought this would flash an error.

It didn't.

Not only was I able to define the macro, I was able to use it without problem after it is defined. Why is this the case?

One clue here, although I don't know why, is that I'm using the TeX \def syntax, rather than \newcommand, which does produce an error.

share|improve this question
Jep thats true. (pdflatex utd) When i add a @ somewhere between begin/end {document} it gets printed. So in fact it seems to be a letter. Maybe a change in pdflatex? – bloodworks Jan 6 '12 at 23:39
@bloodworks nope @ is not a letter but a symbol just like 1 or / etc. And yes symbols print but they can't be used in macros "names". they can however be used inargument delimiters when using \def to define macros. – Frank Mittelbach Jan 7 '12 at 0:05
up vote 39 down vote accepted

Your definition defines a macro \my that is required to be followed by @macro followed by one argument (which is either a single token or a brace group). Thus this gives you the result.

Reason that this works this way is that normally @ is not a letter (but a symbol which is \catcode 12) so it would end the "macro name" but it then becomes part of the parameter text which is everything that is follows after the name up to the { which starts the replacement text. You can test this as follows:

\my @macro {hi}  % should work too
\my {hi}         % error

LaTeX 's \newcommand complains as it builds up the macro definition differently and doesn't allow for delimited arguments.

share|improve this answer

You are defining the control sequence \my which has a bizarre <parameter text> consisting of the tokens

@12 m11 a11 c11 r11 o11 #1

(as subscripts I've put the category code).

This means that \my must be followed by @macro and then comes the argument.

You can experiment writing, after \begin{document},

\my @macro{hi}

The first line will be accepted and print


because spaces after control sequence names are always ignored.

The second line will be accepted and perform the requested definition; the third line will print


while the fourth will give an error:

! Use of \my doesn't match its definition.

Indeed \my now requires @differentmacro after it.

What's the business? If the category code of @ is 12 (\makeatother), then the scanner during \def\my@macro#1{-#1-} will stop the control sequence name as soon as it finds @ which is a non letter (letters have category code 11), so it takes everything up to the first brace as the <parameter text>.

When \makeatletter is in force, @ is a letter, so with


the macro's name will be \my@macro and the parameter text will be simply #1.

share|improve this answer
+1 for the example with \my@differentmacro. That was what got me to understand how this works. – Tomas Lycken Jan 7 '12 at 5:54

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.