While writing lecture notes from statistical physics I found out, that I am often writing very similar long LaTeX sequences like
\frac{\partial }{\partial <foo>}
\frac{\partial <bar>}{\partial <foo>}
and
\left( \frac{\partial <bar>}{\partial <foo>} \right)_{<baz>}
I wanted ease my life by using forms
\dddfrac{<foo>}
\dddfrac{<foo>}{<bar>}
,
and
\dddfrac{<foo>}{<bar>}{<baz>}
all with the same name, so they are easy to remember.
One friend of mine (who's help is unavailable now) helped me with the following TeX hackery:
%requires \usepackage{gmverb}
\fooatletter{%
\def\dddfrac#1{%
\relaxen\dddfrac@i
\relaxen\dddfrac@ii
\relaxen\dddfrac@iii
\def\dddfrac@i{#1}%
\@ifnextchar\bgroup\dddfrac@getii\dddfrac@typeset}%
%
\def\dddfrac@getii#1{%
\def\dddfrac@ii{#1}%
\@ifnextchar\bgroup\dddfrac@getiii\dddfrac@typeset}%
%
\def\dddfrac@getiii#1{%
\def\dddfrac@iii{#1}%
\dddfrac@typeset}%
%
\def\dddfrac@typeset{%
\@ifundefined{dddfrac@iii}{%
\@ifundefined{dddfrac@ii}{% 1 argument only
\frac{\partial }{\partial \dddfrac@i}
}{% 2 arguments
\frac{\partial \dddfrac@i}{\partial \dddfrac@ii}%
}}{% 3 arguments
\left( \frac{\partial \dddfrac@i}{\partial \dddfrac@ii} \right)_{\dddfrac@iii}%
}}
}
I have experience in LaTeX, but cannot write in pure TeX (but I understand what the code does more-or-less).
Now although this works as it is, the code is ridiculously long to write if I want to have, say, 20 such commands. Is there any standard way of slipstreaming implementation of such behaviour, for a person who don't know how to program in pure TeX? Maybe someone already wrote package for this case, similar to e.g. the suffix
package?
Second question: LaTeX has a tradition of introducing starred versions for commands with some extra functionality instead of sufixing name with e.g. "Ex" (like Microsoft did). Is it possible to go along this tradition with the \dddfrac command and define \dddfrac* with another set of definitions for different number of arguments?
Matbe the suffix
will help? After all, this package allows for definitions of starred versions of commands or for a version of command with 1 argument and without. But the documenation is rather short and requires knowledge of TeX, which I humbly hope to be able to live without.