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\makeatletter
is only saved (not executed) the following that is saved are the tokens\comma
,@
,p
,a
,r
,s
,e
.\verb
in 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 scanned
you get token\makeatletter
token\comma
token@
tokenp
tokena
tokenr
tokens
tokene
when the command is executed the catcode of@
is changed but that has no affect on tokens