ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Need help defining command.
@ 2013-10-22  8:34 Keith J. Schultz
  2013-10-22  9:31 ` Wolfgang Schuster
  0 siblings, 1 reply; 4+ messages in thread
From: Keith J. Schultz @ 2013-10-22  8:34 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-22 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-22  8:34 Need help defining command Keith J. Schultz
2013-10-22  9:31 ` Wolfgang Schuster
2013-10-22 12:45   ` Keith J. Schultz
2013-10-22 12:50   ` Keith J. Schultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).