ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Wolfgang Schuster <schuster.wolfgang@googlemail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Macro with variable number of arguments
Date: Sun, 28 Feb 2010 10:17:15 +0100	[thread overview]
Message-ID: <4B8A349B.6040906@googlemail.com> (raw)
In-Reply-To: <4C6F69ED-2E35-4260-B2FE-125D1EF31611@gmail.com>

Am 28.02.10 09:54, schrieb Otared Kavian:
> Hi all,
>
> I would like to write a macro which may have sometimes two, sometimes three arguments. The first and the last one are always present, but not necessarily the middle one. The unsatisfactory solution I have now is something like the example below:
>
> \define[2]\myMacroTwo{Name: #1\crlf Email: #2\crlf\thinrule\blank[small]}
> \define[3]\myMacroThree{Name: #1\crlf Address: #2 \crlf Email: #3\crlf\thinrule\blank[small]}
>
> \starttext
> \myMacroTwo{Hans}{hans@hagen.context.nl}
> \myMacroThree{Wolfgang}{Paradise of TeX, 2010}{wolfgang@schuster.context.de}
> \stoptext
>
> I think that (or rather I am certain…) in ConTeXt it is possible to define a unique macro called \myMacro which automatically tests the number of arguments: if there are  only two of them the commands in \myMacroTwo are executed, while if three arguments are present, the commands in \myMacroThree are executed.
>
> Can anyone give a hint on this matter?
>    
\def\myMacro
   {\dotriplegroupempty\domyMacro}

\def\domyMacro#1#2#3%
   {\doifelsenothing{#3}
      {Name: #1\crlf Email: #2\crlf}
      {Name: #1\crlf Address: #2 \crlf Email: #3\crlf}%
    \thinrule\blank[small]}

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


  reply	other threads:[~2010-02-28  9:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-28  8:54 Otared Kavian
2010-02-28  9:17 ` Wolfgang Schuster [this message]
2010-02-28 11:44   ` Otared Kavian
2010-02-28 11:48     ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B8A349B.6040906@googlemail.com \
    --to=schuster.wolfgang@googlemail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).