[texhax] Creating stared versions of macros
Morten Høgholm
moho01ab at student.cbs.dk
Thu Dec 30 14:10:26 CET 2004
On Thu, 30 Dec 2004 12:36:20 +0100, Stefan Björk <stefan at raggmunk.nu>
wrote:
>> instead of RTFM -- try to look inside your favorite packages or clases
>
> I tried (pstricks) but that was even more confusing. :-)
That particular one is pretty hairy!
This small example should perhaps make it a little clearer:
%%%%%%%%%%%
\documentclass{minimal}
\makeatletter
\newcommand*\testa{%
\@ifstar
{Star version, two mandatory arguments:
\testa at star}
{No star, one mandatory and one optional argument:
\testa at nostar}%
}
\newcommand*\testa at star[2]{%
Arg~1:~``#1'', arg~2:~``#2''.%
}
\newcommand*\testa at nostar[2][Default]{%
Arg~1:~``#1'', arg~2:~``#2''.%
}
\makeatother
\begin{document}
\testa*{First}{Second}
\testa[Optional]{Mandatory}
\testa{Mandatory only}
\end{document}
%%%%%%%%%%%
This kind of trickery will be a lot easier in the (near) future with the
xparse package. You can get it from
<http://www.latex-project.org/code/experimental/xbase.tgz> if you want to
look at it.
--
Morten Høgholm
More information about the texhax
mailing list