From: DesdeChaves <desdechaves@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Update text variables inside metapost
Date: Sat, 7 Mar 2015 16:37:01 +0000 [thread overview]
Message-ID: <CAPBmU9EochS19T-8CTUBWWNPgDyr8Q8wTgH0e3SGEaFWh8VDZg@mail.gmail.com> (raw)
[-- 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
___________________________________________________________________________________
next reply other threads:[~2015-03-07 16:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-07 16:37 DesdeChaves [this message]
2015-03-07 23:57 ` Aditya Mahajan
2015-03-08 0:28 ` DesdeChaves
2015-03-08 9:54 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPBmU9EochS19T-8CTUBWWNPgDyr8Q8wTgH0e3SGEaFWh8VDZg@mail.gmail.com \
--to=desdechaves@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).