On Thu, 29 Jun 2006, Idris Samawi Hamid wrote:

> Dear knights,
>
> I spent a few hours today with MetaPost and MetaFun, my first serious stab at 
> Meta in many years, so I'm a virtual newbie (used PSTricks back in the LaTeX 
> days). I am trying to basically duplicate the attached pdf graphic and need 
> help with the following:
>
> 1. This code is pretty naive; how can I make it more efficient? Eg, can I 
> make a global "scaled 1cm" declaration instead of repeating it so many times?

drawoptions(scaled 1cm) ; , see below.

> 2. ConTeXt's alignment mechanism apparently does not work in MetaPost 
> (alignment is commented); is there a workaround? ragged left needed for some 
> labels.

Use \framed for multiline labels. Infact, what I ususally do is

\forceMPTEXcheck{LABEL}

\startMPinclusions
vardef [EMAIL PROTECTED](expr s, p)= [EMAIL 
PROTECTED](textext("\framed[width=3cm,align=middle,frame=off,autowidth=force, 
strut=on]{" & s & "}"),p)
enddef ;
\stopMPinclusions

and then I can simply use

LABEL.bot("A big huge label that spans multiple lines", origin)

or

LABEL.bot("short",center)

It can be made more efficient using the new sometxt feature. But I do 
not understand the sometxt interaction completely.

> 3. What is the most efficient way to get labels to follow the diagonals as in 
> the attached pdf?

remember, anything inside btex...etex or textext() is just a picture. 
So, you can do

picture p; p := textext("some label");
p := p rotatedaround (center, angle) ;

label.llft(p,center) ;

etc..


> Any tips/trick will be appreciated!
>
> Best
> Idris
> ====================================
> % output=pdf interface=en
>
> \setupcolors[state=start]
>
> \starttext
>
> \noheaderandfooterlines
>
> \startuseMPgraphic{square}
>
> picture p ; p := dashpattern(on 1mm off 1mm) ;
>
> label bot(btex %\hbox to 1.5cm
>               {%\startalignment[left]
>               \vbox{\hsize=1.2cm
>               \ssxx\setupinterlinespace
>               (0,0,0,0) \crlf
>               Light \crlf
>               Condensed
>               Small \crlf
>               Sans~Serif}
>               %\stopalignment
>               }
>               etex, (-1.2cm,0)) ;

Firstly use \textext("string") instead of btex ... etex (assuming you 
have a uptodate context).

For alignment, I find it easiest to use \framed. So in your case
\framed[align=normal,width=1,5cm,font(forgot the switch)=\ssxx]{etc}


> draw (origin -- (0,5) -- (5,5) -- (5,0) -- cycle)
> scaled 1cm withcolor .625red ;
>
> %draw ((2,1) -- (2,6) -- (7,6) -- (7,1) -- cycle)
> %scaled 1cm withcolor .625red ;
>
> draw ((2,6) -- (7,6))
> scaled 1cm withcolor .625red ;
>
> draw ((7,6) -- (7,1))
> scaled 1cm withcolor .625red ;
>
> draw ((2,6) -- (2,5))
> scaled 1cm withcolor .625red ;

you can use

drawoptions(scaled 1cm withcolor .625red) ;

draw(...) ;
draw(...) ;
draw(...) ;


> draw ((2,5) -- (2,1))
> scaled 1cm withcolor .625red dashed p withpen pencircle scaled 0.4pt;
>
> draw ((2,1) -- (5,1))
> scaled 1cm withcolor .625red dashed p withpen pencircle scaled 0.4pt;

same here. Use drawoptions.

> draw ((5,1) -- (7,1))
> scaled 1cm withcolor .625red ;
>
> draw ((0,5) -- (2,6))
> scaled 1cm withcolor .625red ;
>
> draw ((5,5) -- (7,6))
> scaled 1cm withcolor .625red ;
>
> draw ((5,0) -- (7,1))
> scaled 1cm withcolor .625red ;
>
> draw (origin -- (2,1 ))
> scaled 1cm withcolor .625red dashed p withpen pencircle scaled 0.4pt;
>
> \stopuseMPgraphic
>
> \startuseMPgraphic{2squares}
>
> draw (origin -- (0,5) -- (5,5) -- (5,0) -- cycle)
> scaled 1cm withcolor .625red ;
>
> draw ((2,1) -- (2,6) -- (7,6) -- (7,1) -- cycle)
> scaled 1cm withcolor .625red ;
>
> draw ((0,5) -- (2,6))
> scaled 1cm withcolor .625red ;
>
> draw ((5,5) -- (7,6))
> scaled 1cm withcolor .625red ;
>
> draw ((5,0) -- (7,1))
> scaled 1cm withcolor .625red ;
>
> draw (origin -- (2,1 ))
> scaled 1cm withcolor .625red ;
>
> draw ((10,0) -- (10,-5) -- (15,-5) -- (15,0) -- cycle)
> scaled 1cm withcolor .625red ;
>
> draw ((12,1) -- (12,-4) -- (17,-4) -- (17,1) -- cycle)
> scaled 1cm withcolor .625red ;
>
> draw ((10,0) -- (12,1))
> scaled 1cm withcolor .625red ;
>
> draw ((10,-5) -- (12,-4))
> scaled 1cm withcolor .625red ;
>
> draw ((15,-5) -- (17,-4))
> scaled 1cm withcolor .625red ;
>
> draw ((15,0) -- (17,1 ))
> scaled 1cm withcolor .625red ;
>
> % map square to square
>
> picture p ; p := dashpattern(on 1mm off 1mm) ;
>
> draw ((0,5) -- (10,0))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((2,6) -- (12,1))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((0,0) -- (10,-5))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((2,1) -- (12,-4))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((5,5) -- (15,0))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((7,6) -- (17,1))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((5,0) -- (15,-5))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> draw ((7,1) -- (17,-4))
> scaled 1cm dashed p withpen pencircle scaled 0.4pt withcolor .625red ;
>
> \stopuseMPgraphic

I would also probably number the points, so that they are easier to 
refer to

pair z[];

z[1] := (0,0) ;
z[2] := (0,5) ;
z[3] := (5,0) ;
z[4] := (5,5) ;

etc.

and then

draw (z[1]--z[2]--z[3]--z[4]--cycle) ;

etc.


> \midaligned{\useMPgraphic{square}}
>
> \hbox{}\blank[5*big]
>
> \useMPgraphic{2squares}
>
> \stoptext


If the graphic is to be used a figure in the document (and not an a 
background graphic of some overlay), you may also want to consider the 
new staticMPgraphic feature. See 
http://wiki.contextgarden.net/Mpgraphic for details. The advantage is 
that an external pdf containing the graphic is created once, and is 
simply included in subsequent runs. It is regenerated only if you make 
some change in the metapost code. So usually the compilation is 
faster.

Aditya

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to