Dear all, is it possible to pass data from MetaPost back to TeX? This would be similar in spirit to, say, the MetaPost variable BodyFontSize that contains data from the TeX surrounding. Just the other way round. Best, Oliver Buerschaper
On 20-7-2010 2:00, Oliver Buerschaper wrote:
Dear all,
is it possible to pass data from MetaPost back to TeX? This would be similar in spirit to, say, the MetaPost variable BodyFontSize that contains data from the TeX surrounding. Just the other way round.
maybe future mlib versions will provide something like that (writing something from mp to a lua table); currently you have to use a file or interpret the log (use show to print out values). 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 -----------------------------------------------------------------
is it possible to pass data from MetaPost back to TeX? This would be similar in spirit to, say, the MetaPost variable BodyFontSize that contains data from the TeX surrounding. Just the other way round.
maybe future mlib versions will provide something like that (writing something from mp to a lua table); currently you have to use a file or interpret the log (use show to print out values).
OK. What I have in mind is to vertically align a diagram with the math axis... something like: --- \startuseMPgraphic{diagram} u := StrutHeight; draw origin--(2u,0)--(u,sqrt(3)*u)--cycle; % MathAxis at y-coordinate sqrt(3)*u/3 \stopuseMPgraphic \starttext \startformula A\useMPgraphic{diagram} =B \stopformula \stoptext --- It would be great if the comment could be turned into a processing instruction for ConTeXt such that the triangle's center of mass ends up on the math axis of the formula. What's the best way to achieve this? Many thanks, Oliver
No answer :-( Does that mean it's impossible with current technology? Oliver
is it possible to pass data from MetaPost back to TeX? This would be similar in spirit to, say, the MetaPost variable BodyFontSize that contains data from the TeX surrounding. Just the other way round.
maybe future mlib versions will provide something like that (writing something from mp to a lua table); currently you have to use a file or interpret the log (use show to print out values).
OK. What I have in mind is to vertically align a diagram with the math axis... something like:
--- \startuseMPgraphic{diagram} u := StrutHeight; draw origin--(2u,0)--(u,sqrt(3)*u)--cycle; % MathAxis at y-coordinate sqrt(3)*u/3 \stopuseMPgraphic
\starttext
\startformula A\useMPgraphic{diagram} =B \stopformula
\stoptext ---
It would be great if the comment could be turned into a processing instruction for ConTeXt such that the triangle's center of mass ends up on the math axis of the formula.
What's the best way to achieve this?
Many thanks, Oliver
On 07/30/2010 08:20 AM, Oliver Buerschaper wrote:
No answer :-( Does that mean it's impossible with current technology?
Well, you could create a temporary file from withing the metapost graphic, then read that file back on the TeX side, and then shift the image vertically based on the info from that. Complicated and a bit ugly, but doable. A nicer solution is to adjust the bounging box of the image itself so that it does the right thing. This seems to do the trick (but I recall there is a way to pass a TeX variable to the figure; and that would be much cleaner; but I don't remember how offhand). \startuseMPgraphic{diagram2} u := StrutHeight; draw origin--(2u,0)--(u,sqrt(3)*u)--cycle; currentpicture := currentpicture shifted (0,-(sqrt(3)*u/3)); setbounds currentpicture to (origin--(2u,0)--(u,sqrt(3)*u)--cycle); \stopuseMPgraphic \starttext \startformula A\raise\Umathaxis\displaystyle\hbox{\useMPgraphic{diagram2}} =B \stopformula \stoptext
Hi Taco,
Well, you could create a temporary file from withing the metapost graphic, then read that file back on the TeX side, and then shift the image vertically based on the info from that.
Could you give me a hint on how to parse such an auxiliary file in TeX? I've never done any sort of that programming before... I'm asking...
Complicated and a bit ugly, but doable. A nicer solution is to adjust the bounging box of the image itself so that it does the right thing. This seems to do the trick (but I recall there is a way to pass a TeX variable to the figure; and that would be much cleaner; but I don't remember how offhand).
\startuseMPgraphic{diagram2} u := StrutHeight; draw origin--(2u,0)--(u,sqrt(3)*u)--cycle; currentpicture := currentpicture shifted (0,-(sqrt(3)*u/3)); setbounds currentpicture to (origin--(2u,0)--(u,sqrt(3)*u)--cycle); \stopuseMPgraphic
\starttext
\startformula A\raise\Umathaxis\displaystyle\hbox{\useMPgraphic{diagram2}} =B \stopformula
\stoptext
... because adjusting the bounding box fails once the figure grows a bit larger. Just use u := 3StrutHeight; in the code above and you'll see the effect. Thanks for your help, Oliver
On 08/01/2010 12:16 PM, Oliver Buerschaper wrote:
Hi Taco,
Well, you could create a temporary file from withing the metapost graphic, then read that file back on the TeX side, and then shift the image vertically based on the info from that.
Could you give me a hint on how to parse such an auxiliary file in TeX? I've never done any sort of that programming before...
You don't have to worry about parsing, just write something like this in the metapost code: write "\string\def\string\MathAxis{"& decimal (sqrt(3)*u/3) &"}" to "info.tex"; Then \input info. Best wishes, Taco
... because adjusting the bounding box fails once the figure grows a bit larger. Just use
u := 3StrutHeight;
in the code above and you'll see the effect.
I forgot to say you need to add some text above and below the displayed formula... then you'll see some awkward vertical spacing :-( Oliver
participants (3)
-
Hans Hagen
-
Oliver Buerschaper
-
Taco Hoekwater