From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/33518 Path: news.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: Question about defining a math macro Date: Sat, 24 Feb 2007 04:59:41 -0500 (EST) Message-ID: References: <45E00AE2.5000405@elvenkind.com> 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 1172311209 550 80.91.229.12 (24 Feb 2007 10:00:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 24 Feb 2007 10:00:09 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Feb 24 11:00:03 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 1HKthB-0005Wc-KM for gctc-ntg-context-518@m.gmane.org; Sat, 24 Feb 2007 11:00:01 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 9A74D201B9; Sat, 24 Feb 2007 10:56:56 +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 14745-04-3; Sat, 24 Feb 2007 10:56:47 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 9A02C201C8; Sat, 24 Feb 2007 10:56:47 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id A3EEF201CA for ; Sat, 24 Feb 2007 10:56:45 +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 14745-04-2 for ; Sat, 24 Feb 2007 10:56:39 +0100 (CET) Original-Received: from skycaptain.mr.itd.umich.edu (smtp.mail.umich.edu [141.211.93.160]) by ronja.ntg.nl (Postfix) with ESMTP id 48B56201B9 for ; Sat, 24 Feb 2007 10:56:39 +0100 (CET) Original-Received: FROM aditya.annarb01.mi.comcast.net (c-68-40-50-205.hsd1.mi.comcast.net [68.40.50.205]) BY skycaptain.mr.itd.umich.edu ID 45E00C8E.653A8.4925 ; 24 Feb 2007 04:59:42 -0500 In-Reply-To: <45E00AE2.5000405@elvenkind.com> 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:33518 Archived-At: 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