From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/33516 Path: news.gmane.org!not-for-mail From: Taco Hoekwater Newsgroups: gmane.comp.tex.context Subject: Re: Question about defining a math macro Date: Sat, 24 Feb 2007 10:52:34 +0100 Message-ID: <45E00AE2.5000405@elvenkind.com> References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1172310787 31935 80.91.229.12 (24 Feb 2007 09:53:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 24 Feb 2007 09:53:07 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Feb 24 10:52:57 2007 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1HKtaL-0002gt-Gf for gctc-ntg-context-518@m.gmane.org; Sat, 24 Feb 2007 10:52:57 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 3DAFB20181; Sat, 24 Feb 2007 10:49:52 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 14516-03; Sat, 24 Feb 2007 10:49:42 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 7C4E32016E; Sat, 24 Feb 2007 10:49:42 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 4565B20181 for ; Sat, 24 Feb 2007 10:49:37 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 14543-09-2 for ; Sat, 24 Feb 2007 10:49:28 +0100 (CET) Original-Received: from post-25.mail.nl.demon.net (post-25.mail.nl.demon.net [194.159.73.195]) by ronja.ntg.nl (Postfix) with ESMTP id CE24020167 for ; Sat, 24 Feb 2007 10:49:28 +0100 (CET) Original-Received: from boo.demon.nl ([82.161.175.147]:57673 helo=[10.10.0.6]) by post-25.mail.nl.demon.net with esmtp (Exim 4.51) id 1HKtZw-000GnD-Q2 for ntg-context@ntg.nl; Sat, 24 Feb 2007 09:52:32 +0000 User-Agent: Thunderbird 1.5.0.9 (X11/20070105) In-Reply-To: X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.9 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:33516 Archived-At: 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. Cheers, Taco