I'm creating a command to generate a series of macros all with equivalent styling. i.e. something along the lines of 1
\newcommand{\newcustommacro}[2]{\newcommand{#1}[1][Default]{#2{##1}}}
\newcustommacro{\macroA}{\textbf}
Now, I want my macro to have Special behavior if optional argument is not passed so I'm using David Carlisle's answer from that question.
However, when that \newcommand method is nested inside another \newcommand then it stops working.
\documentclass{standalone}
\makeatletter
\newcommand{\testA}[1][\@nil]{
\def\tmp{#1}%
\ifx\tmp\@nnil%
No arg: Hello%
\else
Yes arg: Bye(#1)%
\fi
}
\makeatother
\newcommand{\makeamacro}[2]{%
\makeatletter
\newcommand{#1}[1][\@nil]{
\def\tmp{##1}%
\ifx\tmp\@nnil%
No arg: Hello%
\else
Yes arg: #2(##1)
\fi
}
\makeatother
}
\makeamacro{\testB}{Bye}
\begin{document}
testA, no arg: \testA
testA, yes arg: \testA[arg]
testB, no arg: \testB
testB, yes arg: \testB[arg]
\end{document}
I doubled the #'s as required for passing arguments to nested newcommands. What do I need to do for the @'s? I'm stumped.
I have no averstion to xparse so if someone suggests a nested verison of egreg's answer to the same question linked above then that'd be ok too.
1: I know the example is just making a macro that is basically just \textbf{}


\makeatletterand\makeatother– egreg Nov 26 '17 at 09:56