77

Does the @ mean anything specific? For example, is it substituted? Does it split the command into parts, like \s@foo could internally mean "foo of type s"? Is the purpose of the @ only to make internal commands break when used outside a class definition or a package? If so, how is that a Good Thing?

47

Others have mentioned the protection against user definition / redefinition. Another aspect is that command names like \foo may only contain letters, so \mymacro is a valid command, \my!macro is not. So the normal user cannot redefine these commands, as \newcommand{\my!macro}{....} will throw an error. You can redefine the category code of e.g. ! to behave as a letter, so that \my!macro is considered as a valid command name (control word in TeX speak). This is what \makeatletter does for @, \makeatother changes the @ back to a symbol (category code 'other').

62

When Knuth originally published the language he used the @ to mark commands that a user should not normally use. This was in order to avoid overriding kernel commands by redefining them. Remember that a macro defined using \def will overwrite an earlier command with the same name. Lamport followed suit with LaTeX a few years later as well as countless other package writers. The @ can only be used in a command in a document only if you use \makeatletter so that it can change its \catcode.

For me it served also another purpose as a marker to split long commands, for example it is more readable to read \make@page@wider than \makepagewider.

24

No, it does not mean anything specific; it is simply used to "namespace" code that shouldn't appear in a regular document. You can use almost any analphabetic symbol you like; ConTeXt also allows ? and !, while LaTeX3/expl3 uses _ and : instead.

While there are few conventions on how to use @ in LaTeX package code, for expl3 we recommend the syntax

\<module>_<function name>:<argument spec>

and

\<l/g/c>_<module>_<variable name>_<datatype>

for functions (macros that take arguments) and variables, respectively. For variables, the prefixes are l for ‘local’, g for ‘global’, and c for ‘constant’.

15

Some TeX internal commands have @ in them, too. IMO the idea is not so much to break when used "externally" as to keep the space of regularly available control sequences free for users.

Some of the original authors used @ in place of vowels, but more often nowadays people seem to use it as a word separator much like _ is used in Perl, C, PHP, Python, etc.

3
  • 9
    Using @ for vowel sounds can get very tiresome: some of the LaTeX2e kernel has runs of internal functions with more and more @ symbols in them, making them more-or-less unreadable! – Joseph Wright Nov 30 '10 at 17:17
  • 1
    @Joseph Wright: indeed. Viz. \z@ and \m@ne – Matthew Leingang Nov 30 '10 at 19:03
  • 2
    @JOseph Wright: in particular when you run out of \v@w@ls@iv. – Ulrich Schwarz Nov 30 '10 at 19:55
2

Use this pair when you redefine LaTeX commands that are named with an at-sign character @. The \makeatletter declaration makes the at-sign character have the category code of a letter, code 11. The \makeatother declaration sets the category code of the at-sign to code 12, its default value.

As TeX reads characters, it assigns each one a category code, or catcode. For instance, it assigns the backslash character \ the catcode 0. Command names consist of a category 0 character, ordinarily backslash, followed by letters, category 11 characters (except that a command name can also consist of a category 0 character followed by a single non-letter symbol).

LaTeX’s source code has the convention that some commands use @ in their name. These commands are mainly intended for package or class writers. The convention prevents authors who are just using a package or class from accidentally replacing such a command with one of their own, because by default the at-sign has catcode 12.

The pair \makeatletter and \makeatother changes the default code and then changes it back. Use them inside a .tex file, in the preamble, when you are defining or redefining commands named with @, by having them surround your definition. Don’t use these inside .sty or .cls files since the \usepackage and \documentclass commands already arrange that the at-sign has the character code of a letter, catcode 11.

In this example the class file has a command \thesis@universityname that the user wants to change. These three lines should go in the preamble, before the \begin{document}.

\makeatletter
\renewcommand{\thesis@universityname}{Saint Michael's College}
\makeatother

I think understanding /makeatletter helps to understand what @ is doing. At least it helped for me after reading this thread. Here is the page from where the explanation taken.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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