From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/33520 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: Question about defining a math macro Date: Sat, 24 Feb 2007 12:20:15 +0100 Message-ID: <45E01F6F.8080401@wxs.nl> 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 1172316054 12886 80.91.229.12 (24 Feb 2007 11:20:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 24 Feb 2007 11:20:54 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Feb 24 12:20:37 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 1HKux8-0003Zt-Rc for gctc-ntg-context-518@m.gmane.org; Sat, 24 Feb 2007 12:20:34 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 345772003A; Sat, 24 Feb 2007 12:17:29 +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 16058-04; Sat, 24 Feb 2007 12:17:22 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 832091FD09; Sat, 24 Feb 2007 12:17:22 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 9E8ED1FF15 for ; Sat, 24 Feb 2007 12:17:20 +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 16095-05 for ; Sat, 24 Feb 2007 12:17:17 +0100 (CET) Original-Received: from mail.pragma-ade.net (dsl-083-247-100-017.solcon.nl [83.247.100.17]) by ronja.ntg.nl (Postfix) with ESMTP id 1214E1FB40 for ; Sat, 24 Feb 2007 12:17:17 +0100 (CET) Original-Received: from [10.100.1.101] (unverified [10.100.1.101]) by controller-1 (SurgeMail 3.7b8) with ESMTP id 10447 for ; Sat, 24 Feb 2007 12:20:14 +0100 User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) In-Reply-To: X-Server: High Performance Mail Server - http://surgemail.com r=-274017400 X-Authenticated-User: hagen@controller-1 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:33520 Archived-At: Aditya Mahajan wrote: > 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. > some applications of this mechanism can be found in the context source code (supp-box etc) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------