From: "Keith J. Schultz" <schultzk@uni-trier.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Need help defining command.
Date: Tue, 22 Oct 2013 10:34:56 +0200 [thread overview]
Message-ID: <563CA660-912A-4857-9AA4-FB16AAD438EA@uni-trier.de> (raw)
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
___________________________________________________________________________________
next reply other threads:[~2013-10-22 8:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 8:34 Keith J. Schultz [this message]
2013-10-22 9:31 ` Wolfgang Schuster
2013-10-22 12:45 ` Keith J. Schultz
2013-10-22 12:50 ` Keith J. Schultz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=563CA660-912A-4857-9AA4-FB16AAD438EA@uni-trier.de \
--to=schultzk@uni-trier.de \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).