1

I am trying to understand the following package etoolbox. I am unsure about the meaning of the following syntax since I am not sure what is the correct question to ask in google or in the book of Knuth what to search.

\edef\etb@catcodes{\etb@catcodes}

I do not understand the meaning of the statement especially the @ character. If anybody could explain it I would be thankful.

  • 1
    Welcome to TeX.SX! Since etoolbox treats basically with LaTeX you won't be successfully looking into D.E. Knuth's TeXBook. The @ is a very often used technique in LaTeX to concat command sequence names etc and to hide the more elementary macros from ordinary user's application, since usage of @ requires some additional 'setup' -- it can't be used accidentally in this case, at least not without warning or error message. But your question itself is unclear – user31729 Jul 20 '15 at 21:35
  • 1
    If you're specifically interested in the use of @, see What do \makeatletter and \makeatother do? (possible duplicate). – Werner Jul 20 '15 at 21:41
  • 2
    This line is part of a few more lines of code which are important in order to understand the meaning of the particular definition. (basicically it is about saving and later restoring category codes of a few characters…) – clemens Jul 20 '15 at 21:43
4

This part of etoolbox is rather tricky, but not really complicated, once one gets the idea.

When LaTeX executes \usepackage, the named file is loaded and @ is considered as a letter, which makes it possible to use it in macro names.

The etoolbox package needs to change category codes in certain parts of it, so it wants to be sure to restore those settings at the end.

Here is the code:

\def\etb@catcodes{\do\&\do\|\do\:\do\-\do\=\do\<\do\>}
\def\do#1{\catcode\number`#1=\the\catcode`#1\relax}
\edef\etb@catcodes{\etb@catcodes}
\let\do\noexpand
\AtEndOfPackage{\etb@catcodes\undef\etb@catcodes}

The first instruction stores a list of the characters that potentially change their category code in the package, to be restored at the end. The \do macro is a traditional macro for defining lists, and it can be redefine to execute the list. In this case it is redefined so that, for instance, \do\& expands to

\catcode\number`\&=\the\catcode`\&\relax

If the code after the definition of \do was just \etb@catcodes, TeX would transform the above code into

\catcode 38=4

which would be useless, because this is the current setting. Instead, etoolbox wants to save these settings for the end, so it does

\edef\etb@catcodes{\etb@catcodes}

which does similar complete expansions for all stored characters. Since \edef does complete expansion before assigning the meaning to \etb@catcodes, there's no danger of infinite loop; at the end, the definition of \etb@catcodes is equivalent to

\def\etb@catcodes{%
  \catcode 38=4\relax
  \catcode 124=12\relax
  \catcode 58=12\relax
  \catcode 45=12\relax
  \catcode 61=12\relax
  \catcode 60=12\relax
  \catcode 62=12\relax
}

but with a fundamental difference: if some package has changed the category code of, say, | to 13, there would be

  \catcode 124=13\relax

in the definition of \etb@catcodes.

At the end of the package, \etb@catcodes is executed, so restoring all category codes to the previous state and the macro is undefined.

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.