873

Many LaTeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?

7
  • 9
    As for a reference, tug.org/pipermail/tugindia/2002-January/000178.html
    – chl
    Jan 5, 2011 at 20:53
  • 293
    For the absolute beginners; the commands should be read as Make @ symbol a letter and Make @ symbol an "other".It's NOT Make when you encounter a letter and Make when you encounter others.
    – percusse
    Mar 14, 2013 at 10:54
  • 15
    @percusse Hah. I've been compiling things in LaTeX since 2005 and I didn't know that. Jun 4, 2014 at 3:26
  • 64
    How bizarre and obscure. I love what LaTeX does, but the more I learn it, the more I realize what a crazy hack it is.
    – Dov
    Jul 14, 2014 at 12:05
  • 7
    hellish language. why do people say it's easy Aug 22, 2019 at 4:57

1 Answer 1

836

All characters in TeX are assigned a Category Code or "catcode". There are 16 catcodes in all, some containing just a single character, e.g. \ is (normally) catcode 0, {, catcode 1 etc. Normal characters are catcode 11; this category normally comprises all of the letter characters. The @ symbol is given the catcode of 12, which means it is not treated as a normal letter. The effects of this are that @ cannot normally be used in user document files as part of a multicharacter macro name. (All other non-letter characters are also forbidden in macro names: for example, \foo123, and \foo?! are not valid macro names.)

In LaTeX class and package files, however, @ is treated as a normal letter (catcode 11) and this allows package writers to make macro-names with @. The advantage of this is that such macro names are automatically protected from regular users: since they cannot use @ as a normal letter, there is no accidental way for a user to override or change a macro that is part of the internal workings of a package.

However, it is sometimes necessary in user documents to have access to such package-internal macros, and so the commands \makeatletter and \makeatother change the catcode of @ from 12 to 11 and 11 to 12, respectively.

In practical terms, if you need to modify a package internal macro that contains the @ symbol in its name, you will need to surround your modifications by these commands:

\makeatletter % changes the catcode of @ to 11
<your changes here>
\makeatother % changes the catcode of @ back to 12

The commands should not be used within .sty and .cls files themselves as they may conflict with the catcode changes that occurs when package and class files are loaded. For more information on this see Is it really bad to use \makeatletter and \makeatother in a package or class file?.

23
  • 15
    @Caramdir: Not quite true. \@ is a perfectly good macro. It's what Knuth calls a control symbol. If the category code of @ is 11, then \@ becomes a control word.
    – TH.
    Jan 5, 2011 at 21:11
  • 18
    @Philipp: Given the audience for this question, surely multiletter macro name is a much more understandable term.
    – Alan Munn
    Jan 5, 2011 at 22:39
  • 57
    Thank you so much for that explanation. The way the command is phrased, I thought it was telling the compiler to make something execute at a specific letter. It's literally: "make the "at" symbol a letter. It's actually pretty funny.
    – user28374
    Apr 3, 2013 at 2:41
  • 10
    @MickG No, there is no general command \make<foo>letter. The \makeatletter commands are one off.
    – Alan Munn
    Dec 28, 2013 at 18:49
  • 13
    Gosh. All this time, I thought that \makeatletter makes a tletter, and \makeatother makes a tother. :)
    – user139954
    Dec 30, 2017 at 18:47

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.