ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Question about defining a math macro
Date: Sat, 24 Feb 2007 04:59:41 -0500 (EST)	[thread overview]
Message-ID: <alpine.WNT.0.82.0702240457380.484@nqvgln> (raw)
In-Reply-To: <45E00AE2.5000405@elvenkind.com>

On Sat, 24 Feb 2007, Taco Hoekwater wrote:

> Aditya Mahajan wrote:
>> Hi,
>>
>> Can I define a math macro, say \EXP that does the following:
>>
>> 1) \EXP{something} gives me, say E(something)
>> 2) \EXP_a^b{something} gives my E_a^b(something)
>>
>> That is, I want to write a macro that will only be used in the math
>> mode, that does something with its argument. But, I also want it to
>> handle _ and ^ if they are present.
>>
>> The only method that I can think of is to check _ or ^ with
>> \ifnextcharacter and go through all 5 cases (nothing, only _, only ^,
>> _ followed by ^, ^ followed by _) but this seems very inefficient. Is
>> there a better way?
>
> Actually, there is, by using a bit of black magic in the
> macro definition:
>
>   \def\EXP#1#{\bgroup\def\EXParg{#1}\doEXP}
>   \def\doEXP#1{\mfunction{E}\EXParg({\rm #1})\egroup}
>
> That extra hash mark has the effect of putting everything
> upto the next explicit left brace into #1.

Wow Taco. This is great.

Thanks,
Aditya

  reply	other threads:[~2007-02-24  9:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-24  8:55 Aditya Mahajan
2007-02-24  9:52 ` Taco Hoekwater
2007-02-24  9:59   ` Aditya Mahajan [this message]
2007-02-24 11:20     ` Hans Hagen
2007-02-24 22:56       ` Aditya Mahajan

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=alpine.WNT.0.82.0702240457380.484@nqvgln \
    --to=adityam@umich.edu \
    --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).