8

This question already has an answer here:

The answers to this question mention commands such as \@author and \@director, and latex.ltx is full of them. However, when I use \@author in my document, it just outputs the word "author". What does the @ in command names mean?

marked as duplicate by Steven B. Segletes, Jesse, jub0bs, Sean Allred, Peter Jansson Mar 7 '14 at 14:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

9

The @ at the beginning of a command name is common way to implement a private namespace, that is, to define commands which are hidden from the user. The user can therefore not inadvertantly modify them. This is a safety belt.

The identifiant of a command—the text after the \ character—must be a sequence of letters. TeX's idea of which character is a letter or not is defined by the table of catcodes, which can be reconfigured at run time.

Many packages find it useful to define private macros which cannot easily be accessed by the user, thus preventing the user to inadvertantly modify them or use them. This is achieved with catcodes in the following manner:

  1. Arrange so that @ has the catcode of a letter.
  2. Define private macros, having the letter @ in their names.
  3. Arrange so that @ has not the catcode of a letter anymore.

When user's code takes control of the flow of execution after step 3, it cannot inadvertantly interact with macros having a @ in their name.

  • +1 Nice answer. "Preventing" is too strong a word, though. I'd write "reducing the risk that", instead. There is always a risk that a macro, internal or not, be overwritten. All it takes is one misplaced \makeatletter. – jub0bs Mar 7 '14 at 14:09
  • So a command such as \@author would only be used by other commands, rather than directly by the user? And when I use \@author in my document, it isn't evaluated as a command, but rather separately as \@ and the text author? I only know what \@ does after characters such as punctuation or capital letters. – Cerran Mar 7 '14 at 14:15
  • 1
    @Jubobs If you play with makeatletter, you are not a user anymore but a developer! :-) – user40989 Mar 7 '14 at 14:19
  • @Cerran You are perfectly right! – user40989 Mar 7 '14 at 14:21
  • @user40989 The answer to Cerran's first question is "yes", but the answer to the second one is "no". – jub0bs Mar 7 '14 at 14:22

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