Need help defining command.
![](https://secure.gravatar.com/avatar/5427eeee9a9c013c071bd4d1a438f969.jpg?s=120&d=mm&r=g)
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.
![](https://secure.gravatar.com/avatar/b79687264c3e06cba13b54d05b12a9f5.jpg?s=120&d=mm&r=g)
Am 22.10.2013 um 10:34 schrieb Keith J. Schultz
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}% }%
\unexanded\def\MyCommand {\dosingleempty\doMyCommand} \def\doMyCommand[#1]#2% {\NassiGroupFrame[#1]{#2}}
or
\unexanded\def\MyCommand[#1]#2% {% % extract keyvalue \NassiGroupFrame[\width=\extractedvalueone]{hbox to \extractvaletwo{#2}}% }%
\unexanded\def\MyCommand {\dosingleempty\doMyCommand} \def\doMyCommand[#1]#2% {\begingroup \getdummyparameters[valueone=6cm,valuetwo=5cm,#1] \NassiGroupFrame[width=\dummyparameter{valueone}]{\hbox to \dummyparameter{valuetwo}{#2}}% \endgroup} \MyCommand[valuetwo=4cm]{...}
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
There are ways to ignore the spaces at the begin (\ignorespaces) and end (\removeunwantedspaces) of a group but you should rethink first your interface for your commands (why no start/stop commands). It can be also useful to draw the whole diagram with Metapost and use the TeX commands only to pass the content to Metapost. Wolfgang
![](https://secure.gravatar.com/avatar/5427eeee9a9c013c071bd4d1a438f969.jpg?s=120&d=mm&r=g)
Hi Wolfgang,
to be honest one of my design considerations was to this work using MetaPost.
But, my knowledge of MetaPost is minimal and it would be involved calculating the positions
of the Frames/boxes and I need to know the sizes of the formatted text, etc
Another approach would be to use layer, but I can not find much documentation about how/if
they can be used inside of a frame.
regards
Keith
Am 22.10.2013 um 11:31 schrieb Wolfgang Schuster
There are ways to ignore the spaces at the begin (\ignorespaces) and end (\removeunwantedspaces) of a group but you should rethink first your interface for your commands (why no start/stop commands).
It can be also useful to draw the whole diagram with Metapost and use the TeX commands only to pass the content to Metapost.
![](https://secure.gravatar.com/avatar/5427eeee9a9c013c071bd4d1a438f969.jpg?s=120&d=mm&r=g)
Hi Wolfgang,
Am 22.10.2013 um 11:31 schrieb Wolfgang Schuster
Am 22.10.2013 um 10:34 schrieb Keith J. Schultz
: 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}% }%
\unexanded\def\MyCommand {\dosingleempty\doMyCommand}
\def\doMyCommand[#1]#2% {\NassiGroupFrame[#1]{#2}}
or
\unexanded\def\MyCommand[#1]#2% {% % extract keyvalue \NassiGroupFrame[\width=\extractedvalueone]{hbox to \extractvaletwo{#2}}% }%
\unexanded\def\MyCommand {\dosingleempty\doMyCommand}
\def\doMyCommand[#1]#2% {\begingroup \getdummyparameters[valueone=6cm,valuetwo=5cm,#1] \NassiGroupFrame[width=\dummyparameter{valueone}]{\hbox to \dummyparameter{valuetwo}{#2}}% \endgroup}
\MyCommand[valuetwo=4cm]{...}
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
There are ways to ignore the spaces at the begin (\ignorespaces) and end (\removeunwantedspaces) of a group but you should rethink first your interface for your commands (why no start/stop commands).
I thought about that, but I do not know I could use start/-commands in this context! regards Keith
participants (2)
-
Keith J. Schultz
-
Wolfgang Schuster