Re: [NTG-context] mp-geo Metapost package with ConTeXt
P.S. I marked the location of our local ConTeXt users group on the map, in case any of you want to visit. 1/3rd of your user group fled the country and is way closer by where i
On 7/16/2021 4:53 PM, Gavin Polhemus wrote: live now, Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 16/07/21 21:51, Hans Hagen wrote:
On 7/16/2021 4:53 PM, Gavin Polhemus wrote:
P.S. I marked the location of our local ConTeXt users group on the map, in case any of you want to visit. 1/3rd of your user group fled the country and is way closer by where i live now,
And in the same time zone! -- Alan
Hi everyone, I’ve made great progress creating globes for my diagrams using the data in the mp-geo package and some ideas from Hans. I have a couple questions about moving information from Lua to MetaPost. Below is a MWE for illustration. I have two related questions: 1) Is there a way for MetaPost to grab information from a Lua table? Currently the MetaPost code calls a Lua function which has a single line returning the information from the table. Is this necessary, or is these something in MetaPost that can get a path or color from a Lua table? 2) While I’m having good luck with paths, colors are causing trouble. In the data set the color information is in strings with French names of the color, like “rouge.” If I hand this string to MetaPost, MetaPost doesn’t expand it into a color. It does work if it is a native color, like “red,” but not if it is a defined color and not if the color is in a Lua variable. Any suggestions? Thanks! Gavin The code below produces four pie shape wedges to show the different results of handling the color. They should all be red, but the last two are black. \startMPinclusions color rouge; % To avoid changing the data files, I need to define colors in French. rouge=(1,0,0); % For this MWE, I only define rouge. color mycolor; % Defining mycolor in MetaPost works great, as shown in the first shape. mycolor = rouge; \stopMPinclusions \startluacode myluapath = {{0,0}, {1,0,0,0,1,0.25}, {0.8,0.6,0.95,0.4}, cycle = true} myluacolor = “red” --% Data files are read by Lua, so the myluacolor will be a string (in French, but native colors don't work either). function mp.getpath() --% Is there a way for the MetaPost code to grab the path directly from the table? mp.inject.path(myluapath) end function mp.getred() --% Returning a string work for native colors. mp.inject.string("red") end function mp.getrouge() --% Returning a string does not work for defined mp.inject.string("rouge") end function mp.getcolor() --% Putting the string in a variable does not work. mp.inject.string(mycolor) end \stopluacode \starttext \startMPpage fill lua.mp.getpath() scaled 2.5cm withcolor mycolor; % MetaPost color definition works great. fill lua.mp.getpath() scaled 2.5cm shifted (0, -2cm) withcolor lua.mp.getred(); % Returning a string work for native colors. fill lua.mp.getpath() scaled 2.5cm shifted (0, -4cm) withcolor lua.mp.getrouge(); % Returning a string does not work for defined colors. fill lua.mp.getpath() scaled 2.5cm shifted (0, -6cm) withcolor lua.mp.getcolor(); % Putting the string in a variable does not work. \stopMPpage \stoptext
On Mon, 26 Jul 2021, Gavin via ntg-context wrote:
2) While I’m having good luck with paths, colors are causing trouble. In the data set the color information is in strings with French names of the color, like “rouge.” If I hand this string to MetaPost, MetaPost doesn’t expand it into a color. It does work if it is a native color, like “red,” but not if it is a defined color and not if the color is in a Lua variable. Any suggestions?
\definecolor[rouge][red] should work. A better option will be use color palettes. This is very old code, but will give an idea of how to use palettes: https://github.com/adityam/visualcounter/blob/master/visualcounter.pdf Effectively all you need to do is add \setuppalet[name] at an appropriate place, and then the user can easily change the colors (rather than having them specified as part of data files). Aditya
Hi All, Getting Closer I asked:
2) While I’m having good luck with paths, colors are causing trouble. In the data set the color information is in strings with French names of the color, like “rouge.” If I hand this string to MetaPost, MetaPost doesn’t expand it into a color. It does work if it is a native color, like “red,” but not if it is a defined color and not if the color is in a Lua variable. Any suggestions?
Aditya suggested:
\definecolor[rouge][red] should work. A better option will be use color palettes.
This solves my problem of translating French colors into English, but not the problem of passing colors from Lua to MetaPost. If the string giving the color name is in a variable, it doesn’t go through. A path in a variable works. I’ve reduced my MWE below – no French, no MPinclusions, no new colors. Both pie slices should be red, but one is black. Any ideas on getting the color “red” passed from Lua to MetaPost when mycolor=“red”? Thanks! Gavin \startluacode mypath = {{0,0}, {2,0,0,0,2,0.5}, {1.6,1.2,1.9,0.8}, cycle = true} mycolor = “red” --% Data files are read by Lua, so the color of each object will be a string, like "red". function mp.getpath() --% Is there a way for the MetaPost code to grab the path directly from the table? mp.inject.path(mypath) end function mp.getred() --% Returning a string works. mp.inject.string("red") end function mp.getcolor() --% Putting the string in a variable does not work. mp.inject.string(mycolor) end \stopluacode \starttext \startMPpage fill lua.mp.getpath() scaled 2.5cm withcolor lua.mp.getred(); % Returning a string works. fill lua.mp.getpath() scaled 2.5cm shifted (0, -4cm) withcolor lua.mp.getcolor(); % Putting the string in a variable does not work. \stopMPpage \stoptext
On 27/07/21 08:12, Gavin via ntg-context wrote:
Hi All,
Getting Closer I asked:
2) While I’m having good luck with paths, colors are causing trouble. In the data set the color information is in strings with French names of the color, like “rouge.” If I hand this string to MetaPost, MetaPost doesn’t expand it into a color. It does work if it is a native color, like “red,” but not if it is a defined color and not if the color is in a Lua variable. Any suggestions?
Aditya suggested:
\definecolor[rouge][red] should work. A better option will be use color palettes.
This solves my problem of translating French colors into English, but not the problem of passing colors from Lua to MetaPost. If the string giving the color name is in a variable, it doesn’t go through. A path in a variable works.
I’ve reduced my MWE below – no French, no MPinclusions, no new colors. Both pie slices should be red, but one is black. Any ideas on getting the color “red” passed from Lua to MetaPost when mycolor=“red”?
I am not looking closely at the code, but in general we use fill fullcircle scaled 1cm withcolor red ; and this takes Metapost's knowledge of red, the rgb triplet (1,0,0). One can also use fill fullcircle scaled 1cm withcolor "red" ; as a string (quotation) and this passes Context's definition of the color. Alan -- Alan
participants (4)
-
Aditya Mahajan
-
Alan Braslau
-
Gavin
-
Hans Hagen