[NTG-context] scaling reusableMPgraphic & some ConTeXt programming

Hans Hagen pragma at wxs.nl
Mon Jul 24 11:03:19 CEST 2006


Mojca Miklavec wrote:
> Hello,
>
> the answers to these three questions are most probably one-liners, but
> I don't know which ones ;)
>
> 1. How can I scale (an already defined) reusableMPgraphic? Simplified
> example of what I currently (want to) have:
>
> % how should I change this definition?
> \def\usemygraphic[#1][#2]{\reuseMPgraphic{#1}}
> \usemygraphic[name][width=.7\textwidth]
>   
\def\usemygraphic[#1][#2]{\scale[#2]{\reuseMPgraphic{#1}}

\usempgraphic[name][width=4cm,height=5cm]

\scale accepts the same scaling options as externalfigure

>
> 2. I have several graphics defined as
>
> \startGNUPLOTgraphic[1][name]
> 	draw fullcircle scaled 3cm withcolor .625red;
> \stopGNUPLOTgraphic
> \startGNUPLOTgraphic[2][name]
> 	draw fullcircle scaled 3cm withcolor .625green;
> \stopGNUPLOTgraphic
> \startGNUPLOTgraphic[3][name]
> 	draw fullcircle scaled 3cm withcolor .625blue;
> \stopGNUPLOTgraphic
>
> \startGNUPLOTgraphic[1][othername]
> 	fill fullcircle scaled 3cm withcolor .625red;
> \stopGNUPLOTgraphic
> \startGNUPLOTgraphic[2][othername]
> 	fill fullcircle scaled 3cm withcolor .625green;
> \stopGNUPLOTgraphic
>
> and a pretty stupid definition:
>
> \long\def\startGNUPLOTgraphic
> 	{\dodoubleargument\dostartGNUPLOTgraphic}
>
> \long\def\dostartGNUPLOTgraphic[#1][#2]#3\stopGNUPLOTgraphic % [number][name]
> 	{% add to counter to note the nuber of the graphic
>          % define a new counter for the first time when you use it
> 	 \doif{#1}{1}{\doglobal\newcounter\abc}% counter name has to depend on #2
> 	 \doglobal\increment\abc % assigning the value #1 to it would also be OK
> 	 \startreusableMPgraphic{gpg:#2:#1}#3\stopreusableMPgraphic}
>
> How can I give a better name than \abc to the counter (the name should
> depend on #2 in order to be unique)?
>   
why do you need a counter

\long\def\dostartGNUPLOTgraphic[#1][#2]#3\stopGNUPLOTgraphic
  {\startreusableMPgraphic{gpg:#2:#1}#3\stopreusableMPgraphic}


>
> 3. I would like to change \usemygraphic, so that
> \usemygraphic[othername] or \usemygraphic[othername][height=5cm] would
> resolve to
>     \dorecurse{2}{\useMPgraphic{gpg:othername:\recurselevel}}
> and \usemygraphic[name][n={1,3},width=8cm] (syntax might be different
> if necessary) to
>     \reuseMPgraphic{gpg:name:1}
>     \reuseMPgraphic{gpg:name:3}
> (with proper scaling if possible).
>   
you want all graphics?

\def\usemygraphic#1%
  {\doloop
     {\doifMPgraphicelse{gpg:#1:\recurselevel}
        {\reuseMPgraphic{gpg:name:\recurselevel}}
        {\exitloop}}} 

or so ... 


Hans 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------



More information about the ntg-context mailing list