From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/78403 Path: news.gmane.org!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: need help with macro Date: Sun, 23 Sep 2012 16:00:29 +0200 Message-ID: References: <20120923133354.GA29608@phlegethon.router_intern> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 6.1 \(1498\)) Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1348408842 28867 80.91.229.3 (23 Sep 2012 14:00:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 23 Sep 2012 14:00:42 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Sep 23 16:00:47 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TFmjj-0006SQ-CY for gctc-ntg-context-518@m.gmane.org; Sun, 23 Sep 2012 16:00:43 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 310EA101F4; Sun, 23 Sep 2012 16:00:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id OsCTn7058wpt; Sun, 23 Sep 2012 16:00:36 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 20B55101E8; Sun, 23 Sep 2012 16:00:36 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 214DD101E8 for ; Sun, 23 Sep 2012 16:00:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id s0tnE3fKyCId for ; Sun, 23 Sep 2012 16:00:33 +0200 (CEST) Original-Received: from filter3-til.mf.surf.net (filter3-til.mf.surf.net [194.171.167.219]) by balder.ntg.nl (Postfix) with ESMTP id 57CF7101E2 for ; Sun, 23 Sep 2012 16:00:33 +0200 (CEST) Original-Received: from mail-bk0-f41.google.com (mail-bk0-f41.google.com [209.85.214.41]) by filter3-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q8NE0WD6004840 for ; Sun, 23 Sep 2012 16:00:32 +0200 Original-Received: by bkcjc3 with SMTP id jc3so2681162bkc.14 for ; Sun, 23 Sep 2012 07:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=R24dSBxdFDe2neZoehpg3VJu9Bw6r9aw4o9HlA+FrPc=; b=DMwjsSXbHfF2dprGXG+wKRsqrpk1smlUDFVc7j4LGNKaJRLx9YI1zEba1NIDQcUW5c ilW0FuoeZXI6p2KCmNX7D1d+JprWF9dAHWQmVvtRZ1TIvaPUYwPfM4H+RZ4zvFlGfpXT 7wzPNlbiFofY8In6jdQiBYmqyPWon/RYclV6kYxr37yfInaKL7ec9b1rgi2UqZfjGcMh ohJeW56OBrfDUCYqrtn+u4Vql7LlwUd5S4kJhLYTf/HX2A2Z33UL5BvR2rWCEmXMtU8t hoc9wKqkflWHbqJ9OPzFt5x3dOTDXVs172sWxWrrnMWFdulk9VCsN0Wy2v/5WVn+f3ni Lj9A== Original-Received: by 10.204.128.65 with SMTP id j1mr3736318bks.93.1348408832205; Sun, 23 Sep 2012 07:00:32 -0700 (PDT) Original-Received: from keima.localdomain (nrbg-4dbe76c9.pool.mediaWays.net. [77.190.118.201]) by mx.google.com with ESMTPS id t23sm8659120bks.4.2012.09.23.07.00.30 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 23 Sep 2012 07:00:31 -0700 (PDT) In-Reply-To: <20120923133354.GA29608@phlegethon.router_intern> X-Mailer: Apple Mail (2.1498) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.214.41; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 06I2C0wAA - 90ba35e1eef1 - 20120923 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.219 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:78403 Archived-At: Am 23.09.2012 um 15:33 schrieb Philipp Gesang : > Hi all, > = > I have a macro =93mogrify=94 that eats three tokens of a string and > treats them differently from the rest of the string. I can=92t > however use it inside more complex macros. Is there a way out or > an alternative using macros? (No Lua.) Other formatting macros > work fine in the same place. > = > Any help will be greatly appreciated > Philipp > = > =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7 Example Code =B7=B7=B7=B7=B7=B7= =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7= =B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7=B7 > % macros=3Dmkvi > = > \unprotect > = > \def\mogrify#content{% > \begingroup > \let\stopper\relax > \def\get_first_three##1##2##3##4\stopper{% > \def\first_three{##1##2##3}% > \def\rest{##4}% > }% > \get_first_three#content\stopper% > \colored[red]{\first_three}% > \colored[green]{\rest}% > \endgraf > \endgroup% > } > = > \installnamespace {ww} > \installcommandhandler \????ww {ww} \????ww > = > \appendtoks > \setuevalue{\currentww}{\wont_work[\currentww]} > \to \everydefineww > = > \unexpanded\def\wont_work[#id]{% > \edef\current_wont_work{#id}% > \dosingleempty\wont_work_indeed% > } > = > \def\wont_work_indeed[#setups]#content{% > \iffirstargument\setupcurrentww[#setups]\fi > %% here is the problem: > \doifsomething{\wwparameter{param}}{\mogrify{\wwparameter{param}}}% > \endgraf > \framed{#content}% > } > = > \defineww[wontwork] > = > \protect > = > \starttext > = > \mogrify{foobar}\par%% the macro does work in isolation > = > \wontwork[param=3Dwhatever]{will it work?} > \wontwork[param=3D] {this, however, does work} > = > \stoptext It=92s a expansion problem, you can either expand the content in the defini= tion of \mogrify (as seen below) or you make the \mogrify command unexpanded and you expand the content of t= he \wwparameter (i.e. \doifsomething{=85}{\normalexpanded{\mogrify{=85}}}) \unprotect \def\mogrify_scan#first#second#third#rest\relax {\def\m_mogrify_three{#first#second#third}% \def\m_mogrify_rest {#rest}} \def\mogrify#content% {\begingroup \edef\m_mogrify_content{#content}% \expandafter\mogrify_scan\m_mogrify_content\relax \colored [red]{\m_mogrify_three}% \colored[green]{\m_mogrify_rest }% \endgraf \endgroup} \installnamespace {ww} \installcommandhandler \????ww {ww} \????ww \appendtoks \setuevalue{\currentww}{\wont_work[\currentww]} \to \everydefineww \unexpanded\def\wont_work[#id]% {\edef\currentww{#id}% \dosingleempty\wont_work_indeed} \def\wont_work_indeed[#setups]#content% {\iffirstargument\setupcurrentww[#setups]\fi \doifsomething{\wwparameter{param}}{\mogrify{\wwparameter{param}}}% \endgraf \framed{#content}} \defineww[wontwork] \protect \starttext \mogrify{foobar}\par%% the macro does work in isolation \wontwork[param=3Dwhatever]{will it work?} \wontwork[param=3D] {this, however, does work} \stoptext Wolfgang ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________