I'd like to do something along the lines of this question but is trying to do something much simpler. The following macro (I'd like to attribute it, but can't remember where I learned it)
\makeatletter
\def\myNorm#1{%
\def\tmp{#1}
\ifx\tmp\@empty%
{\rho}
\else%
{\rho(#1)}
\fi%
}
\makeatother
puts parens around the second argument if it's not empty, e.g.,
$\myNorm{5}$
and $\myNorm{}$
return resp $\rho(5)$
and $\rho$
.
The construction above is a bit of a mouthful, and hard to remember, but I use it a lot. So I'd like to automate the macro-creating process. Specifically, what I'd like to do is create a macro-creating macro that would look something like
\MacroTemplate#1#2
so that the first argument would be the name of a new macro, e.g., myNorm
, and the second would be, say, \rho
, such that
\MacroTemplate{myNorm}{\rho}
would construct the macro that I defined explicitly above. Then I could proceed to write $\myNorm{\rho}$
and $\myNorm{\rho}{5}$
which would return as above. But I could also then define
\MacroTemplate{yourNorm}{\nu}
and and write $\yourNorm{\nu}{5}$
and $\yourNorm{\nu}{}$
which would return $\beta(5)$
and $\beta$
respectively
without having to remember the complicated construction every time I want something similar. thanks very much for any suggestions.
`
to mark your inline code as I did in my edit.\rho
and\nu
as arguments of the final macros? Aren't the values given to\MacroTemplate
already hard-coded in the definition of the final macros?%
on lines where they do nothing (after\@empty
,\else
and\fi
) but are missing%
where they would do something (after the}
)