Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!yale!quasi-eli!cs.yale.edu!newsbase!duchier From: duchier@cs.yale.edu (Denys Duchier) Newsgroups: comp.text.tex Subject: Re: Optional arguments? Message-ID: Date: 12 Jun 90 01:00:36 GMT References: <1990Jun11.165323.231@metro.ucc.su.OZ.AU> Sender: news@cs.yale.edu Reply-To: duchier-denys@cs.yale.edu Organization: Computer Science, Yale University, New Haven, CT 06520-2158 Lines: 25 In-reply-to: mathas_a@maths.su.oz.au's message of 11 Jun 90 16:53:23 GMT The code for LaTeX has numerous example of this. Say you want to create a macro of no mandatory argument and 1 optional argument: \def\foo{\@ifnextchar[{\@foo}{\@foo[DEFAULT]}} \def\@foo[#1]{...} the real work is done by \@foo. \foo simply checks the next character, and if it isn't [ (indicating the presence of an optional argument), a default optional argument is inserted ([DEFAULT] here). Suppose you want a macro of 2 mandatory arguments and 1 optional argument, which typesets in math mode the 1st mandatory argument followed by the optional argument followed by the second mandatory argument. The default argument should default to an arrow. Here is what you do: \def\sequent#1#2{\@ifnextchar[{\@sequent{#1}{#2}}{\@sequent{#1}{#2}[\Rightarrow]}} \def\@sequent#1#2[#3]{\ifmmode#1#3#2\else$#1#3#2$\fi} Note that the code in the above assumes that @ is considered a letter: either put the code in a .sty file or bracket it with \makeatletter \makeatother, or something... --Denys