Hi, I am looking for a way to assign the value of a TeX macro to an MP variable. However, this only works the first time, then the value is not updated any longer. Example: \startMPdefinitions size = \somesize ; \stopMPdefinitions \startuseMPgraphic{alpha} fill unitcircle scaled size; \stopuseMPgraphic \starttext \def\somesize{1cm} \useMPgraphic{alpha} %% diameter = 1cm \def\somesize{2cm} \useMPgraphic{alpha} %% diameter = 1cm \stoptext I looked into \setupMPvariables, but I couldn't manage to assign them to an MP variable. The setups key from \defineMPinstance seems to to the job, but it's TeX, not MetaPost. What comes to mind is a \processMPbuffer before every MPgraphic: \startbuffer[foo] size := \somesize ; \stopbuffer \startuseMPgraphic{alpha} fill unitcircle scaled size; \stopuseMPgraphic \starttext \def\somesize{1cm} \processMPbuffer[foo] \useMPgraphic{alpha} %% diameter = 1cm \def\somesize{2cm} \processMPbuffer[foo] \useMPgraphic{alpha} %% diameter = 2cm \stoptext Is there a better way? Marco
On 03/16/2013 04:07 PM, Marco Patzer wrote:
Hi,
I am looking for a way to assign the value of a TeX macro to an MP variable. However, this only works the first time, then the value is not updated any longer. Example:
I'm not quite sure if this is what you're looking for, but here is an example how you could do this with \MPvars: \def\Circlediameter{15mm} \def\setupCircle#1[#2]% {\getparameters[Circle][diameter=15mm,#2]} \setupMPvariables [mycircle] [diameter=\Circlediameter, ] \startuseMPgraphic{mycircle} fill unitcircle scaled \MPvar{diameter} withcolor red ; \stopuseMPgraphic \starttext \useMPgraphic{mycircle} \blank[1cm] \setupCircle[diameter=5cm] \useMPgraphic{mycircle} \blank[1cm] \setupCircle[diameter=0.5cm] \useMPgraphic{mycircle} \stoptext Thomas
On 2013–03–16 Thomas A. Schmitz wrote:
I'm not quite sure if this is what you're looking for, but here is an example how you could do this with \MPvars:
\def\Circlediameter{15mm}
\def\setupCircle#1[#2]% {\getparameters[Circle][diameter=15mm,#2]}
\setupMPvariables [mycircle] [diameter=\Circlediameter, ]
\startuseMPgraphic{mycircle} fill unitcircle scaled \MPvar{diameter} withcolor red ; \stopuseMPgraphic
The above works in the larger document, but a construct like this fails: \startuseMPgraphic{mycircle} mysize := \MPvar{diameter}; fill unitcircle scaled mysize withcolor red ; \stopuseMPgraphic However, in the minimal example it works, too. So the problem lies be somewhere else. I will investigate why it fails. I like the MPvar solution and try to get it working. Thanks Marco
Am 16.03.2013 um 17:13 schrieb Marco Patzer
On 2013–03–16 Thomas A. Schmitz wrote:
\setupMPvariables [mycircle] [diameter=\Circlediameter, ]
MPvariables are local to a particular MP graphic. I need a way to set the variables global to all MPgraphics of that MP instance.
http://www.ntg.nl/pipermail/ntg-context/2013/071538.html Wolfgang
On 2013–03–16 Wolfgang Schuster wrote:
Well, I played with all possible environments, but there is no environment local to a particular MP instance which is re-read on every MP graphic. The only usable environment in this case is MPinitializations, but the values affect all MP instances. I will settle for MPinitializations until I find a better solution, it allows for a cleaner code compared to the MPbuffer workaround. But still, I would prefer to have the setting non-global. Marco
On Sat, 16 Mar 2013, Marco Patzer wrote:
On 2013–03–16 Thomas A. Schmitz wrote:
\setupMPvariables [mycircle] [diameter=\Circlediameter, ]
MPvariables are local to a particular MP graphic. I need a way to set the variables global to all MPgraphics of that MP instance.
See the visualcounter module for an alternative way to pass values from TeX to MP. Basically, I define a namespace and then just access the parameters at MP end using somvar := \....parameter{...}; etc. Aditya
On 3/16/2013 4:07 PM, Marco Patzer wrote:
Hi,
I am looking for a way to assign the value of a TeX macro to an MP variable. However, this only works the first time, then the value is not updated any longer. Example:
\startMPdefinitions size = \somesize ; \stopMPdefinitions
\startuseMPgraphic{alpha} fill unitcircle scaled size; \stopuseMPgraphic
\starttext \def\somesize{1cm} \useMPgraphic{alpha} %% diameter = 1cm
\def\somesize{2cm} \useMPgraphic{alpha} %% diameter = 1cm \stoptext
I looked into \setupMPvariables, but I couldn't manage to assign them to an MP variable. The setups key from \defineMPinstance seems to to the job, but it's TeX, not MetaPost. What comes to mind is a \processMPbuffer before every MPgraphic:
\startbuffer[foo] size := \somesize ; \stopbuffer
\startuseMPgraphic{alpha} fill unitcircle scaled size; \stopuseMPgraphic
\starttext \def\somesize{1cm} \processMPbuffer[foo] \useMPgraphic{alpha} %% diameter = 1cm
\def\somesize{2cm} \processMPbuffer[foo] \useMPgraphic{alpha} %% diameter = 2cm \stoptext
Is there a better way?
grep for \includeMPgraphic -- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2013–03–16 Hans Hagen wrote:
Is there a better way?
grep for \includeMPgraphic
Well, I know \includeMPgraphic but the combination of \includeMPgraphic and \MPvar is very creative, indeed. But it's a little tricky to find out what code actually gets included. Obviously there are plenty of solutions to pass from TeX to MP. Marco
participants (5)
-
Aditya Mahajan
-
Hans Hagen
-
Marco Patzer
-
Thomas A. Schmitz
-
Wolfgang Schuster