Kimbing Ng
Kimbing Ng

Reputation: 77

What does the symbol @ mean in latex

for example

\def\if@nch@mpty#1{\def\temp@a{#1}\ifx\temp@a\@empty}
\def\f@nch@def#1#2{\if@nch@mpty{#2}\f@nch@gbl\def#1{\leavevmode}\else
                                   \f@nch@gbl\def#1{#2\strut}\fi}

What does the symbol @ mean in latex

Upvotes: 5

Views: 3492

Answers (1)

Peterlits Zo
Peterlits Zo

Reputation: 536

By default in a TeX document, a command (also called a macro) can be only named using the letters [a-zA-Z] but not symbols such as @.

Why is that? Because each character has a category code (or catcode, for short), and by default only [a-zA-Z] have the catcode 11 that allows it to be used in a macro. But, amazingly, TeX allows you to change a character's catcode! So at the beginning of cls/sty files, LaTeX sets the catcode for @ to catcode 11. Afterward, it resets it back to the default.

LaTeX also includes two commands \makeatletter and \makeatother to easily change the catcode of @.

For example:

\makeatletter

% This is ok define new command with at character.
\def\command@with@at@character{%
    Command With At Character.%
}

% And you can use it in the pair makeatletter/makeatother
\command@with@at@character

\makeatother

% But you CANNOT use the macro here!!! TeX will try to call \command
% but not \command@with@at@character, because `@` now does not have 
% right catcode.
% \command@with@at@character

See What do \makeatletter and \makeatother do? to get more information.

About the macro \catcode(which can help you to change the character's catcode), you can get more information from here.

Upvotes: 6

Related Questions