How can I make this macro initially ignore the undefined key fn-special-text
in the second argument? It is defined within the macro (because the name is generated from the text of the first argument; that all happens in the first two steps), then set using that argument only after that definition is generated.
\documentclass{article}
\usepackage{xstring}
\usepackage{keyval}
\begin{document}
% The command:
\newcommand\annMessageParseParse[2]{%
% first step, search for the instance of `FN...` in arg #1
\StrCut{#1}{FN}\partA\partB% take unique name starting after "FN"
\StrCut{\partB}{ }\partC\partD% stop at the first space
% generate a new key using that unique name:
\makeatletter
\define@key{mykeys}{fn-\partC-text}{\expandafter\def\csname fn\partC text\endcsname{#1}}
\makeatother
% set the key using arg #2
\setkeys{mykeys}{#2}
% create a command using the new name, which employs our new key (which is just a footnote command)
\expandafter\def\csname FN\partC\endcsname{\expandarg\footnote{\expandafter\csname fn\partC text\endcsname}}
% combine `FN` and `\partC` in order to use the so-named command we just made
\edef\combinethem{FN\partC}
% replace the old `FN...` with the new command
\expandarg\def\thenewmessage{
\StrSubstitute[0]{#1}{\combinethem}
{\csname FN\partC\endcsname}
}
% spit out the message
\thenewmessage
}
% use case:
\annMessageParseParse
{This is myFNspecial new message.}% will turn into `This is my^[1] new message`
{fn-special-text={This is the special footnote}}
\end{document}
The issue is that, when the macro is called, keyval sees the undefined key immediately and errors out. Is there some way I can tell keyval (or xkeyval?) to just ignore undefined keys? Both the message and the yet to be defined key need to be made in arguments in the same command.
\makeatletter
...\makeatother
setting outside your definition of the macro\annMessageParseParse
.FN...
's are in the message, then do this stuff to each one - so it'll be much cleaner now to just wrap the whole macro def in\makeatletter
/\makeatother
once.