After hours of banging my brain against my skull, I narrowed down an issue I'm having to the fact that \makeatletter doesn't work inside \newcommand. Commands that I call after \makeatletter are registered as undefined, as if \makeatletter didn't do anything.
Why is this the case?
In the example below, I define two commands. Calling one of them from the document body causes the undefined error, while the other doesn't.
\documentclass[11pt]{book}
\usepackage{kvsetkeys}
\newcommand{\commandThatFails}{
\makeatletter \comma@parse{}{} \makeatother
}
\makeatletter
\newcommand{\commandThatWorks}{
\comma@parse{}{}
}
\makeatother
\begin{document}
Hi there.
\commandThatFails
\commandThatWorks
\end{document}
\comma@parse, but in the first one, since\makeatletteris only saved (not executed) the following that is saved are the tokens\comma,@,p,a,r,s,e. – Manuel Sep 16 '14 at 00:13\verbin a command argument. catcodes change the tokenisation of characters they do not affect tokens tat have already been parsed. when the argument to\newcommand is scannedyou get token\makeatlettertoken\commatoken@tokenptokenatokenrtokenstokenewhen the command is executed the catcode of@is changed but that has no affect on tokens – David Carlisle Sep 16 '14 at 00:14\csname comma@parse \endcsnamedoesn't require cat change? – percusse Sep 16 '14 at 00:20