Update text variables inside metapost
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
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
Aditaya, thanks for the clarification. Now it works perfectly.
Jorge
2015-03-07 23:57 GMT+00:00 Aditya Mahajan
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
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 -----------------------------------------------------------------
participants (3)
-
Aditya Mahajan
-
DesdeChaves
-
Hans Hagen