loop textext and \MPstring{…}
Hi, I am trying to achieve the following: \setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI} \starttext \startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage \stoptext There is no error but no content either. What's wrong? Thanks Andreas
Andreas Harder wrote:
Hi,
I am trying to achieve the following:
\setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI}
\starttext
\startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage
\stoptext
There is no error but no content either. What's wrong?
this won't work as {i} is not expanded at the right moment Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Tue, 11 Aug 2009, Andreas Harder wrote:
Hi,
I am trying to achieve the following:
\setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI}
\starttext
\startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage
\stoptext
There is no error but no content either. What's wrong?
Another way to do this is to use \TeXtext{1}{ABC} etc. and then call draw sometxt(i) For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf Aditya
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
On Tue, 11 Aug 2009, Andreas Harder wrote:
Hi,
I am trying to achieve the following:
\setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI}
\starttext
\startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage
\stoptext
There is no error but no content either. What's wrong?
Another way to do this is to use
\TeXtext{1}{ABC} etc.
and then call
draw sometxt(i)
For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
Thank you for the tip, I tried it, but sometext seems deprecated in mkiv ("[do we need TeXtexts in MkIV]"). I've different buffers named 1–12 and would like to pipe them to Metapost. I thought I could use a textext(\getbuffer[i])-construct, it failed. So I tried it with \setMPtext{}{} … What is the approach to achieve this? Thank you in advance, Andreas
On Wed, 12 Aug 2009, Andreas Harder wrote:
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
On Tue, 11 Aug 2009, Andreas Harder wrote:
Hi,
I am trying to achieve the following:
\setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI}
\starttext
\startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage
\stoptext
There is no error but no content either. What's wrong?
Another way to do this is to use
\TeXtext{1}{ABC} etc.
and then call
draw sometxt(i)
For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
Thank you for the tip, I tried it, but sometext seems deprecated in mkiv ("[do we need TeXtexts in MkIV]").
I thought that you were using MKII.
I've different buffers named 1–12 and would like to pipe them to Metapost. I thought I could use a textext(\getbuffer[i])-construct, it failed. So I tried it with \setMPtext{}{} …
What is the approach to achieve this?
Well, if nothing else works, you can always cheat. \startluacode userdata = userdata or {} userdata.labels = { [1] = "ABC" , [2] = "DEF" , [3] = "GHI" } function userdata.shift(i) return "(" .. i .. "cm ," .. i .. "cm )" end function userdata.draw(i) return "draw btex " .. userdata.labels[i] .. " etex shifted ".. userdata.shift(i) .. ";" end \stopluacode \starttext \startluacode context.startMPpage({offset = "1ex", width = [[\paperwidth]], height = [[\paperheight]]}) for i = 1,3 do context(userdata.draw(i)) end context.stopMPpage() \stopluacode \stoptext Aditya
Am 12.08.2009 um 15:25 schrieb Aditya Mahajan:
On Wed, 12 Aug 2009, Andreas Harder wrote:
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
On Tue, 11 Aug 2009, Andreas Harder wrote:
Hi, I am trying to achieve the following: \setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI} \starttext \startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage \stoptext There is no error but no content either. What's wrong? Another way to do this is to use \TeXtext{1}{ABC} etc. and then call draw sometxt(i) For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
Thank you for the tip, I tried it, but sometext seems deprecated in mkiv ("[do we need TeXtexts in MkIV]").
I thought that you were using MKII.
I've different buffers named 1–12 and would like to pipe them to Metapost. I thought I could use a textext(\getbuffer[i])-construct, it failed. So I tried it with \setMPtext{}{} …
What is the approach to achieve this?
Well, if nothing else works, you can always cheat.
\startluacode userdata = userdata or {} userdata.labels = { [1] = "ABC" , [2] = "DEF" , [3] = "GHI" }
function userdata.shift(i) return "(" .. i .. "cm ," .. i .. "cm )" end
function userdata.draw(i) return "draw btex " .. userdata.labels[i] .. " etex shifted ".. userdata.shift(i) .. ";" end
\stopluacode
\starttext
\startluacode context.startMPpage({offset = "1ex", width = [[\paperwidth]], height = [[\paperheight]]}) for i = 1,3 do context(userdata.draw(i)) end context.stopMPpage() \stopluacode
\stoptext
Thank you, very nice. In the "real world“ I've stripped quotes form another document and stored them in buffer-environments (attachment). With your solution I've no idea how to incorporate them in a "automatic" manner. Anyhow thanks Andreas
On Wed, 12 Aug 2009, Andreas Harder wrote:
In the "real world“ I've stripped quotes form another document and stored them in buffer-environments (attachment).
Save them as lua tables. Much easier to manipulate than tex objects.
With your solution I've no idea how to incorporate them in a "automatic" manner.
You just need to work a little harder. \startbuffer[1] This is a test \stopbuffer \startbuffer[2] Another test \stopbuffer \startbuffer[3] And again \stopbuffer \startluacode userdata = userdata or {} function userdata.shift(i) return "(" .. i .. "cm ," .. i .. "cm )" end function userdata.buffers(i) local idx = string.format("%s",i) local b = buffers.data[idx] if b then if type(b) == "table" then return table.concat(b) else return b end else return "unknown" end end function userdata.draw_buffer(i) return "draw btex " .. userdata.buffers(i) .. " etex shifted ".. userdata.shift(i) .. ";" end \stopluacode \starttext \startluacode context.startMPpage({offset = "1ex", width = [[\paperwidth]], height = [[\paperheight]]}) for i = 1,3 do context(userdata.draw_buffer(i)) end context.stopMPpage() \stopluacode \stoptext Aditya
Am 13.08.2009 um 05:00 schrieb Aditya Mahajan:
You just need to work a little harder.
\startbuffer[1] This is a test \stopbuffer
\startbuffer[2] Another test \stopbuffer
\startbuffer[3] And again \stopbuffer
\startluacode userdata = userdata or {} function userdata.shift(i) return "(" .. i .. "cm ," .. i .. "cm )" end
function userdata.buffers(i) local idx = string.format("%s",i) local b = buffers.data[idx] if b then if type(b) == "table" then return table.concat(b) else return b end else return "unknown" end end
function userdata.draw_buffer(i) return "draw btex " .. userdata.buffers(i) .. " etex shifted ".. userdata.shift(i) .. ";" end \stopluacode
\starttext
\startluacode
context.startMPpage({offset = "1ex", width = [[\paperwidth]], height = [[\paperheight]]}) for i = 1,3 do context(userdata.draw_buffer(i)) end context.stopMPpage() \stopluacode
\stoptext
Thank you very much! I played today (a couple of hours) with your solution and adapted some things, so if someone is interested, I've attached the file. PS. I like the math.random() function I found in the Lua manual. Andreas
Aditya Mahajan wrote:
On Wed, 12 Aug 2009, Andreas Harder wrote:
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
On Tue, 11 Aug 2009, Andreas Harder wrote:
Hi,
I am trying to achieve the following:
\setMPtext{1}{ABC} \setMPtext{2}{DEF} \setMPtext{3}{GHI}
\starttext
\startMPpage[offset=1ex,width=\paperwidth,height=\paperheight] for i=1 upto 3: draw textext(\MPstring{i}) shifted(i*cm,i*cm) ; endfor; \stopMPpage
\stoptext
There is no error but no content either. What's wrong?
Another way to do this is to use
\TeXtext{1}{ABC} etc.
and then call
draw sometxt(i)
For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
Thank you for the tip, I tried it, but sometext seems deprecated in mkiv ("[do we need TeXtexts in MkIV]").
I thought that you were using MKII.
I've different buffers named 1–12 and would like to pipe them to Metapost. I thought I could use a textext(\getbuffer[i])-construct, it failed. So I tried it with \setMPtext{}{} …
What is the approach to achieve this?
Well, if nothing else works, you can always cheat.
\startluacode userdata = userdata or {} userdata.labels = { [1] = "ABC" , [2] = "DEF" , [3] = "GHI" }
function userdata.shift(i) return "(" .. i .. "cm ," .. i .. "cm )" end
function userdata.draw(i) return "draw btex " .. userdata.labels[i] .. " etex shifted ".. userdata.shift(i) .. ";" end
\stopluacode
\starttext
\startluacode context.startMPpage({offset = "1ex", width = [[\paperwidth]], height = [[\paperheight]]}) for i = 1,3 do context(userdata.draw(i)) end context.stopMPpage() \stopluacode
\stoptext
a nice example for the wiki Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Wed, Aug 12, 2009 at 12:51, Andreas Harder wrote:
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
Another way to do this is to use
\TeXtext{1}{ABC} etc.
and then call
draw sometxt(i)
For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
Thank you for the tip, I tried it, but sometext seems deprecated in mkiv ("[do we need TeXtexts in MkIV]").
This only means that you need to send a request to Hans and ask for reenabling the feature, explaining that it's still usable :) :) :) It's a question from him after all (I think that I disabled the feature in my module for mkiv since it didn't work). If he was sure that it needs to be deprecated, he would not write that string :) I'm sure that there's a workaround (or at least a dozen of other ways), but I have no time (and my computer is being repaired again) to inspect right now. MKIV is both very powerful and fast, so you could probably also define strings inside metapost run, something like string mystrings[]; strings[1] := "ABC"; strings[2] = "DEF"; draw textext(strings[1]); Untested.
I've different buffers named 1–12 and would like to pipe them to Metapost. I thought I could use a textext(\getbuffer[i])-construct, it failed. So I tried it with \setMPtext{}{} …
(There should be at least quotation marks: textext("\getbuffer[i]"), but I don't clain that it would work then.) Maybe Hans should answer why \setMPtext fails. Mojca
Mojca Miklavec wrote:
On Wed, Aug 12, 2009 at 12:51, Andreas Harder wrote:
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
Another way to do this is to use
\TeXtext{1}{ABC} etc.
and then call
draw sometxt(i)
For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
when processing that one i found out that (1) syntax coloring was not enabled in mkii (due to tex->mkii renaming) (2) labels were not centered by default i fixed that as a bonus i implemented TeXtext in mkiv ... so those who use it have to buy Mojca a beer some day ... new beta Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Am 12.08.2009 um 23:22 schrieb Hans Hagen:
Mojca Miklavec wrote:
On Wed, Aug 12, 2009 at 12:51, Andreas Harder wrote:
Am 12.08.2009 um 07:40 schrieb Aditya Mahajan:
Another way to do this is to use
\TeXtext{1}{ABC} etc.
and then call
draw sometxt(i)
For Sec 4.5 of Mojca's my way on sometxt http://dl.contextgarden.net/myway/sometxt.pdf
when processing that one i found out that
(1) syntax coloring was not enabled in mkii (due to tex->mkii renaming) (2) labels were not centered by default
i fixed that
as a bonus i implemented TeXtext in mkiv ... so those who use it have to buy Mojca a beer some day ...
Thank you for your help. I've tried some examples form Mojca's MyWay but the pages still empty (without the "do we need …" question). Anyway, Aditya's solution works. Andreas Andreas
Am 12.08.2009 um 20:34 schrieb Mojca Miklavec:
I'm sure that there's a workaround (or at least a dozen of other ways), but I have no time (and my computer is being repaired again) to inspect right now.
Some tips?
MKIV is both very powerful and fast, so you could probably also define strings inside metapost run, something like
string mystrings[]; strings[1] := "ABC"; strings[2] = "DEF"; draw textext(strings[1]);
Untested.
It works, but if you loop it the problem remains. Thanks! Andreas
participants (4)
-
Aditya Mahajan
-
Andreas Harder
-
Hans Hagen
-
Mojca Miklavec