[Tex/LaTex] LaTeX @ (at) symbol

tex-core

Possible Duplicate:
Why do LaTeX internal commands have an @ in them?

What does the @ symbol mean in LaTeX? I'm looking at the source of apa.cls, and there's a declaration:

\newsavebox\gr@box

and later on

\sbox\gr@box{\includegraphics[width=\linewidth]{#2}}.

It seems like @ isn't acting as a normal character, but I can't figure out exactly what it's doing, and couldn't find anything after bit of googling (how I would love a Google regex feature!) Thanks.

EDIT: Thanks for the help; of the links I looked through I found http://www.tug.org/pipermail/tugindia/2002-January/000178.html to be very helpful and concise. To summarize, the @ character is not normally allowed in the names of macros, so as a hack for scoping, LaTeX packages declare it internally to be a valid name character and use it for their macros. You can use \makeatletter in a document to access these macros, but you obviously must be very careful since you have can now overwrite essential LaTeX kernel macros; use \makeatother to revert.

Best Answer

Every char has the category code from 0 up to 15.

  • 0 - Escape character; this signals the start of a control sequence. backslash \ (Unicode code point U+005C) is a default escape character.
  • 1 - Beginning of group; such a character causes TeX to enter a new level of grouping. The open brace { is a beginning-of-group character.
  • 2 - End of group; TeX closes the current level of grouping. TeX has the closing brace } as end-of-group character.
  • 3 - Math shift; TeX uses the dollar sign $ for this.
  • 4 - Alignment tab; TeX uses the ampersand &.
  • 5 - End of line; a character that TeX considers to signal the end of an input line.
  • 6 - Parameter character; this indicates parameters for macros. In TeX this is the hash sign #.
  • 7 - Superscript; default superscript is the circumflex ^.
  • 8 - Subscript; default superscript is underscore _.
  • 9 - Ignored; characters of this category are removed from the input.
  • 10 - Space; space characters receive special treatment. TeX assigns this category to the space (Unicode code point U+0020) and tab characters (U+0009).
  • 11 - Letter; in TeX only the characters a..z, A..Z are in this category. Often, macro packages make some ‘secret’ character (for instance @) into a letter, see below.
  • 12 - Other; TeX puts everything that is not in the other categories into this category. It includes, for instance, digits, punctuation and @.
  • 13 - Active; active characters function as a TeX command, without being preceded by an escape character. The tie character ~ has such category.
  • 14 - Comment character; the default comment character is %.
  • 15 - Invalid character; this category is for characters that should not appear in the input. TeX causes an error in the case of such chars.

A macro name consists only of letters (code 11). The @ symbol has category code 12 and can therefore not be included in the macro name. However, you can change the category of any symbol

\catcode`\@ = 11 % Macro \makeatletter does the same

Now you can use @ as letter in your macro names. All LaTeX packages change catcode of the @ to 11 and return it to 12 at the end.

\catcode`\@ = 12 % Macro \makeatother does the same

Note you can change catcode any character, not only @. For example, if you want to use [, ] as open and close group symbols write

\catcode`\[ = 1
\catcode`\] = 2
Related Question