From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/33528 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 17:56:48 -0500 (EST) Message-ID: References: <45E00AE2.5000405@elvenkind.com> <45E01F6F.8080401@wxs.nl> 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 1172357839 31986 80.91.229.12 (24 Feb 2007 22:57:19 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 24 Feb 2007 22:57:19 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Feb 24 23:57:10 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 1HL5pG-0003cN-6Q for gctc-ntg-context-518@m.gmane.org; Sat, 24 Feb 2007 23:57:10 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 403482028F; Sat, 24 Feb 2007 23:53:59 +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 28728-03; Sat, 24 Feb 2007 23:53:49 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id D3955202A1; Sat, 24 Feb 2007 23:53:49 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 53C76202C4 for ; Sat, 24 Feb 2007 23:53:48 +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 28692-07 for ; Sat, 24 Feb 2007 23:53:44 +0100 (CET) Original-Received: from tombraider.mr.itd.umich.edu (smtp.mail.umich.edu [141.211.93.161]) by ronja.ntg.nl (Postfix) with ESMTP id A703E2028F for ; Sat, 24 Feb 2007 23:53:43 +0100 (CET) Original-Received: FROM aditya.annarb01.mi.comcast.net (c-68-40-50-205.hsd1.mi.comcast.net [68.40.50.205]) BY tombraider.mr.itd.umich.edu ID 45E0C2B2.32922.20057 ; 24 Feb 2007 17:56:50 -0500 In-Reply-To: <45E01F6F.8080401@wxs.nl> 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:33528 Archived-At: On Sat, 24 Feb 2007, Hans Hagen wrote: > 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) Yes, those were parts of the core that I could never understand. Now, I do understand them a little. Thanks, Aditya