* TeX macro to MP variable
@ 2013-03-16 15:07 Marco Patzer
2013-03-16 15:37 ` Thomas A. Schmitz
2013-03-16 21:46 ` Hans Hagen
0 siblings, 2 replies; 10+ messages in thread
From: Marco Patzer @ 2013-03-16 15:07 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1055 bytes --]
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
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 15:07 TeX macro to MP variable Marco Patzer
@ 2013-03-16 15:37 ` Thomas A. Schmitz
2013-03-16 15:47 ` Marco Patzer
2013-03-16 16:13 ` Marco Patzer
2013-03-16 21:46 ` Hans Hagen
1 sibling, 2 replies; 10+ messages in thread
From: Thomas A. Schmitz @ 2013-03-16 15:37 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 15:37 ` Thomas A. Schmitz
@ 2013-03-16 15:47 ` Marco Patzer
2013-03-16 16:13 ` Marco Patzer
1 sibling, 0 replies; 10+ messages in thread
From: Marco Patzer @ 2013-03-16 15:47 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 879 bytes --]
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
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 15:37 ` Thomas A. Schmitz
2013-03-16 15:47 ` Marco Patzer
@ 2013-03-16 16:13 ` Marco Patzer
2013-03-16 17:08 ` Wolfgang Schuster
2013-03-17 0:11 ` Aditya Mahajan
1 sibling, 2 replies; 10+ messages in thread
From: Marco Patzer @ 2013-03-16 16:13 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 267 bytes --]
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.
Marco
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 16:13 ` Marco Patzer
@ 2013-03-16 17:08 ` Wolfgang Schuster
2013-03-16 17:36 ` Marco Patzer
2013-03-17 0:11 ` Aditya Mahajan
1 sibling, 1 reply; 10+ messages in thread
From: Wolfgang Schuster @ 2013-03-16 17:08 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 16.03.2013 um 17:13 schrieb Marco Patzer <homerow@lavabit.com>:
> 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
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 17:08 ` Wolfgang Schuster
@ 2013-03-16 17:36 ` Marco Patzer
0 siblings, 0 replies; 10+ messages in thread
From: Marco Patzer @ 2013-03-16 17:36 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 568 bytes --]
On 2013–03–16 Wolfgang Schuster wrote:
> http://www.ntg.nl/pipermail/ntg-context/2013/071538.html
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
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 15:07 TeX macro to MP variable Marco Patzer
2013-03-16 15:37 ` Thomas A. Schmitz
@ 2013-03-16 21:46 ` Hans Hagen
2013-03-17 13:14 ` Marco Patzer
1 sibling, 1 reply; 10+ messages in thread
From: Hans Hagen @ 2013-03-16 21:46 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
-----------------------------------------------------------------
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 16:13 ` Marco Patzer
2013-03-16 17:08 ` Wolfgang Schuster
@ 2013-03-17 0:11 ` Aditya Mahajan
2013-03-17 12:53 ` Marco Patzer
1 sibling, 1 reply; 10+ messages in thread
From: Aditya Mahajan @ 2013-03-17 0:11 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: TEXT/PLAIN, Size: 540 bytes --]
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
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-17 0:11 ` Aditya Mahajan
@ 2013-03-17 12:53 ` Marco Patzer
0 siblings, 0 replies; 10+ messages in thread
From: Marco Patzer @ 2013-03-17 12:53 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 281 bytes --]
On 2013–03–16 Aditya Mahajan wrote:
> See the visualcounter module for an alternative way to pass values
> from TeX to MP.
I see, you create an initialisation graphic and include it where
necessary. And it's local to the MP instance. Thanks for the
pointer.
Marco
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
* Re: TeX macro to MP variable
2013-03-16 21:46 ` Hans Hagen
@ 2013-03-17 13:14 ` Marco Patzer
0 siblings, 0 replies; 10+ messages in thread
From: Marco Patzer @ 2013-03-17 13:14 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 361 bytes --]
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
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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] 10+ messages in thread
end of thread, other threads:[~2013-03-17 13:14 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-16 15:07 TeX macro to MP variable Marco Patzer
2013-03-16 15:37 ` Thomas A. Schmitz
2013-03-16 15:47 ` Marco Patzer
2013-03-16 16:13 ` Marco Patzer
2013-03-16 17:08 ` Wolfgang Schuster
2013-03-16 17:36 ` Marco Patzer
2013-03-17 0:11 ` Aditya Mahajan
2013-03-17 12:53 ` Marco Patzer
2013-03-16 21:46 ` Hans Hagen
2013-03-17 13:14 ` Marco Patzer
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).