* Update text variables inside metapost
@ 2015-03-07 16:37 DesdeChaves
2015-03-07 23:57 ` Aditya Mahajan
0 siblings, 1 reply; 4+ messages in thread
From: DesdeChaves @ 2015-03-07 16:37 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 2221 bytes --]
Why the metapost not updated the value of text variables that are generated
inside luacode environment?
In the code below, If I have \startitemize[columns,two] then metapost draw:
1. \Bolha[size=6cm]{text1}{text2}{text3},
2. and four \Bolha[size=4cm]{text1}{text2}{text3}, but text1, text2 and
text3 is not updated in every call;
If I omit the itemize environment or with \startitemize metapost only draw:
1. the first call of Bolha that is: \Bolha[size=6cm]{text1}{text2}{text3}
2. and four call of \Bolha[size=6cm]{text1}{text2}{text3} %% all new
information is omited
Jorge
%%%%% code
\def\Bolha[#1]#2#3#4%
{\setupMPvariables[bolha][#1]%
\setMPtext{labelcima}{#3}%
\setMPtext{labelesquerda}{#2}%
\setMPtext{labeldireita}{#4}%
\useMPgraphic{bolha}}
\startuniqueMPgraphic{bolha}
path p, q, cima, esquerda, direita, vertical; pair A, B, C;
p:=fullcircle scaled \MPvar{size};
A:= (point 4 of p);
B:= (point 8 of p);
C:= (point 6 of p);
q:=A--B;
vertical := .5[A,B]--C;
cima := buildcycle(q, subpath(4,8) of reverse p);
esquerda := buildcycle(subpath(4,6) of p, vertical, subpath(0,.5) of q);
direita := buildcycle(subpath(6,8) of p, subpath(0,.5) of reverse q,
vertical);
draw p;
draw q;
draw vertical;
label(textext( \MPstring{labelcima} ), center cima);
label(textext( \MPstring{labelesquerda} ), center esquerda);
label(textext( \MPstring{labeldireita} ), center direita);
\stopuniqueMPgraphic
\starttext
\placefigure[center, nonumber]{}{
\Bolha[size=6cm]{$C_m$ (g/dm\high{3})}{mass (g)}{V\low{s} (dm\high{3})}
}
\startitemize[columns,two] %% try only \startitemize
\startluacode
flasks={20,25,50,100,200,250,500,1000}
k=1
repeat
Cm=math.random(1,10)/10
Vs=flasks[math.random(1,8)]/1000
mass=Cm*Vs
--incognita=math.random(1,3)
incognita=1
context.item()
if incognita==1 then
context("\\Bolha[size=4cm]{$C_m$}{%.2f g}{%.1f dm\\high{3}} mass=%.2f g",
mass, Vs, mass)
elseif incognita==2 then
context("\\Bolha[size=5cm]{%.1f g/dm\\high{3}}{m}{%.1f dm\\high{3}} mass=
hidde", Cm, Vs, mass)
elseif incognita==3 then
context("\\Bolha[size=5cm]{%.1f g/dm\\high{3}}{%.2f g}{V\\low{s}}
mass=%.2f g", Cm ,mass, mass)
end
k=k+1
until k==5
\stopluacode
\stopitemize
\stoptext
%%% stop code
[-- Attachment #1.2: Type: text/html, Size: 3541 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] 4+ messages in thread
* Re: Update text variables inside metapost
2015-03-07 16:37 Update text variables inside metapost DesdeChaves
@ 2015-03-07 23:57 ` Aditya Mahajan
2015-03-08 0:28 ` DesdeChaves
2015-03-08 9:54 ` Hans Hagen
0 siblings, 2 replies; 4+ messages in thread
From: Aditya Mahajan @ 2015-03-07 23:57 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Sat, 7 Mar 2015, DesdeChaves wrote:
> Why the metapost not updated the value of text variables that are generated
> inside luacode environment?
>
> In the code below, If I have \startitemize[columns,two] then metapost draw:
>
> 1. \Bolha[size=6cm]{text1}{text2}{text3},
> 2. and four \Bolha[size=4cm]{text1}{text2}{text3}, but text1, text2 and
> text3 is not updated in every call;
Use useMPgraphic instead of uniqueMPgraphic.
uniqueMPgraphic recomputes the graphic only when the dimensions of figure
has changed; otherwise, it reuses the previously drawn graphic. This
behavior was useful for drawing page-backgrounds etc in MkII where calling
metapost was slow.
Aditya
___________________________________________________________________________________
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] 4+ messages in thread
* Re: Update text variables inside metapost
2015-03-07 23:57 ` Aditya Mahajan
@ 2015-03-08 0:28 ` DesdeChaves
2015-03-08 9:54 ` Hans Hagen
1 sibling, 0 replies; 4+ messages in thread
From: DesdeChaves @ 2015-03-08 0:28 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1394 bytes --]
Aditaya, thanks for the clarification. Now it works perfectly.
Jorge
2015-03-07 23:57 GMT+00:00 Aditya Mahajan <adityam@umich.edu>:
> On Sat, 7 Mar 2015, DesdeChaves wrote:
>
> Why the metapost not updated the value of text variables that are
>> generated
>> inside luacode environment?
>>
>> In the code below, If I have \startitemize[columns,two] then metapost
>> draw:
>>
>> 1. \Bolha[size=6cm]{text1}{text2}{text3},
>> 2. and four \Bolha[size=4cm]{text1}{text2}{text3}, but text1, text2 and
>> text3 is not updated in every call;
>>
>
> Use useMPgraphic instead of uniqueMPgraphic.
>
> uniqueMPgraphic recomputes the graphic only when the dimensions of figure
> has changed; otherwise, it reuses the previously drawn graphic. This
> behavior was useful for drawing page-backgrounds etc in MkII where calling
> metapost was slow.
>
> Aditya
> ____________________________________________________________
> _______________________
> 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
> ____________________________________________________________
> _______________________
--
Atentamente
DesdeChaves
[-- Attachment #1.2: Type: text/html, Size: 2402 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] 4+ messages in thread
* Re: Update text variables inside metapost
2015-03-07 23:57 ` Aditya Mahajan
2015-03-08 0:28 ` DesdeChaves
@ 2015-03-08 9:54 ` Hans Hagen
1 sibling, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2015-03-08 9:54 UTC (permalink / raw)
To: ntg-context
On 3/8/2015 12:57 AM, Aditya Mahajan wrote:
> On Sat, 7 Mar 2015, DesdeChaves wrote:
>
>> Why the metapost not updated the value of text variables that are
>> generated
>> inside luacode environment?
>>
>> In the code below, If I have \startitemize[columns,two] then metapost
>> draw:
>>
>> 1. \Bolha[size=6cm]{text1}{text2}{text3},
>> 2. and four \Bolha[size=4cm]{text1}{text2}{text3}, but text1, text2 and
>> text3 is not updated in every call;
>
> Use useMPgraphic instead of uniqueMPgraphic.
>
> uniqueMPgraphic recomputes the graphic only when the dimensions of
> figure has changed; otherwise, it reuses the previously drawn graphic.
> This behavior was useful for drawing page-backgrounds etc in MkII where
> calling metapost was slow.
not only dimensions, also the overlay related colors (and if needed one
can extend the hash used) .. an other advantage (also in mkiv) is that
reuse also makes the pdf file smaller
Hans
-----------------------------------------------------------------
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] 4+ messages in thread
end of thread, other threads:[~2015-03-08 9:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-07 16:37 Update text variables inside metapost DesdeChaves
2015-03-07 23:57 ` Aditya Mahajan
2015-03-08 0:28 ` DesdeChaves
2015-03-08 9:54 ` Hans Hagen
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).