Solved
Thanks to @PhelypeOleinik for the solution! And thanks to everyone else who responded so quickly to provide assistance. For anyone who finds this post in the future, the error really had nothing to do with ConTeXt, so the explanation below will be useful even if you use LaTeX or plain TeX.
Original Post
I am creating a module in ConTeXt that is primarily accessed through a command \setup<name>[]
(for some generic structure named <name>
). Apart from this and a few other commands intended for the end-user, I have been adding a namespace prefix to all my internal commands, but due to how I want this command to operate, I chose not to use ConTeXt's built-in \installcommandhandler
.
Nonetheless, I have almost finished the entire thing except for one incredibly irritating namespace-related bug that I haven't been able to work out. At one point, one of my commands calls \processcommacommand[<list>]<command>
where both <list>
and <command>
are in \csname
style, due to namespace prefixing, and both need to be expanded with \expandafter
chains. I've isolated the problematic section and changed command names below:
\unprotect
\installnamespace{nms}
%\def\????nms{@@@@nms} % For testing only
% A simpler namespace creator could just run e.g. \def\????nms{@@@@nms}, but since in
% practice the actual namespace installer won't determine the prefix string until runtime,
% I have to define everything as generally as possible below, in terms of
% \csname\????nms<other>\endcsname.
% ... other module code ...
% If #1 consists of <arg1A>,<arg1B>,... separated by commas, and #2 consists of
% <arg2Akey>=<arg2Aval>, <arg2Bkey>=<arg2Bval>,... separated by commas, the
% \<namespace>_processor command below attempts to create a series of commands like so:
% % \def\<namespace>@<tag>@<arg1A>@<arg2Akey>{arg2Aval}
% % \def\<namespace>@<tag>@<arg1B>@<arg2bkey>{arg2Bval}
% % etc.
% ...for some externally defined string \tag.
\expandafter\unexpanded\expandafter\def\csname\????nms _processor\endcsname[#1][#2]{%
\expandafter\def\csname\????nms _params\endcsname##1{%
\doifnotempty{##1}{\getparameters[\????nms @\tag @##1@][#2]}
}
\expandafter\def\csname\????nms _csvs\endcsname{#1}
\expandafter\expandafter\expandafter\processcommacommand\expandafter\expandafter
\expandafter[\expandafter\csname\????nms _csvs\endcsname\expandafter]%
\csname\????nms _params\endcsname
% The above should simplify to
% % \processcommacommand[\<namespace>_csvs]\<namespace>_params,
% ...but in practice it throws a "Missing \endcsname inserted" error.
}
% ... other module code ...
\protect
\endinput
However, if I set the namespace at the top to be defined by \def\????nms{@@@@nms}
instead and replace the problematic line, which begins with the 3 \expandafter
calls, with direct references to the namespace prefix (e.g. \processcommacommand[\@@@@nms_csvs]\@@@@nms_params
), the entire module works just fine, which is baffling to me, since this shouldn't be any different in theory. Am I using \expandafter
incorrectly? I tried rewriting that particular line a few times and it came out the exact same way, so I can't tell what mistakes, if any, I'm making there.
ConTeXt ver: 2018.07.02 14:39 MKIV beta fmt: 2018.9.17 int: english/english
for my version. I'm a bit wary of posting the entire log file due to privacy concerns (and probably some paranoia), but I'll add the specific error message to the original post. Let me know if I'm leaving out anything essential. – N.D. Oct 10 '18 at 16:07