From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/84943 Path: news.gmane.org!not-for-mail From: "Keith J. Schultz" Newsgroups: gmane.comp.tex.context Subject: Need help defining command. Date: Tue, 22 Oct 2013 10:34:56 +0200 Message-ID: <563CA660-912A-4857-9AA4-FB16AAD438EA@uni-trier.de> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1382430905 780 80.91.229.3 (22 Oct 2013 08:35:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Oct 2013 08:35:05 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Oct 22 10:35:10 2013 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VYXQj-0007vy-5y for gctc-ntg-context-518@m.gmane.org; Tue, 22 Oct 2013 10:35:09 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 9CEF21021B; Tue, 22 Oct 2013 10:32:12 +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 KXhrimpQ2Qfc; Tue, 22 Oct 2013 10:32:10 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 3FBAC10210; Tue, 22 Oct 2013 10:32:10 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id D09F510210 for ; Tue, 22 Oct 2013 10:32:08 +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 M9zmj+zrga58 for ; Tue, 22 Oct 2013 10:32:06 +0200 (CEST) Original-Received: from filter4-ams.mf.surf.net (filter4-ams.mf.surf.net [192.87.102.72]) by balder.ntg.nl (Postfix) with ESMTP id 0C20210205 for ; Tue, 22 Oct 2013 10:32:06 +0200 (CEST) Original-Received: from mx2.uni-trier.de (mx2.uni-trier.de [136.199.224.18]) by filter4-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id r9M8dtTb006111 for ; Tue, 22 Oct 2013 10:39:57 +0200 X-IronPort-AV: E=Sophos;i="4.93,546,1378850400"; d="scan'208";a="7937184" Original-Received: from rzmail.uni-trier.de ([136.199.8.220]) by mx2i.uni-trier.de with ESMTP; 22 Oct 2013 10:34:56 +0200 Original-Received: from [10.0.62.5] (dslb-084-059-011-127.pools.arcor-ip.net [84.59.11.127]) by rzmail.uni-trier.de (Postfix) with ESMTPA id 8E4423FEDB for ; Tue, 22 Oct 2013 10:34:56 +0200 (CEST) X-Mailer: Apple Mail (2.1510) X-Bayes-Prob: 0.9808 (Score 4.7, tokens from: @@RPTN) X-CanIt-Geo: ip=136.199.224.18; country=DE; region=08; city=Trier; latitude=49.7500; longitude=6.6333; http://maps.google.com/maps?q=49.7500,6.6333&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 01KE8DT56 - 5250b2c6b8ca - 20131022 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.72 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:84943 Archived-At: HI All, I remember seeing some seeing what I want to do but I can not find it. I would like to define a command that takes an optional key-valued list and 1 or 2 manditory ones. Something like \unexanded\def\MyCommand[#1]#2% {% \NassiGroupFrame[#1]{#2}% }% or \unexanded\def\MyCommand[#1]#2% {% % extract keyvalue \NassiGroupFrame[\width=\extractedvalueone]{hbox to \extractvaletwo{#2}}% }% where \NassiGroupFrame is a Frame. To give you an idea why I need this see the MWE below. This is a relatively simple example, there will be more complicated frames and they will be nested. Maybe I am chasing windmills and there is a better way and I should use cld or lua for outputing the Frames so that I can have spacing between the command and avoid having to use "%" after the first opening "{". Or does someone know how it can be done. Is there a way to use ConTeXt to write the command Pointers, help welcome. MWE: %%%%%%%%%%%%%%%%%%%%% %% NassiSimpleFrameBox %% %% Draw a box around a frame using exact height %% and width. to use it use overlay NassiSimpleFrameBox %% \startuniqueMPgraphic{NassiSimpleFrameBox} pickup pencircle scaled \overlaylinewidth ; draw (0,0) -- (0, OverlayHeight) -- (OverlayWidth, OverlayHeight) -- (OverlayWidth, 0) -- cycle withcolor OverlayLineColor; \stopuniqueMPgraphic %% Define Overlay for NassiSimpleFrameBox %% \defineoverlay[NassiSimpleFrameBox][\uniqueMPgraphic{NassiSimpleFrameBox}] %% %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% %% NassiGroupFrameBox %% %% Draw a box around a frame which contains several %% structures. Since the frame size containing the structures %% has a \rulethickness frame around then we have to adjust %% so that we can draw on top of its bounding box %% \startuniqueMPgraphic{NassiGroupFrameBox} numeric DoubleLineWidth, TrueWidth, TrueHeight; DoubleLineWidth := 2 * OverlayLineWidth; TrueHeight := OverlayHeight - DoubleLineWidth; TrueWidth := OverlayWidth - DoubleLineWidth; pickup pencircle scaled OverlayLineWidth; draw (0,0) -- (0, TrueHeight) -- (TrueWidth, TrueHeight) -- (TrueWidth, 0) -- cycle withcolor OverlayLineColor; \stopuniqueMPgraphic \defineoverlay[NassiGroupFrameBox][\uniqueMPgraphic{NassiGroupFrameBox}] %% %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% %% NassiSimpleFrame %% %% Frame for putting a frame around it. %% Location is set so that they can be stack %% on top of each other. \defineframed[NassiSimpleFrame] \setupframed[NassiSimpleFrame] [width=5cm, frame=off, background=NassiSimpleFrameBox, rulethickness=1pt, framecolor=blue, offset=0pt, frameoffset=0pt, location=lohi] %% %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%% %% NassiGroupFrame %% %% Frame for putting a frame around a block of %% structures. Since it surrounds a group we use %% fit for Height and Width. %% So that the The frame gets draw on top that the %% the background has to be setup accordingly. \defineframed[NassiGroupFrame] \setupframed[NassiGroupFrame] [width=fit, height=fit, frame=off, rulethickness=3pt, framecolor=green, offset=0pt, background={foreground, NassiGroupFrameBox}, frameoffset=0pt, align=middle, strut=no] %% %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%% %% Frame a Statement %% The text inside the frame is adjust to %% leave room for the frame \unexpanded\def\Statement#1% {% \NassiSimpleFrame[width=5cm,framecolor=red]{\vbox{\hsize \dimexpr\framedparameter{width} * 9/10\relax \strut #1}}% }% \unexpanded\def\MyGroup#1% {% \NassiGroupFrame{\hbox to 10cm% {#1}} }% \unexpanded\def\MyBlock#1% {% \vtop{{\hsize 5cm#1}}% }% \starttext \NassiGroupFrame{% \vbox{\hsize 5cm% \Statement{This is a test This is a test This is a test This is a test This is a test This is a test} \Statement{This $is^a$ test } \Statement{This $is^a$ test This is a test This is a test This is a test This is a test This is a test} }} \MyGroup{% How do I avoid comment here \MyBlock{ \Statement{This is a test This is a test This is a test This is a test This is a test This is a test} \Statement{This $is^a$ test } }% How do I avoid comment here \MyBlock{\Statement{This is a test This is a test This is a test This is a test This is a test This is a test} } } \stoptext regards Keith. ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________