Path: utzoo!attcan!uunet!munnari.oz.au!metro!news From: mathas_a@maths.su.oz.au ( Andrew ) Newsgroups: comp.text.tex Subject: Optional arguments? Message-ID: <1990Jun11.165323.231@metro.ucc.su.OZ.AU> Date: 11 Jun 90 16:53:23 GMT Sender: news@metro.ucc.su.OZ.AU (news) Reply-To: mathas_a@maths.su.oz.au ( Andrew ) Organization: Mathematics, University of Sydney Lines: 26 Does anyone know of a way to define macros with an optional argument in LaTeX. I know that you can fudge it as follows: \newcounter{Code} \newenvironment{code}[2]% {\refstepcounter{Code}% \if#2N{}\else\label{#2}\fi% <- if second argument is % an "N" don't label \def\CAPTION{#1}\begin{verbatim}}% {\centerline{Code fragment \theCode.\quad\CAPTION}} (this is an improved version of my suggestion for the Code environment - it allows easy labelling of each fragment - see previous posting if interested). However, it would be nicer to be able to do something like \newcommand\fred[2][1]{...} and make fred have two mandatory arguments and one optional; and \fred would be used in the normal way of \fred{213}{lkjhksdfa}[hjd] etc. Any ideas? Will post a summary if something turns up. Andrew - smile at a stranger today and help make the world a better place. while you're, at it, why not hug a friend!