# Outputting internal at-macro via newcommand?

Just noticed a somewhat strange behavior, when trying to show internal Latex @ commands from main document via \newcommand.

Consider the following MWE, where all instances of the internal macro ( \c@something) calls are already wrapped in \makeatletter/\makeatother:

\documentclass[10pt]{article}

% define internal at-macro
\makeatletter
\def\c@something{AAA}
\typeout{ == \c@something == }
\makeatother

% define a newcommand calling the at-macro
\newcommand{\mytest}{
\makeatletter
\c@something
\makeatother
}

\begin{document}

test

\mytest{}

\makeatletter
here \c@something
\makeatother

\end{document}


When I build the above with pdflatex, I get this:

... however, I would have expected something like:

test
AAA
here AAA



-

TeX converts characters to tokens when it first reads them. So when you do

\newcommand{\mytest}{
\makeatletter
\c@something
\makeatother
}


TeX 'sees' @ as an 'other' character, and the definition of \mytest is:

1. A space (as you have a new line with no % just after the opening {)
2. The token \makeatletter
3. The token \c
4. The 'other' character @
5. The 'letter' tokens 'something' (each separate)
6. The token \makeatother

What you wanted was

\makeatletter
\newcommand{\mytest}{%
\c@somecommand
}
\makeatother


in which case the definition of \mytest is the single token \c@somecommand, exactly as for the \def case.

-
Awesome - many, many thanks for that, @JosephWright! Special thanks for breaking it down character by character - it also cleared up other things for me (such as the comment before the end of line thing :)) ; cheers! –  sdaau May 14 '12 at 19:46