I have already seen these posts Macro defining macro and
Macros that define other macros, which also define other macros but unfortunately I didn't manege to figure it out how to correct my attempt to the problem.
I want to create a macro which will produce macro + global macro with @
in front of macro name, like in the following example:
\def\Bob#1{\gdef\@Bob{#1}}
\Bob{My name is Bob}
\makeatletter
\@Bob % it will display `My name is Bob'
\Bob{Name: Bob}
\@Bob % it will display `Name: Bob'
\makeatother
So this works. However:
\def\DefineField#1{%
\expandafter\edef\csname #1\endcsname##1{%
\gdef\csname @#1 \endcsname{##1}%
}%
}
\DefineField{Alice}
\Alice{My name is Alice}
doesn't work. I got Undefined control sequence.
with \@Alice
. I have checked Alice
and Bob
with \show
command:
> \Bob=macro:
#1->\gdef \@Bob {#1}.
l.20 \show\Bob
> \Alice=macro:
#1->\gdef \@Alice {#1}.
l.21 \show\Alice
They have exactly the same structure. What did I miss? MWE:
\documentclass[preview]{standalone}
\makeatletter
\def\DefineField#1{%
\expandafter\edef\csname #1\endcsname##1{%
\gdef\csname @#1 \endcsname{##1}%
}%
}
\DefineField{Alice}
\Alice{My name is Alice}
\def\Bob#1{\gdef\@Bob{#1}}
\Bob{My name is Bob}
\begin{document}
%\@Alice % Undefined control sequence.
\@Bob
\Bob{No my name is Alice}
\@Bob
\show\Bob
\show\Alice
\makeatother
\end{document}
#1
in\gdef\csname @#1 \endcsname{##1}%
, it should be\gdef\csname @#1\endcsname{##1}%
– moewe Jan 27 '19 at 11:00