I have several macros with a similar structure, for example:
\def\firstmacro#1{\myinitializer ...actual code... \myfinalizer}
\def\secondmacro#1{\myinitializer ...actual code... \myfinalizer}
\def\thirdmacro#1{\myinitializer ...actual code... \myfinalizer}
(\myinitializer and \myfinalizer are only placeholders for more complicated initializer code.) I was thinking how I could simplify this common structure by defining a custom \def macro. I arrived at
\def\custom@def#1{
\def#1{\myinitializer\csname custom@#1\endcsname}
\expandafter\def\csname custom@#1\endcsname
}
\custom@def\firstmacro#1{...actual code... \myfinalizer}
\custom@def\secondmacro#1{...actual code... \myfinalizer}
\custom@def\thirdmacro#1{...actual code... \myfinalizer}
So \custom@def defines the wanted command to call \myinitializer and pass to an internal command that contains the actual definition. Everything after the first argument of \def is passed to the \def of that internal macro. However, with this approach, \myfinalizer still needs to be specified explicitly. Any idea how I could eliminiate this?
