[NTG-context] metapost graph and ConTeXt LMTX
Dear List, I have used TikZ and pgfplots for a few years and I am considering switching to metapost/metafun which appears more efficient with LMTX. I have already designed several figures with metapost/metafun and some with the help of metaobj and I am fully satisfied with the result. I am now trying to draw graphs with the metapost graph module, but I haven't been integrated to my ConTeXt LMTX document. The following example works perfectly well when compiled directly with metapost (from TeXlive 2020). = mpost example = beginfig(1) input graph draw begingraph(150mm, 100mm); gdraw "test-mpgraph.txt"; endgraph; endfig; end = Here is my demo data file test-mpgraph.txt 0 0 1 1 2 2 3 1 4 3 5 2 6 1 == I tried the following to draw directly from a ConTeXt document LMTX example = \starttext \startMPcode troffmode:=0; prologues:=0; input graph draw begingraph(150mm, 100mm); gdraw "test-mpgraph.txt"; endgraph; \stopMPcode \stoptext === I had to define troffmode and prologues, otherwise I get error messages about undecidable expressions and now I get an error that I don't understand (see attached log file). I also tried \usemodule[graph] as documented on the wiki (https://wiki.contextgarden.net/MPgraph) but without success. I guess I am doing something wrong. Could someone help me see my error? Thanks, -- Jean-Philippe Rey jean-philippe@centralesupelec.fr 91192 Gif-sur-Yvette Cedex - France Empreinte PGP : 807A 5B2C 69E4 D4B5 783A 428A 1B5E E83E 261B BF51 test-mpgraph.log Description: Binary data ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] drop shadows with metapost/ metafun
> Am 29.12.2020 um 22:56 schrieb Garulfo : > > Which process would you advice to add « drop shadows » to any kind of metafun > / metapost figures like: > picture p; > p := textext("MetaPost is fun!") shifted (10cm,10cm); > > > My current understanding of the required steps : > > > 1- fill p with the shadow color > > 2- write it to an external metapost file (with savebuffer ?) ready for png > export (outputformat := "png »;) > > 3- with lua, os.execute, and imagemagick prepare the shadow > - extent the png file with a transparent background, to have room for > blurring > - blur it > > 4- import this png in context / Metapost (externalfigure), and center it with > p figure > > 5- shift it according to the desired shadows distance and angle > > 6- apply the initial bounding box of p to the shadow, draw the shadow, draw > the p picture > > > Actually, all this seems long and tedious, and contrasts with the already > existing links between MetaPost / MetaFun and cairo + libpng. I don’t know if that helps, but I’m using a stack of transparent objects to simulate drop shadows: https://wiki.contextgarden.net/Drop_shadows No pixel images required. But I’d like to have a real text shadow instead of that box shadow. Happy New Year! Hraban ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] drop shadows with metapost/ metafun
On Fri, 1 Jan 2021, Aditya Mahajan wrote: > On Tue, 29 Dec 2020, Garulfo wrote: > > > Which process would you advice to add « drop shadows » to any kind of > > metafun / metapost figures like: > > > Actually, all this seems long and tedious, and contrasts with the already > > existing links between MetaPost / MetaFun and cairo + libpng. > > There was a drops module by Peter Rolf, which provides exactly these features: > > https://mailman.ntg.nl/pipermail/ntg-context/2016/084242.html > > It is not part of modules.contextgarden.net and the url in the previous post > is no longer valid. > > I am CC:ing Peter and perhaps he can point to the updated location for the > module. Also, if you don't want the shadows to be too nice, you can also translate the fake shadows used by tikz to metapost: https://adityam.github.io/context-blog/post/drop-shadow-with-lifted-corners/ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] drop shadows with metapost/ metafun
On Tue, 29 Dec 2020, Garulfo wrote: > Which process would you advice to add « drop shadows » to any kind of metafun > / metapost figures like: > picture p; > p := textext("MetaPost is fun!") shifted (10cm,10cm); > > My current understanding of the required steps : > > > 1- fill p with the shadow color > > 2- write it to an external metapost file (with savebuffer ?) ready for png > export (outputformat := "png »;) > > 3- with lua, os.execute, and imagemagick prepare the shadow > - extent the png file with a transparent background, to have room for > blurring > - blur it > > 4- import this png in context / Metapost (externalfigure), and center it with > p figure > > 5- shift it according to the desired shadows distance and angle > > 6- apply the initial bounding box of p to the shadow, draw the shadow, draw > the p picture > > > Actually, all this seems long and tedious, and contrasts with the already > existing links between MetaPost / MetaFun and cairo + libpng. There was a drops module by Peter Rolf, which provides exactly these features: https://mailman.ntg.nl/pipermail/ntg-context/2016/084242.html It is not part of modules.contextgarden.net and the url in the previous post is no longer valid. I am CC:ing Peter and perhaps he can point to the updated location for the module. 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] drop shadows with metapost/ metafun
Which process would you advice to add « drop shadows » to any kind of metafun / metapost figures like: picture p; p := textext("MetaPost is fun!") shifted (10cm,10cm); My current understanding of the required steps : 1- fill p with the shadow color 2- write it to an external metapost file (with savebuffer ?) ready for png export (outputformat := "png »;) 3- with lua, os.execute, and imagemagick prepare the shadow - extent the png file with a transparent background, to have room for blurring - blur it 4- import this png in context / Metapost (externalfigure), and center it with p figure 5- shift it according to the desired shadows distance and angle 6- apply the initial bounding box of p to the shadow, draw the shadow, draw the p picture Actually, all this seems long and tedious, and contrasts with the already existing links between MetaPost / MetaFun and cairo + libpng. Thanks again for your help.___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Metafun: dotlabel issue in latest LMTX
Hi Hans, The following (due to you and Aditya, discussed a few days ago) used to work with LMTX until version 2020-12-10, but it does not work anymore with LMTX version 2020-12-24 17:30. I wonder whether this is due to some changes you have made recently. %% begin squaredot-test.tex \startMPdefinitions newpath mydotlabelshape ; mydotlabelshape := fullcircle ; mydotlabeldiam := 12 pt ; vardef mydotlabel@#(expr s,z) text t_ = label@#(s,z) t_ ; fill (mydotlabelshape scaled 2mydotlabeldiam) shifted z t_; enddef ; \stopMPdefinitions \starttext \startMPcode newpath p ; p := (2cm, 3cm) -- (3cm, 5cm); mydotlabeldiam := 15pt; mydotlabelshape := fullsquare ; draw p ; mydotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) withcolor transparent("exclusion",.5,red) ; mydotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) withcolor transparent("exclusion",.5,red) ; \stopMPcode \stoptext %% end squaredot-test.tex I get an error message, which is obscure to me, saying: %-- begin error message excerpt metafun > log > error: Isolated expression metafun > log > metapost> log > metapost> log > metapost > log > ; metapost> log > <*> newpath mydotlabelshape ; metafun > log > metafun > log > I couldn't find an '=' or ':=' after the expression that is shown above this error message, so I guess I'll just ignore it and carry on. metafun > log > metapost> log > mydotlabelshape := fullcircle ; mydotlabeldiam := 12 pt ; vardef mydotlabel@##(expr s,z) text t_ = label@##(s,z) t_ ; fill (mydotlabelshape scaled 2mydotlabeldiam) shi... %-- end error message excerpt Best regards: Otared ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] freedotlabel not defined in LMTX ?
On 12/26/2020 11:28 AM, Otared Kavian wrote: Hi Hans, When I was testing your example with freelabel in another thread, I noticed that freedotlabel does not work in LMTX. Here is the code from the Metafun manual which works with ConTeXt version 2020.06.25 10:55 MKIV, but not with ConTeXt version 2020.12.24 17:30 LMTX. %% begin freedotlabel.tex \setupbodyfont[pagella] \starttext \startMPcode pair destination ; for whereto = "up", "down", "left", "right" : destination := scantokens(whereto) * 1cm ; freedotlabel(whereto, destination, origin) ; drawarrow origin -- destination withpen pencircle scaled .25mm withcolor .625 red ; endfor ; \stopMPcode \stoptext %% end freedotlabel.tex a renamed variable ... vardef freedotlabel (expr asked_text, asked_location, asked_origin) = interim linecap := rounded ; draw asked_location withpen pencircle scaled freedotlabelsize ; draw thefreelabel(asked_text,asked_location,asked_origin) ; enddef ; - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] freedotlabel not defined in LMTX ?
Hi Hans, When I was testing your example with freelabel in another thread, I noticed that freedotlabel does not work in LMTX. Here is the code from the Metafun manual which works with ConTeXt version 2020.06.25 10:55 MKIV, but not with ConTeXt version 2020.12.24 17:30 LMTX. %% begin freedotlabel.tex \setupbodyfont[pagella] \starttext \startMPcode pair destination ; for whereto = "up", "down", "left", "right" : destination := scantokens(whereto) * 1cm ; freedotlabel(whereto, destination, origin) ; drawarrow origin -- destination withpen pencircle scaled .25mm withcolor .625 red ; endfor ; \stopMPcode \stoptext %% end freedotlabel.tex Best regards: Otared ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun labels and xsized
On 12/25/20 10:09 PM, Hans Hagen wrote: >> [...] > \startMPcode > path p ; p := ( > ( 1, 1) -- > ( 1, 5) -- > (10, 10) -- > (14, 4) -- > cycle) xsized .75TextWidth; > > draw p ; > > freelabel("\strut α",point 0 of p,center p) ; > freelabel("\strut β",point 1 of p,center p) ; > freelabel("\strut γ",point 2 of p,center p) ; > freelabel("\strut δ",point 3 of p,center p) ; > \stopMPcode Many thanks for your code, Hans. This is exactly what I need. Pablo -- http://www.ousia.tk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun labels and xsized
On 12/25/2020 6:36 PM, Fabrice L wrote: Hi, Le 25 déc. 2020 à 12:30, Pablo Rodriguez a écrit : Dear list, I have this minimal MetaFun sample (the only one in my real document): \setupbodyfont[pagella] \starttext \startMPcode pair a ; a := (1, 1) ; pair b ; b := (1, 10) ; pair c ; c := (10, 10) ; pair d ; d := (10, 1) ; draw (a--b--c--d--a) xsized .75TextWidth; draw thelabel.lft("α",a) ; draw thelabel.lft("β",b) ; draw thelabel.top("γ",c) ; draw thelabel.rt("δ",d) ; \stopMPcode \stoptext Is there a way to relate adapt the labels to the xsized positions used? I’m sure somebody could find a more elegant solution, but here is a simple one: \setupbodyfont[pagella] \starttext \startMPcode pair a ; a := (1, 1) ; pair b ; b := (1, 10) ; pair c ; c := (10, 10) ; pair d ; d := (10, 1) ; path square ; square := (a--b--c--d--cycle) xsized .75TextWidth ; draw square xsized .75TextWidth; draw thelabel.lft("α",point 0 of square) ; draw thelabel.lft("β",point 1 of square) ; draw thelabel.top("γ",point 2 of square) ; draw thelabel.rt("δ",point 3 of square) ; \stopMPcode \stoptext Fabrice. \startMPcode path p ; p := ( ( 1, 1) -- ( 1, 5) -- (10, 10) -- (14, 4) -- cycle) xsized .75TextWidth; draw p ; freelabel("\strut α",point 0 of p,center p) ; freelabel("\strut β",point 1 of p,center p) ; freelabel("\strut γ",point 2 of p,center p) ; freelabel("\strut δ",point 3 of p,center p) ; \stopMPcode - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun labels and xsized
On 12/25/20 6:36 PM, Fabrice L wrote: >> I have this minimal MetaFun sample (the only one in my real document): >> [...] >> Is there a way to relate adapt the labels to the xsized positions used? > > I’m sure somebody could find a more elegant solution, but here is a simple > one: > > \setupbodyfont[pagella] > \starttext > \startMPcode > pair a ; a := (1, 1) ; > pair b ; b := (1, 10) ; > pair c ; c := (10, 10) ; > pair d ; d := (10, 1) ; > path square ; > square := (a--b--c--d--cycle) xsized .75TextWidth ; > > draw square xsized .75TextWidth; > > draw thelabel.lft("α",point 0 of square) ; > draw thelabel.lft("β",point 1 of square) ; > draw thelabel.top("γ",point 2 of square) ; > draw thelabel.rt("δ",point 3 of square) ; > \stopMPcode > \stoptext Many thanks for your ultra-fast reply, Fabrice. I didn’t know that paths could be also defined (MP is all Greek to me). I realized that drawing doesn’t require resizing again (once the path definition contains resizing). Many thanks for your help, Pablo -- http://www.ousia.tk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun labels and xsized
Hi, > Le 25 déc. 2020 à 12:30, Pablo Rodriguez a écrit : > > Dear list, > > I have this minimal MetaFun sample (the only one in my real document): > > \setupbodyfont[pagella] > \starttext > \startMPcode > pair a ; a := (1, 1) ; > pair b ; b := (1, 10) ; > pair c ; c := (10, 10) ; > pair d ; d := (10, 1) ; > draw (a--b--c--d--a) xsized .75TextWidth; > > draw thelabel.lft("α",a) ; > draw thelabel.lft("β",b) ; > draw thelabel.top("γ",c) ; > draw thelabel.rt("δ",d) ; > \stopMPcode > \stoptext > > Is there a way to relate adapt the labels to the xsized positions used? I’m sure somebody could find a more elegant solution, but here is a simple one: \setupbodyfont[pagella] \starttext \startMPcode pair a ; a := (1, 1) ; pair b ; b := (1, 10) ; pair c ; c := (10, 10) ; pair d ; d := (10, 1) ; path square ; square := (a--b--c--d--cycle) xsized .75TextWidth ; draw square xsized .75TextWidth; draw thelabel.lft("α",point 0 of square) ; draw thelabel.lft("β",point 1 of square) ; draw thelabel.top("γ",point 2 of square) ; draw thelabel.rt("δ",point 3 of square) ; \stopMPcode \stoptext Fabrice. > > Many thanks for your help, > > Pablo > -- > http://www.ousia.tk > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] MetaFun labels and xsized
Dear list, I have this minimal MetaFun sample (the only one in my real document): \setupbodyfont[pagella] \starttext \startMPcode pair a ; a := (1, 1) ; pair b ; b := (1, 10) ; pair c ; c := (10, 10) ; pair d ; d := (10, 1) ; draw (a--b--c--d--a) xsized .75TextWidth; draw thelabel.lft("α",a) ; draw thelabel.lft("β",b) ; draw thelabel.top("γ",c) ; draw thelabel.rt("δ",d) ; \stopMPcode \stoptext Is there a way to relate adapt the labels to the xsized positions used? Many thanks for your help, Pablo -- http://www.ousia.tk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Check if two paths intersect in Metafun
Hi, > Le 25 déc. 2020 à 08:48, Jairo A. del Rio a écrit : > > Hi, list. I've got a question about paths and intersections. The following: > > \starttext > \startMPpage > path p[]; > > p[1] = fullcircle scaled 2cm; > p[2] = unitsquare shifted (4cm,6cm); > > if (known (p[1] intersectionpoint p[2])): > > draw textext("yes"); > > else: > > draw textext("no"); > fi; > > \stopMPpage > \stoptext > > yields an error message: "The paths don't intersect". Is there a way to > intercept this error message and trigger an action instead? Thank you in > advance. Instead of using « intersectionpoint » use « Intersectiontimes », this will give you the « time » of the intersection of the two paths. If the paths do not intersect, than the value is (-1,-1). So you could do something like: pair checkintersec ; checkintersec := p[1] intersectiontimes p[2] ; If xpart(checkintersec) <> -1 : draw textext("yes »); else: draw textext(« non »); fi; Fabrice. > > Best regards, > > Jairo > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Check if two paths intersect in Metafun
Hi, list. I've got a question about paths and intersections. The following: \starttext \startMPpage path p[]; p[1] = fullcircle scaled 2cm; p[2] = unitsquare shifted (4cm,6cm); if (known (p[1] intersectionpoint p[2])): draw textext("yes"); else: draw textext("no"); fi; \stopMPpage \stoptext yields an error message: "The paths don't intersect". Is there a way to intercept this error message and trigger an action instead? Thank you in advance. Best regards, Jairo ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
Much more lean now thanks to your feedbacks. I prefered to "remove the shapes of the letter" rather than doubling the shading. Wikified https://wiki.contextgarden.net/Cover_Pages#.22Empty.22_letters \definecolor [ColorHighA] [h=c4a000] \definecolor [ColorHighB] [h=602217] \definecolor [ColorLow] [0.8(white)] \startMPpage %-- picture tt ; tt := lmt_outline [ kind = "fillup", text = "\definedfont[name:texgyrepagellabold*default]% \framed[frame=off,offset=3mm,align=middle,strut=none] {MetaPost\\is Fun !\\Aujourd'hui\\Today\\*§ 2020 §*}", ] xsized 12cm ; path bb ; bb := boundingbox tt; %-- path pp ; pp := bb enlarged 2cm ; fill pp withshademethod "linear" withshadedirection (2.,0.) withshadecolors (\MPcolor{ColorHighA}, \MPcolor{ColorHighB}); %-- picture Paddmissing; Paddmissing := nullpicture; picture Pwoletters; Pwoletters := nullpicture; numeric testwithin ; %-- for i within tt : if stroked i or filled i : testwithin :=0; for j within tt : if stroked j or filled j: if (((xpart llcorner i) > (xpart llcorner j)) and ((ypart llcorner i) > (ypart llcorner j)) and ((xpart urcorner i) < (xpart urcorner j)) and ((ypart urcorner i) < (ypart urcorner j))) : testwithin :=1; fi; fi; endfor; if testwithin == 1: addto Paddmissing contour (pathpart i) withcolor \MPcolor{ColorLow}; else: addto Pwoletters contour (pathpart i) withpostscript "collect"; fi; fi ; endfor ; %-- addto Pwoletters contour bb withpostscript "evenodd" withcolor \MPcolor{ColorLow}; draw Pwoletters ; draw Paddmissing ; \stopMPpage ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
> On 24 Dec 2020, at 00:14, Garulfo wrote: > > Thanks Taco, > > I made some progress : > https://wiki.contextgarden.net/Talk:Cover_Pages > > I now have two additional questions ... ;-) > > - How can I deal with "space" characters (because current solution > requires to explicitly add the ~ character) Here’s what I would do (which is probably not the nicest way of doing it). Just enable \obeyspaces while reading the argument to \EmptyLetters, then disable it again immediately (that is needed if you have to go back to TeX from Lua): \def\EmptyLetters {\obeyspaces\doEmptyLetters} \def\doEmptyLetters#1% {\normalspaces ... } and in \whatever you then need \doifinstringelse{ }{#1} Best wishes, Taco ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
On 12/24/2020 12:46 AM, Otared Kavian wrote: Hi Garulfo, Thank you for sharing your nice example: it typesets correctly with mkiv, but it seems to me that with LMTX the text does not appear (at least on my installation of the latest LMTX). I admit that I had to trial and error this: \startMPpage picture tt ; tt := lmt_outline [ kind = "fillup", text = "\strut foo f o o", drawcolor = "white", rulethickness = .2 ] ysized 5cm ; path bb ; bb := boundingbox tt; path pp ; pp := bb enlarged 3cm ; fill pp withshademethod "linear" withshadedirection down withshadecolors (red, blue) ; fill bb withcolor "darkgray" ; for i within tt : if stroked i : nofill (pathpart i) ; fi ; dofill bb withshademethod "linear" withshadedirection down withshadecolors (red, blue) ; endfor ; \stopMPpage - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
On 12/24/2020 12:14 AM, Garulfo wrote: Thanks Taco, I made some progress : https://wiki.contextgarden.net/Talk:Cover_Pages I now have two additional questions ... ;-) - How can I deal with "space" characters (because current solution requires to explicitly add the ~ character) - What would be the work to do in order to make this mechanism directly usable in metapost / metafun, within \startMPpage \stopMPpage, - to avoid switching between \start\stopMPdrawing and TeX - to have something like "draw followtext" in mp-blob.mpiv ? Maybe pickup some tricks from this: \starttext \startMPpage StartPage; fill Page withshademethod "linear" withshadedirection(0,1) withshadecolors (red, blue) ; picture p ; p := lmt_outline [ text = "\strut foo f o o", drawcolor = "white", rulethickness = .2 ] ysized 5cm ; draw (p shifted - center p) shifted center Page; StopPage; \stopMPpage \startuseMPgraphic{MyShade} fill OverlayBox withshademethod "linear" withshadedirection(0,1) withshadecolors (red, blue) ; \stopuseMPgraphic \defineoverlay[MyShade][\useMPgraphic{MyShade}] \setupbackgrounds[page][background=MyShade] \startmakeup \definedfont[SerifBold*default @ 50pt] \setupinterlinespace \defineeffect[MyOutline][alternative=outer,rulethickness=1pt] \startcolor[white] \starteffect[MyOutline] \input jojomayer \stopeffect \stopcolor \stopmakeup \stoptext %-- \setuppapersize [A4] %-- \def\MyFont{\definedfont[name:% texgyrepagellabold% %exo2black% %agaramondprobold% *default at 55pt]} %-- \startluacode function document.outlinepaths(character) local chardata = fonts.hashes.characters[true] -- by unicode local shapedata = fonts.hashes.shapes[true] -- by index local c = chardata[character] if c and c.index and shapedata then local shapeglyphs = shapedata.glyphs or { } local glyph = shapeglyphs[c.index] if glyph and (glyph.segments or glyph.sequence) then local units = shapedata.units or 1000 local factor = 100/units return fonts.metapost.paths(glyph,factor) end end return { } end function document.defineoutline(char,target) local outlines = document.outlinepaths(char) local nofpaths = #outlines context("\\startMPdrawing") -- ADDED by garulfo context("path %s[] ;",target) context("numeric %sn ; %sn := %s ;",target,target,nofpaths) for i=1,nofpaths do context("%s[%i] := %s ; ",target,i,outlines[i]) end context("\\stopMPdrawing") -- ADDED by garulfo end \stopluacode %-- \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}} %-- \def\EmptyLetters#1% {% \resetMPdrawing \MPtoks={} % \startMPdrawing picture pic[], pictA ; numeric wid[], len[], pos[], n ; wid[0] := len[0] := pos[0] := n := 0 ; numeric scaling; path pictB , frame ; pair shiftB ; picture monImageA; monImageA := nullpicture; picture monImageB; monImageB := nullpicture; color colorframe; colorframe := 0.6white; % \stopMPdrawing % \MyFont\handletokens#1\with\whatever % \startMPdrawing frame := unitsquare xscaled ( (xpart urcorner monImageB - xpart llcorner monImageB) + 5mm ) yscaled ( (ypart urcorner monImageB - ypart llcorner monImageB) + 5mm ); frame := frame shifted (center monImageB - center frame); addto monImageB contour frame withpostscript "evenodd" withcolor transparent (1,1.,colorframe); draw monImageB ; draw monImageA ; \stopMPdrawing % \MPdrawingdonetrue \getMPdrawing} %-- \def\whatever#1% {\appendtoks#1\to\MPtoks \setbox\MPbox=\hbox{\MyFont\the\MPtoks}% % \startMPdrawing n := n + 1 ; len[n] := \the\wd\MPbox ; \stopMPdrawing % \mpdefineoutlines{M}{MaLettre} % \startMPdrawing pictA := textext.drt("\MyFont M") ; pictB := MaLettre[1]; scaling := bbheight pictA / bbheight pictB; \stopMPdrawing % \doifinstringelse{~}{#1}{}{% HOW TO PROPERLY COPE WITH SPACES ? \mpdefineoutlines{#1}{MyGlyph} % \s
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
Hi Garulfo, Thank you for sharing your nice example: it typesets correctly with mkiv, but it seems to me that with LMTX the text does not appear (at least on my installation of the latest LMTX). Best regards: Otared > On 24 Dec 2020, at 00:14, Garulfo wrote: > > Thanks Taco, > > I made some progress : > https://wiki.contextgarden.net/Talk:Cover_Pages > > I now have two additional questions ... ;-) > > - How can I deal with "space" characters (because current solution > requires to explicitly add the ~ character) > > - What would be the work to do in order to make this mechanism directly > usable in metapost / metafun, within \startMPpage \stopMPpage, > - to avoid switching between \start\stopMPdrawing and TeX > - to have something like "draw followtext" in mp-blob.mpiv ? > > > > %-- > > \setuppapersize [A4] > > %-- > > \def\MyFont{\definedfont[name:% > texgyrepagellabold% > %exo2black% > %agaramondprobold% > *default at 55pt]} > > %-- > > \startluacode > > function document.outlinepaths(character) >local chardata = fonts.hashes.characters[true] -- by unicode >local shapedata = fonts.hashes.shapes[true] -- by index >local c = chardata[character] >if c and c.index and shapedata then >local shapeglyphs = shapedata.glyphs or { } >local glyph = shapeglyphs[c.index] >if glyph and (glyph.segments or glyph.sequence) then >local units = shapedata.units or 1000 >local factor = 100/units >return fonts.metapost.paths(glyph,factor) >end >end >return { } > end > > function document.defineoutline(char,target) >local outlines = document.outlinepaths(char) >local nofpaths = #outlines >context("\\startMPdrawing") -- ADDED by garulfo >context("path %s[] ;",target) >context("numeric %sn ; %sn := %s ;",target,target,nofpaths) >for i=1,nofpaths do >context("%s[%i] := %s ; ",target,i,outlines[i]) >end >context("\\stopMPdrawing") -- ADDED by garulfo > end > > \stopluacode > > %-- > > \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}} > > %-- > > \def\EmptyLetters#1% > {% > \resetMPdrawing > \MPtoks={} > % > \startMPdrawing > picture pic[], pictA ; > numeric wid[], len[], pos[], n ; > wid[0] := len[0] := pos[0] := n := 0 ; > numeric scaling; > path pictB , frame ; > pair shiftB ; > picture monImageA; monImageA := nullpicture; > picture monImageB; monImageB := nullpicture; > color colorframe; colorframe := 0.6white; > % > \stopMPdrawing > % > \MyFont\handletokens#1\with\whatever > % > \startMPdrawing > frame := unitsquare > xscaled ( (xpart urcorner monImageB - xpart llcorner monImageB) + > 5mm ) > yscaled ( (ypart urcorner monImageB - ypart llcorner monImageB) + > 5mm ); > frame := frame shifted (center monImageB - center frame); > addto monImageB contour >frame >withpostscript "evenodd" >withcolor transparent (1,1.,colorframe); > draw monImageB ; > draw monImageA ; > \stopMPdrawing > % > \MPdrawingdonetrue > \getMPdrawing} > > %-- > > \def\whatever#1% > {\appendtoks#1\to\MPtoks > \setbox\MPbox=\hbox{\MyFont\the\MPtoks}% > % > \startMPdrawing > n := n + 1 ; len[n] := \the\wd\MPbox ; > \stopMPdrawing > % > \mpdefineoutlines{M}{MaLettre} > % > \startMPdrawing > pictA := textext.drt("\MyFont M") ; > pictB := MaLettre[1]; > scaling := bbheight pictA / bbheight pictB; > \stopMPdrawing > % > \doifinstringelse{~}{#1}{}{%HOW TO PROPERLY COPE WITH > SPACES ? > \mpdefineoutlines{#1}{MyGlyph} > % > \startMPdrawing > string sb; sb := "i"; > pic[n] := textext.drt("\MyFont\setstrut\strut#1") ; > % > shiftB := - llcorner pic[n]; > pic[n] := pic[n] shifted shiftB ; > % > wid[n] := abs(xpart urcorner pic[n] - xpart llcorner pic[n]) ; > pos[n] := len[n]-wid[n] ; >
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
Thanks Taco, I made some progress : https://wiki.contextgarden.net/Talk:Cover_Pages I now have two additional questions ... ;-) - How can I deal with "space" characters (because current solution requires to explicitly add the ~ character) - What would be the work to do in order to make this mechanism directly usable in metapost / metafun, within \startMPpage \stopMPpage, - to avoid switching between \start\stopMPdrawing and TeX - to have something like "draw followtext" in mp-blob.mpiv ? %-- \setuppapersize [A4] %-- \def\MyFont{\definedfont[name:% texgyrepagellabold% %exo2black% %agaramondprobold% *default at 55pt]} %-- \startluacode function document.outlinepaths(character) local chardata = fonts.hashes.characters[true] -- by unicode local shapedata = fonts.hashes.shapes[true] -- by index local c = chardata[character] if c and c.index and shapedata then local shapeglyphs = shapedata.glyphs or { } local glyph = shapeglyphs[c.index] if glyph and (glyph.segments or glyph.sequence) then local units = shapedata.units or 1000 local factor = 100/units return fonts.metapost.paths(glyph,factor) end end return { } end function document.defineoutline(char,target) local outlines = document.outlinepaths(char) local nofpaths = #outlines context("\\startMPdrawing") -- ADDED by garulfo context("path %s[] ;",target) context("numeric %sn ; %sn := %s ;",target,target,nofpaths) for i=1,nofpaths do context("%s[%i] := %s ; ",target,i,outlines[i]) end context("\\stopMPdrawing") -- ADDED by garulfo end \stopluacode %-- \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}} %-- \def\EmptyLetters#1% {% \resetMPdrawing \MPtoks={} % \startMPdrawing picture pic[], pictA ; numeric wid[], len[], pos[], n ; wid[0] := len[0] := pos[0] := n := 0 ; numeric scaling; path pictB , frame ; pair shiftB ; picture monImageA; monImageA := nullpicture; picture monImageB; monImageB := nullpicture; color colorframe; colorframe := 0.6white; % \stopMPdrawing % \MyFont\handletokens#1\with\whatever % \startMPdrawing frame := unitsquare xscaled ( (xpart urcorner monImageB - xpart llcorner monImageB) + 5mm ) yscaled ( (ypart urcorner monImageB - ypart llcorner monImageB) + 5mm ); frame := frame shifted (center monImageB - center frame); addto monImageB contour frame withpostscript "evenodd" withcolor transparent (1,1.,colorframe); draw monImageB ; draw monImageA ; \stopMPdrawing % \MPdrawingdonetrue \getMPdrawing} %-- \def\whatever#1% {\appendtoks#1\to\MPtoks \setbox\MPbox=\hbox{\MyFont\the\MPtoks}% % \startMPdrawing n := n + 1 ; len[n] := \the\wd\MPbox ; \stopMPdrawing % \mpdefineoutlines{M}{MaLettre} % \startMPdrawing pictA := textext.drt("\MyFont M") ; pictB := MaLettre[1]; scaling := bbheight pictA / bbheight pictB; \stopMPdrawing % \doifinstringelse{~}{#1}{}{%HOW TO PROPERLY COPE WITH SPACES ? \mpdefineoutlines{#1}{MyGlyph} % \startMPdrawing string sb; sb := "i"; pic[n] := textext.drt("\MyFont\setstrut\strut#1") ; % shiftB := - llcorner pic[n]; pic[n] := pic[n] shifted shiftB ; % wid[n] := abs(xpart urcorner pic[n] - xpart llcorner pic[n]) ; pos[n] := len[n]-wid[n] ; % addto monImageB contour ((MyGlyph[1] scaled scaling) shifted ( (pos[n],0) + shiftB)) withpostscript "collect"; % if MyGlyphn > 1 : for ind=2 upto MyGlyphn : if (((xpart llcorner MyGlyph[ind]) > (xpart llcorner MyGlyph[1])) and ((ypart llcorner MyGlyph[ind]) > (ypart llcorner MyGlyph[1])) and ((xpart urcorner MyGlyph[ind]) < (xpart urcorner MyGlyph[1])) and ((ypart urcorner MyGlyph[ind]) < (ypart urcorner MyGlyph[1]))) : % addto monImageA contour (MyGlyph[ind] scaled scaling) shifted ( (pos[n],0) + shiftB) withcolor transparent (1,1.,colorframe); else : addto monImageB contour (
Re: [NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
> On 21 Dec 2020, at 16:09, Garulfo wrote: > > Hi, > > > * I try to "remove the paths of text" from a metapost pictures to let > the background visible. > > * Using > https://mailman.ntg.nl/pipermail/ntg-context/2018/thread.html#92725 > > * I was able to get the following with one glyph (MVE code below) > > https://wiki.contextgarden.net/images/d/d2/test_extract_glyphs.pdf > > > 2 questions: > > 1/ for some fonts (e.g. dejavu vs latin modern) the "encompassing" path > of the B glyph can switch from B[1] to B[Bn]. Is there a trick to > identify which id match with "the encompassing" path ? What you get is the order of the paths as defined in the font, which is arbitrary, as you discovered. A quick trick (that will not always work, but should work quite well for font variations of alphabetics) is to check the actual arclength of the paths. The longest one will typically be the outer one. But much depends on the font, so a generic solution is likely quite complicated. Consider an outline font’s colon glyph ;) > > 2/ now, I would like to do the same, but for text... a kind of > derivative of "textext" or "outlinetext". > Would you please give me some guidelines ? > does it already exist ? > should I use something like \handletokens, \scantokens ? > do you have examples where I can get inspiration ? > > > Thanks again for your help, > Garulfo > > > %== > > > > > \starttext > > %-- > > \startluacode > > function document.outlinepaths(character) >local chardata = fonts.hashes.characters[true] -- by unicode >local shapedata = fonts.hashes.shapes[true] -- by index >local c = chardata[character] >if c and c.index and shapedata then >local shapeglyphs = shapedata.glyphs or { } >local glyph = shapeglyphs[c.index] >if glyph and (glyph.segments or glyph.sequence) then >local units = shapedata.units or 1000 >local factor = 100/units >return fonts.metapost.paths(glyph,factor) >end >end >return { } > end > > function document.defineoutline(char,target) >local outlines = document.outlinepaths(char) >local nofpaths = #outlines >context("path %s[] ;",target) >context("numeric %sn ; %sn := %s ;",target,target,nofpaths) >for i=1,nofpaths do >context("%s[%i] := %s ; ",target,i,outlines[i]) >end > end > > \stopluacode > > %-- > > \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}} > > %-- > > \startMPpage > > numeric dimA ; dimA := 20cm; > > path pathbackground ; > pathbackground := unitsquare scaled dimA ; > fill pathbackground withshademethod "linear" withshadedirection(0,1) > withshadecolors (red,blue); > > %-- > > \mpdefineoutlines{B}{B} > > %-- > > numeric dimB ; dimB := 2cm; > numeric vratio ; vratio := 2; > > path frame ; > frame := unitsquare > xscaled (dimA - 2 * dimB) > yscaled (dimA / vratio) > shifted (dimB , (dimA - (dimA / vratio))/2 ); > > %-- > > pair shift ; shift := center frame; > numeric scal ; scal := (0.9) * (10cm / (bbheight B[1])) ; > > picture monImageB; monImageB := nullpicture; > addto monImageB contour > (B[1] shifted (- center B[1]) scaled scal) > shifted shift > withpostscript "collect"; > > addto monImageB contour > frame > withpostscript "evenodd"; > > for i=2 upto Bn : > addto monImageB contour >(B[i] shifted (- center B[1]) scaled scal) >shifted shift; > endfor ; > > %-- > > draw monImageB withcolor white; > > \stopMPpage > > \stoptext > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ Taco Hoekwater Elvenkind BV ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/
[NTG-context] MetaFun - "remove the paths of text" from a rectangle to let the background visible
Hi, * I try to "remove the paths of text" from a metapost pictures to let the background visible. * Using https://mailman.ntg.nl/pipermail/ntg-context/2018/thread.html#92725 * I was able to get the following with one glyph (MVE code below) https://wiki.contextgarden.net/images/d/d2/test_extract_glyphs.pdf 2 questions: 1/ for some fonts (e.g. dejavu vs latin modern) the "encompassing" path of the B glyph can switch from B[1] to B[Bn]. Is there a trick to identify which id match with "the encompassing" path ? 2/ now, I would like to do the same, but for text... a kind of derivative of "textext" or "outlinetext". Would you please give me some guidelines ? does it already exist ? should I use something like \handletokens, \scantokens ? do you have examples where I can get inspiration ? Thanks again for your help, Garulfo %== \starttext %-- \startluacode function document.outlinepaths(character) local chardata = fonts.hashes.characters[true] -- by unicode local shapedata = fonts.hashes.shapes[true] -- by index local c = chardata[character] if c and c.index and shapedata then local shapeglyphs = shapedata.glyphs or { } local glyph = shapeglyphs[c.index] if glyph and (glyph.segments or glyph.sequence) then local units = shapedata.units or 1000 local factor = 100/units return fonts.metapost.paths(glyph,factor) end end return { } end function document.defineoutline(char,target) local outlines = document.outlinepaths(char) local nofpaths = #outlines context("path %s[] ;",target) context("numeric %sn ; %sn := %s ;",target,target,nofpaths) for i=1,nofpaths do context("%s[%i] := %s ; ",target,i,outlines[i]) end end \stopluacode %-- \def\mpdefineoutlines#1#2{\ctxlua{document.defineoutline(\number`#1,"#2")}} %-- \startMPpage numeric dimA ; dimA := 20cm; path pathbackground ; pathbackground := unitsquare scaled dimA ; fill pathbackground withshademethod "linear" withshadedirection(0,1) withshadecolors (red,blue); %-- \mpdefineoutlines{B}{B} %-- numeric dimB ; dimB := 2cm; numeric vratio ; vratio := 2; path frame ; frame := unitsquare xscaled (dimA - 2 * dimB) yscaled (dimA / vratio) shifted (dimB , (dimA - (dimA / vratio))/2 ); %-- pair shift ; shift := center frame; numeric scal ; scal := (0.9) * (10cm / (bbheight B[1])) ; picture monImageB; monImageB := nullpicture; addto monImageB contour (B[1] shifted (- center B[1]) scaled scal) shifted shift withpostscript "collect"; addto monImageB contour frame withpostscript "evenodd"; for i=2 upto Bn : addto monImageB contour (B[i] shifted (- center B[1]) scaled scal) shifted shift; endfor ; %-- draw monImageB withcolor white; \stopMPpage \stoptext ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Problem with shading in Metafun (LMTX)
Nice. It works again. Thank you very much! Cordially, Jairo El lun., 21 de dic. de 2020 2:45 a. m., Hans Hagen escribió: > On 12/21/2020 4:46 AM, Jairo A. del Rio wrote: > > While shading works with MkIV, with LMTX the following breaks: > > > > > > \startMPpage > > > > comment("two shades with named colors"); > > > > fill fullcircle scaled 5cm > > > > withshademethod "circular" > > > > withshadecolors ((1,0,0),(0,0,1,0)) > > > > ; > > > > fill fullcircle scaled 5cm shifted (6cm,0) > > > > withshademethod "circular" > > > > withcolor (1,0,0,0) shadedinto "blue" > > > > ; > > > > \stopMPpage > > in mp-base.mpxl there is a ; missing > > temp_any_u = u > > must be: > > temp_any_u := u ; > > (in the min and max macros) > > (i replaced some internal names as part of a cleanup) > > (there will be a new upload later that will also fix this) > > 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 > - > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Problem with shading in Metafun (LMTX)
On 12/21/2020 4:46 AM, Jairo A. del Rio wrote: While shading works with MkIV, with LMTX the following breaks: \startMPpage comment("two shades with named colors"); fill fullcircle scaled 5cm withshademethod "circular" withshadecolors ((1,0,0),(0,0,1,0)) ; fill fullcircle scaled 5cm shifted (6cm,0) withshademethod "circular" withcolor (1,0,0,0) shadedinto "blue" ; \stopMPpage in mp-base.mpxl there is a ; missing temp_any_u = u must be: temp_any_u := u ; (in the min and max macros) (i replaced some internal names as part of a cleanup) (there will be a new upload later that will also fix this) 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Problem with shading in Metafun (LMTX)
While shading works with MkIV, with LMTX the following breaks: \startMPpage comment("two shades with named colors"); fill fullcircle scaled 5cm withshademethod "circular" withshadecolors ((1,0,0),(0,0,1,0)) ; fill fullcircle scaled 5cm shifted (6cm,0) withshademethod "circular" withcolor (1,0,0,0) shadedinto "blue" ; \stopMPpage The log says: metafun > log > metafun > log > error: Unknown relation will be considered false metafun > log > metapost > log > metapost > log > metapost > log > : metapost > log > if(EXPR0)>temp_any_u: metapost > log > temp_any_u:=(EXPR0);fi ENDFOR metapost > log > max->begingroup.save.temp_any_u;if.pair(EXPR2):pair.temp_any_u.elseif.string(EXPR2): string.temp_any_u.fi ;temp_any_u=(EXPR2)for.i=(TEXT3):if.i>temp_any_u:temp_any_u:=i;fi.endfor metapost > log > .temp_any_u.endgroup metapost > log > mfun_max_radius->...er(EXPR2)-xpart.center(EXPR2))++(ypart.center(EXPR2)-ypart.lrcorner(EXPR2)),(xpart.urcorner(EXPR2)-xpart.center(EXPR2))++(ypart.urcorner(EXPR2)-ypart.center(EXPR2))) metapost > log > endgroup metapost > log > withshademethod->...cimal.center(EXPR0)withprescript"sh_center_b="(EXPR0)withprescript"sh_radius_a=""sh_radius_b="_max_radius((EXPR0)) metapost > log > fi metapost > log > metapost > log > withprescript metapost > log > withshadecolors->...hprescript"sh_color_a_"_shade_step&"="(EXPR0)withprescript"sh_color_b_"_shade_step&"="(EXPR1)else:withprescript metapost > log > "sh_color=in... metapost > log > <*> comment("two shades with named colors"); fill fullcircle scaled 5cm withshademethod "circular" withshadecolors ((1,0,0),(0,0,1,0)) metafun > log > metafun > log > Oh dear. I can't decide if the expression above is positive, negative, or zero. So this comparison test won't be 'true'. metafun > log > metapost > log > ; fill fullcircle scaled 5cm shifted (6cm,0) withshademethod "... metapost > log > Hans told me not to use the B tag, so I'm asking first in case I've missed something. Thank you in advance. Best regards, Jairo ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] A link to an example of poster build with ConTeXt
Hi, it's really fun to play with ConTeXt and MetaPost / Metafun to build posters (color, fonts, alignment, scaling, randomized geometry). Thanks to the ConTeXt team to make it easy. PDF: https://salsa.debian.org/zleap-guest/libreplanet2021/-/raw/master/ConTeXt_version/poster_libreplanet_2021.pdf Source code: https://salsa.debian.org/zleap-guest/libreplanet2021/-/blob/master/README.md ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On 12/17/2020 3:03 PM, Neven Sajko wrote: Hello all, I am completely new to TeX, ConTeXt, MetaPost, etc. (Except for some MathJax snippets and the like.) I am using Aditya's LMTX package from AUR on Archlinux. I have some SVGs (generated by the Julia Gadfly package) that represent 2D plots of some functions, and I would like to include the SVGs in a ConTeXt document so it ends up as PDF. I started creating the document by including the SVGs using the new LMTX MetaPost SVG feature, however at this point I don't know how to proceed... This is the situation: the source SVGs look fine, but after including them in the document with the new ConTeXt feature mentioned above, the bottom-most part of the image is "cut off" (not visible). In the attached ZIP I included all relevant files (.tex, .svg, .pdf, ...), as well as PNG screenshots of the PDFs (in case the issue is PDF-viewer-specific, I'm using Chromium as the PDF viewer). I tried doing this in two different ways: using includesvgfile with the offset option, and using startMPcode with setbounds in the MetaFun code. In both cases I just get blank space instead of the cut-off content How can I fix this? Related question: is it possible to get the MetaPost code that (I think) the SVG gets translated to? I'm interested in how it looks like. \enabletrackers[metapost.svg.result] but i have a fix that does clipping different - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On 12/17/20 6:45 PM, Pablo Rodriguez wrote: > On 12/17/20 5:08 PM, Neven Sajko wrote: >> On Thu, 17 Dec 2020 at 15:27, Aditya Mahajan wrote: >> [...] >>> Can you check with a desktop pdf viewer as well. >> >> It looks the same with MuPDF. > > Hi Neven, > > it seems to be an issue with the conversion of the SVG file. Hans, I thought it was an issue with the MP conversion of the SVG file. I was wrong: it is an issue on how LMTX deals with the SVG conversion in MP. MkIV is totally fine respecting image dimensions. Many thanks for your help, Pablo -- http://www.ousia.tk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On 12/17/20 5:08 PM, Neven Sajko wrote: > On Thu, 17 Dec 2020 at 15:27, Aditya Mahajan wrote: > [...] >> Can you check with a desktop pdf viewer as well. > > It looks the same with MuPDF. Hi Neven, it seems to be an issue with the conversion of the SVG file. > This is a combined TeX file containing two different ways I took to > try to accomplish the same thing: How about a much simpler approach? \starttext \framed[offset=overlay] {\externalfigure[hammingCoderStopwatch-hammingCoder-gcc-RowsSparse-1023-1013.svg] [width=\textwidth, offset=20pt]} \stoptext In that case, if you use \externalfigure, ConTeXt will invoke Inkscape to convert the file. The output is way better. Just in case it may help, Pablo -- http://www.ousia.tk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On Thu, 17 Dec 2020 at 15:27, Aditya Mahajan wrote: > OT but can Gadfly directly produce PDFs? [...] Yes it can. Going to try that route if this doesn't work out. > [..] Depending on how complicated plots you want to generate, you can also > use metapost graph module or pdfplots package for drawing 2D plots. OT, but that wouldn't work for me easily, because I don't actually know what function I'm plotting - it's a probability density function estimation (which is similar to a histogram, but continuous), where I only provide the data points and Gadfly takes care of everything else. > Can you check with a desktop pdf viewer as well. It looks the same with MuPDF. > The mailing list has a size limit for attachments, so I think that your zip > file did not get included in your message. Could you just include the tex > file and maybe upload the svg somewhere and include a link. This is a combined TeX file containing two different ways I took to try to accomplish the same thing: \starttext {\switchtobodyfont[2pt] {\framed[offset=overlay]{\includesvgfile[../hammingCoderStopwatch-hammingCoder-gcc-RowsSparse-1023-1013.svg][offset=20pt]}} {some offset} \startMPcode draw lmt_svg [ filename = "../hammingCoderStopwatch-hammingCoder-gcc-RowsSparse-1023-1013.svg" ]; setbounds currentpicture to boundingbox currentpicture enlarged 20pt; \stopMPcode } \stoptext The SVG: https://drive.google.com/file/d/1_JsIfA9cgEs5_x7FFJrUWPPe3Ht8JnIm/view?usp=sharing To be specific, what gets cut off is the bottom half of each number on the x-axis and the entire x-axis label. Thanks, Neven ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On Thu, 17 Dec 2020, Neven Sajko wrote: > Hello all, > > I am completely new to TeX, ConTeXt, MetaPost, etc. (Except for some > MathJax snippets and the like.) > > I am using Aditya's LMTX package from AUR on Archlinux. > > I have some SVGs (generated by the Julia Gadfly package) that > represent 2D plots of some functions, and I would like to include the > SVGs in a ConTeXt document so it ends up as PDF. OT but can Gadfly directly produce PDFs? Depending on how complicated plots you want to generate, you can also use metapost graph module or pdfplots package for drawing 2D plots. > I started creating > the document by including the SVGs using the new LMTX MetaPost SVG > feature, however at this point I don't know how to proceed... > > This is the situation: the source SVGs look fine, but after including > them in the document with the new ConTeXt feature mentioned above, the > bottom-most part of the image is "cut off" (not visible). In the > attached ZIP I included all relevant files (.tex, .svg, .pdf, ...), as > well as PNG screenshots of the PDFs (in case the issue is > PDF-viewer-specific, I'm using Chromium as the PDF viewer). Can you check with a desktop pdf viewer as well. > I tried doing this in two different ways: using includesvgfile with > the offset option, and using startMPcode with setbounds in the MetaFun > code. In both cases I just get blank space instead of the cut-off > content > > How can I fix this? The mailing list has a size limit for attachments, so I think that your zip file did not get included in your message. Could you just include the tex file and maybe upload the svg somewhere and include a link. 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
Hello all, I am completely new to TeX, ConTeXt, MetaPost, etc. (Except for some MathJax snippets and the like.) I am using Aditya's LMTX package from AUR on Archlinux. I have some SVGs (generated by the Julia Gadfly package) that represent 2D plots of some functions, and I would like to include the SVGs in a ConTeXt document so it ends up as PDF. I started creating the document by including the SVGs using the new LMTX MetaPost SVG feature, however at this point I don't know how to proceed... This is the situation: the source SVGs look fine, but after including them in the document with the new ConTeXt feature mentioned above, the bottom-most part of the image is "cut off" (not visible). In the attached ZIP I included all relevant files (.tex, .svg, .pdf, ...), as well as PNG screenshots of the PDFs (in case the issue is PDF-viewer-specific, I'm using Chromium as the PDF viewer). I tried doing this in two different ways: using includesvgfile with the offset option, and using startMPcode with setbounds in the MetaFun code. In both cases I just get blank space instead of the cut-off content How can I fix this? Related question: is it possible to get the MetaPost code that (I think) the SVG gets translated to? I'm interested in how it looks like. Thanks, Neven ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] upload / metafun
On 12/15/2020 9:18 PM, Pablo Rodriguez wrote: On 12/15/20 8:24 PM, Otared Kavian wrote: [...] However after running install. sh on MacOS, I still get current version: 2020.12.10 22:26, even after removing the .tma files.> So I guess I have to wait a little bit for the new version to be upoaded. Hans, I’m afraid I’m having the same issue as Otared. $ curl I http://lmtx.pragma-ade.com/install-lmtx/texmf-context.zip Last-Modified: Thu, 10 Dec 2020 21:30:45 GMT $ curl -I http://lmtx.pragma-ade.com/install-lmtx/texmf.zip Last-Modified: Thu, 10 Dec 2020 21:30:47 GMT This is from some minute ago (Date: Tue, 15 Dec 2020 20:15:33 GMT). I guess this might be the reason for an oudated brand new install. I think there might be an issue here. I'll check it when I've finished what I'm doing now (some more mp stuff). 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] upload / metafun
On 12/15/20 8:24 PM, Otared Kavian wrote: > [...] > However after running install. sh on MacOS, I still get current > version: 2020.12.10 22:26, even after removing the .tma files.> So I guess I > have to wait a little bit for the new version to be > upoaded. Hans, I’m afraid I’m having the same issue as Otared. $ curl I http://lmtx.pragma-ade.com/install-lmtx/texmf-context.zip Last-Modified: Thu, 10 Dec 2020 21:30:45 GMT $ curl -I http://lmtx.pragma-ade.com/install-lmtx/texmf.zip Last-Modified: Thu, 10 Dec 2020 21:30:47 GMT This is from some minute ago (Date: Tue, 15 Dec 2020 20:15:33 GMT). I guess this might be the reason for an oudated brand new install. I think there might be an issue here. Many thanks for your help, Pablo -- http://www.ousia.tk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] upload / metafun
Hi Hans, Thanks for the new upload. With your comments, I understand that, following the discussion with Aditya, when using the new version I should not define in Metafun a new function named dotlabel in order to have a square dot… Actually I called it mydotlabel in order to be able to change the shape of the dot, so I will be on the safe side when I can download the new version. However after running install. sh on MacOS, I still get current version: 2020.12.10 22:26, even after removing the .tma files. So I guess I have to wait a little bit for the new version to be upoaded. Best regards: Otared > On 15 Dec 2020, at 10:35, Hans Hagen wrote: > > Hi, > > I uploaded a new lmtx. This time some work has been done at the metafun end. > > At the tex end we're working on some overload protection mechanism which > involves tagging many macro so that will take a while (most tagging is done > but checking left over cases take time). > > So, I wondered if we can do something similar in metapost: flag macros and > variables in order to issue a warnings when a dangerous overload happens. > > The current lmtx has this as an experiment: primitives, permanent, immutable > and mutable (so far); you can look at the *.mpxl files to get an idea. If you > say for instance > >path fullcircle; > > there will be a warning > > metapost> overloading immutable 'fullcircle' > > or when > > \enabledirectives[metapost.overloadmode=error] > > has been given you get an error. > > The implementation is rather simple and non intrusive and differs from > the one in tex. There it is tightly integrated for all kind of reasons > (millions of macro definitions per run so efficiency matters). Also, in > metapost variables (tags) can have complex name constructions and we only > test the top level. When a overload happens (overloadmode internal <> 0) a > lua callback takes care of it. > > A side effect is that we can query all hash entries and check for consistency > which is what i've done and am doing now. Of course that can introduce issues > ... just that you know. > > 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 > - > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] RE : upload / metafun
Hi, FYI, when running install.bat I see problem downloading exe mtx-install | changed : 0 % : 2391552 : tex/texmf-win64/bin/luametatex.exemtx-install | tex/texmf-win64/bin/luametatex.exe, trying again: After several attempts, the install.bat run stops.Thanks Joseph De : Hans HagenEnvoyé le :mardi 15 décembre 2020 10:35À : mailing list for ConTeXt usersObjet :[NTG-context] upload / metafun Hi, I uploaded a new lmtx. This time some work has been done at the metafun end. At the tex end we're working on some overload protection mechanism which involves tagging many macro so that will take a while (most tagging is done but checking left over cases take time). So, I wondered if we can do something similar in metapost: flag macros and variables in order to issue a warnings when a dangerous overload happens. The current lmtx has this as an experiment: primitives, permanent, immutable and mutable (so far); you can look at the *.mpxl files to get an idea. If you say for instance path fullcircle; there will be a warning metapost > overloading immutable 'fullcircle' or when \enabledirectives[metapost.overloadmode=error] has been given you get an error. The implementation is rather simple and non intrusive and differs fromthe one in tex. There it is tightly integrated for all kind of reasons (millions of macro definitions per run so efficiency matters). Also, in metapost variables (tags) can have complex name constructions and we only test the top level. When a overload happens (overloadmode internal <> 0) a lua callback takes care of it. A side effect is that we can query all hash entries and check for consistency which is what i've done and am doing now. Of course that can introduce issues ... just that you know. 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-___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-contextwebpage : http://www.pragma-ade.nl / http://context.aanhet.netarchive : https://bitbucket.org/phg/context-mirror/commits/wiki : http://contextgarden.net___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] upload / metafun
Hi, I uploaded a new lmtx. This time some work has been done at the metafun end. At the tex end we're working on some overload protection mechanism which involves tagging many macro so that will take a while (most tagging is done but checking left over cases take time). So, I wondered if we can do something similar in metapost: flag macros and variables in order to issue a warnings when a dangerous overload happens. The current lmtx has this as an experiment: primitives, permanent, immutable and mutable (so far); you can look at the *.mpxl files to get an idea. If you say for instance path fullcircle; there will be a warning metapost> overloading immutable 'fullcircle' or when \enabledirectives[metapost.overloadmode=error] has been given you get an error. The implementation is rather simple and non intrusive and differs from the one in tex. There it is tightly integrated for all kind of reasons (millions of macro definitions per run so efficiency matters). Also, in metapost variables (tags) can have complex name constructions and we only test the top level. When a overload happens (overloadmode internal <> 0) a lua callback takes care of it. A side effect is that we can query all hash entries and check for consistency which is what i've done and am doing now. Of course that can introduce issues ... just that you know. 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
On 12/10/2020 8:37 PM, Aditya Mahajan wrote: On Thu, 10 Dec 2020, Hans Hagen wrote: dotlabel uses a pen to draw the dot, and I am not sure why it uses that rather than a path. Here is a (to me) simpler definition, where you can change the shape: just look in the pdf ... in your case the dot is a n point path while otherwise it uses the default postscript pen (which is a dot) Ah, that makes sense. it surprised me that a math guru like you doesn't do this: vardef dotlabel@#(expr s,z) text t_ = % draw textext("$\bullet$") scaled (1/2) shifted z ; % draw textext("$\blacktriangle$") scaled (1/4) shifted z ; draw textext("$\blacksquare$") scaled (1/4) shifted z ; label@#(s,z) t_ ; enddef ; \stopMPdefinitions Ha! I know that you said this as a joke, but as someone who did try to use the old font-based picture environment in LaTeX back in the day, I would never try to use fonts for "drawing". Especially, math fonts, where every designer has a different idea of what the shape should look like. ah pictex memories ... drawing lines with cmr5 periods ... but actually, we can define a stable font with symbols in metafun and use that (quite efficient too) and then one can even cut'n'paste those tiny symbols (don't worry ... not much of a challenge so low on my list) 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
On Thu, 10 Dec 2020, Hans Hagen wrote: > > dotlabel uses a pen to draw the dot, and I am not sure why it uses that > > rather > > than a path. Here is a (to me) simpler definition, where you can change the > > shape: > > just look in the pdf ... in your case the dot is a n point path while > otherwise > it uses the default postscript pen (which is a dot) Ah, that makes sense. > it surprised me that a math guru like you doesn't do this: > > vardef dotlabel@#(expr s,z) text t_ = > % draw textext("$\bullet$") scaled (1/2) shifted z ; > % draw textext("$\blacktriangle$") scaled (1/4) shifted z ; > draw textext("$\blacksquare$") scaled (1/4) shifted z ; > label@#(s,z) t_ ; > enddef ; > \stopMPdefinitions Ha! I know that you said this as a joke, but as someone who did try to use the old font-based picture environment in LaTeX back in the day, I would never try to use fonts for "drawing". Especially, math fonts, where every designer has a different idea of what the shape should look like. 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
On 12/10/2020 7:04 PM, Aditya Mahajan wrote: On Thu, 10 Dec 2020, Otared Kavian wrote: Hi Aditya, Thank you very much ! That's great indeed, you gave me an elegant solution. One more question, in order for me to understand a little more: when defining a new dotlabel as you do, might it not conflict with the internal definitions of dotlabel in Metafun in some other place? Maybe it is safer for me to call it something like « dotshapelabel » ? In general, I agree. Redefining internal macros has the advantage that your code doesn't have to change. See, for example: it depends a bit ... redefing dotlabel in a compatible way is kind of ok, but using/redefining \foo_bar_something_internal is a real bad idea as that is not part of the interface (okay, i know that there are macro packages out there where it's part of the concept to redefine low level stuff for styles but in context we should try to avoid it ... we should then adapt the high level interface to suport something) it also depends who does it ... i know that aditya knows the internals well enough to deal with it (one of my concerns is always that while we try to come up with efficient solutions it's easy to make things inefficient but that's not the case here ... unless of course we want to nurture the 'context is slow' meme) 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
On 12/10/2020 6:44 PM, Aditya Mahajan wrote: On Thu, 10 Dec 2020, Otared Kavian wrote: Hi all, In Metafun when representing a point I woul dlike to have some dots represented by a square (or even by another scalable symbol): for instance in the following I would like the dot at the point B to be a square: \starttext \startMPcode draw (2cm,3cm) -- (3cm,5cm) ; dotlabel(textext("\switchtobodyfont[8pt]" & "A"), (2cm,3cm)) withpen pencircle scaled 12pt withcolor transparent("exclusion",.5,red) ; dotlabel(textext("\switchtobodyfont[8pt]" & "B"), (3cm,5cm)) withpen pencircle scaled 12pt withcolor transparent("exclusion",.5,red) ; \stopMPcode \stoptext I wonder whether it is possible to define something like « drawsquaredot » or « squaredotlabel » in order to do this. dotlabel uses a pen to draw the dot, and I am not sure why it uses that rather than a path. Here is a (to me) simpler definition, where you can change the shape: just look in the pdf ... in your case the dot is a n point path while otherwise it uses the default postscript pen (which is a dot) actually fullcircle is pencircle so you can ponder why that is the case -) \startMPdefinitions newpath dotlabelshape; dotlabelshape := fullcircle; vardef dotlabel@#(expr s,z) text t_ = label@#(s,z) t_ ; fill (dotlabelshape scaled 2dotlabeldiam) shifted z t_; enddef ; \stopMPdefinitions \starttext \startMPcode newpath p ; p := (2cm, 3cm) -- (3cm, 5cm); dotlabeldiam := 12pt; % Default draw p; dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) withcolor transparent("exclusion",.5,red) ; dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) withcolor transparent("exclusion",.5,red) ; % Using a square "dot" p := p shifted (5cm, 0); dotlabelshape := fullsquare; draw p; dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) withcolor transparent("exclusion",.5,red) ; dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) withcolor transparent("exclusion",.5,red) ; \stopMPcode \stoptext These types of macros are also a good candidate for the new LMTX syntax, where we can make all components configurable via a key-value interface (labeldistance etc. as well). it surprised me that a math guru like you doesn't do this: vardef dotlabel@#(expr s,z) text t_ = % draw textext("$\bullet$") scaled (1/2) shifted z ; % draw textext("$\blacktriangle$") scaled (1/4) shifted z ; draw textext("$\blacksquare$") scaled (1/4) shifted z ; label@#(s,z) t_ ; enddef ; \stopMPdefinitions - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
On Thu, 10 Dec 2020, Otared Kavian wrote: > Hi Aditya, > Thank you very much ! > That's great indeed, you gave me an elegant solution. > > One more question, in order for me to understand a little more: when defining > a new dotlabel as you do, might it not conflict with the internal definitions > of dotlabel in Metafun in some other place? > Maybe it is safer for me to call it something like « dotshapelabel » ? In general, I agree. Redefining internal macros has the advantage that your code doesn't have to change. See, for example: https://github.com/adityam/mp-sketch/blob/master/mp-sketch.mp 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
Hi Aditya, Thank you very much ! That's great indeed, you gave me an elegant solution. One more question, in order for me to understand a little more: when defining a new dotlabel as you do, might it not conflict with the internal definitions of dotlabel in Metafun in some other place? Maybe it is safer for me to call it something like « dotshapelabel » ? Best regards and agin many thanks: Otared > On 10 Dec 2020, at 18:44, Aditya Mahajan wrote: > > On Thu, 10 Dec 2020, Otared Kavian wrote: > >> Hi all, >> >> In Metafun when representing a point I woul dlike to have some dots >> represented by a square (or even by another scalable symbol): for instance >> in the following I would like the dot at the point B to be a square: >> >> \starttext >> \startMPcode >> draw (2cm,3cm) -- (3cm,5cm) ; >> dotlabel(textext("\switchtobodyfont[8pt]" & "A"), (2cm,3cm)) >> withpen pencircle scaled 12pt >> withcolor transparent("exclusion",.5,red) ; >> >> dotlabel(textext("\switchtobodyfont[8pt]" & "B"), (3cm,5cm)) >> withpen pencircle scaled 12pt >> withcolor transparent("exclusion",.5,red) ; >> \stopMPcode >> \stoptext >> >> I wonder whether it is possible to define something like « drawsquaredot » >> or « squaredotlabel » in order to do this. > > dotlabel uses a pen to draw the dot, and I am not sure why it uses that > rather than a path. Here is a (to me) simpler definition, where you can > change the shape: > > \startMPdefinitions > newpath dotlabelshape; > > dotlabelshape := fullcircle; > > vardef dotlabel@#(expr s,z) text t_ = >label@#(s,z) t_ ; >fill (dotlabelshape scaled 2dotlabeldiam) shifted z t_; > enddef ; > \stopMPdefinitions > > \starttext > \startMPcode > newpath p ; > p := (2cm, 3cm) -- (3cm, 5cm); > dotlabeldiam := 12pt; > > % Default > draw p; > dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) >withcolor transparent("exclusion",.5,red) ; > > dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) >withcolor transparent("exclusion",.5,red) ; > > % Using a square "dot" > p := p shifted (5cm, 0); > dotlabelshape := fullsquare; > > draw p; > dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) >withcolor transparent("exclusion",.5,red) ; > > dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) >withcolor transparent("exclusion",.5,red) ; > \stopMPcode > \stoptext > > These types of macros are also a good candidate for the new LMTX syntax, > where we can make all components configurable via a key-value interface > (labeldistance etc. as well). > > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
On Thu, 10 Dec 2020, Otared Kavian wrote: > Hi all, > > In Metafun when representing a point I woul dlike to have some dots > represented by a square (or even by another scalable symbol): for instance in > the following I would like the dot at the point B to be a square: > > \starttext > \startMPcode > draw (2cm,3cm) -- (3cm,5cm) ; > dotlabel(textext("\switchtobodyfont[8pt]" & "A"), (2cm,3cm)) > withpen pencircle scaled 12pt > withcolor transparent("exclusion",.5,red) ; > > dotlabel(textext("\switchtobodyfont[8pt]" & "B"), (3cm,5cm)) > withpen pencircle scaled 12pt > withcolor transparent("exclusion",.5,red) ; > \stopMPcode > \stoptext > > I wonder whether it is possible to define something like « drawsquaredot » or > « squaredotlabel » in order to do this. dotlabel uses a pen to draw the dot, and I am not sure why it uses that rather than a path. Here is a (to me) simpler definition, where you can change the shape: \startMPdefinitions newpath dotlabelshape; dotlabelshape := fullcircle; vardef dotlabel@#(expr s,z) text t_ = label@#(s,z) t_ ; fill (dotlabelshape scaled 2dotlabeldiam) shifted z t_; enddef ; \stopMPdefinitions \starttext \startMPcode newpath p ; p := (2cm, 3cm) -- (3cm, 5cm); dotlabeldiam := 12pt; % Default draw p; dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) withcolor transparent("exclusion",.5,red) ; dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) withcolor transparent("exclusion",.5,red) ; % Using a square "dot" p := p shifted (5cm, 0); dotlabelshape := fullsquare; draw p; dotlabel(textext("\switchtobodyfont[8pt]" & "A"), point 0 of p) withcolor transparent("exclusion",.5,red) ; dotlabel(textext("\switchtobodyfont[8pt]" & "B"), point 1 of p) withcolor transparent("exclusion",.5,red) ; \stopMPcode \stoptext These types of macros are also a good candidate for the new LMTX syntax, where we can make all components configurable via a key-value interface (labeldistance etc. as well). 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Metafun: is it possible to redefine dotlabel to draw a square ?
Hi all, In Metafun when representing a point I woul dlike to have some dots represented by a square (or even by another scalable symbol): for instance in the following I would like the dot at the point B to be a square: \starttext \startMPcode draw (2cm,3cm) -- (3cm,5cm) ; dotlabel(textext("\switchtobodyfont[8pt]" & "A"), (2cm,3cm)) withpen pencircle scaled 12pt withcolor transparent("exclusion",.5,red) ; dotlabel(textext("\switchtobodyfont[8pt]" & "B"), (3cm,5cm)) withpen pencircle scaled 12pt withcolor transparent("exclusion",.5,red) ; \stopMPcode \stoptext I wonder whether it is possible to define something like « drawsquaredot » or « squaredotlabel » in order to do this. If I use for B the command withpen pensquare scaled 12pt then the dot is a square, but the label B is drawn in a strange way. Thanks for any help: Otared ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
On 12/9/2020 9:38 PM, Aditya Mahajan wrote: Or just redefine shortened to accept a pair! \startMPdefinitions primarydef p shortened d = reverse ( ( reverse (p enlonged -xpart paired(d)) ) enlonged -ypart paired(d) ) enddef ; \stopMPdefinitions patched but then also: primarydef p enlonged len = begingroup if len == 0 : p elseif pair p : ... in order to save some energy when one is zero 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
Thanks Aditya! One can learn a lot with your answers ! In the Metafun manual I see enlonged but I did not know to use it. Best regards: Otared > On 9 Dec 2020, at 21:38, Aditya Mahajan wrote: > > On Wed, 9 Dec 2020, Otared Kavian wrote: > >> Hi Aditya, >> >> Thanks for the alternative method, which comes handy if one wishes to extend >> the straight line by a different amount at either end: >> >> \starttext >> \startMPcode >> z1 = (1cm,3cm) ; >> z2 = (5cm, 9cm) ; >> z3 = 1cm * dir(angle (z2 - z1)) shifted z2 ; >> z4 = -.5cm*dir(angle(z2 - z1)) shifted z1 ; >> draw z1 -- z3 ; >> draw z4 -- z1 ; >> draw z1 -- z2 withcolor red ; >> \stopMPcode >> \stoptext > > Or just redefine shortened to accept a pair! > > \startMPdefinitions > primarydef p shortened d = >reverse ( ( reverse (p enlonged -xpart paired(d)) ) enlonged -ypart > paired(d) ) > enddef ; > \stopMPdefinitions > > > > \starttext > \startMPpage > z1 = (1cm,3cm) ; > z2 = (5cm, 9cm) ; > draw (z1--z2) shortened (-1cm,-2cm) withcolor blue ; > draw (z1--z2) withcolor red ; > > \stopMPpage > \stoptext > > Now that if you really want to shorten a path, then cutends works better than > shortened > > \startMPdefinitions > primarydef p shortened d = >reverse ( ( reverse (p enlonged -xpart paired(d)) ) enlonged -ypart > paired(d) ) > enddef ; > \stopMPdefinitions > > > \starttext > \startMPpage > z1 = (1cm,3cm) ; > z2 = (5cm, 9cm) ; > path p, q; > p := z1 {up} .. {right} z2; > q := p shifted (6cm, 0); > > draw p withcolor red ; > draw p shortened (1cm,2cm) withcolor blue ; > > draw q withcolor green ; > draw q cutends (1cm,2cm) withcolor blue ; > > \stopMPpage > \stoptext > > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
On Wed, 9 Dec 2020, Otared Kavian wrote: > Hi Aditya, > > Thanks for the alternative method, which comes handy if one wishes to extend > the straight line by a different amount at either end: > > \starttext > \startMPcode >z1 = (1cm,3cm) ; >z2 = (5cm, 9cm) ; >z3 = 1cm * dir(angle (z2 - z1)) shifted z2 ; >z4 = -.5cm*dir(angle(z2 - z1)) shifted z1 ; >draw z1 -- z3 ; >draw z4 -- z1 ; >draw z1 -- z2 withcolor red ; > \stopMPcode > \stoptext Or just redefine shortened to accept a pair! \startMPdefinitions primarydef p shortened d = reverse ( ( reverse (p enlonged -xpart paired(d)) ) enlonged -ypart paired(d) ) enddef ; \stopMPdefinitions \starttext \startMPpage z1 = (1cm,3cm) ; z2 = (5cm, 9cm) ; draw (z1--z2) shortened (-1cm,-2cm) withcolor blue ; draw (z1--z2) withcolor red ; \stopMPpage \stoptext Now that if you really want to shorten a path, then cutends works better than shortened \startMPdefinitions primarydef p shortened d = reverse ( ( reverse (p enlonged -xpart paired(d)) ) enlonged -ypart paired(d) ) enddef ; \stopMPdefinitions \starttext \startMPpage z1 = (1cm,3cm) ; z2 = (5cm, 9cm) ; path p, q; p := z1 {up} .. {right} z2; q := p shifted (6cm, 0); draw p withcolor red ; draw p shortened (1cm,2cm) withcolor blue ; draw q withcolor green ; draw q cutends (1cm,2cm) withcolor blue ; \stopMPpage \stoptext 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
Hi Aditya, Thanks for the alternative method, which comes handy if one wishes to extend the straight line by a different amount at either end: \starttext \startMPcode z1 = (1cm,3cm) ; z2 = (5cm, 9cm) ; z3 = 1cm * dir(angle (z2 - z1)) shifted z2 ; z4 = -.5cm*dir(angle(z2 - z1)) shifted z1 ; draw z1 -- z3 ; draw z4 -- z1 ; draw z1 -- z2 withcolor red ; \stopMPcode \stoptext Best regards: Otared > On 9 Dec 2020, at 18:37, Aditya Mahajan wrote: > > On Wed, 9 Dec 2020, Otared Kavian wrote: > >> Thanks a lot ! Indeed that does the job, which shows how wonderful Metafun >> is ! > > Or, if you want to use high school algebra: > > \starttext > \startMPcode >z1 = (1cm,3cm) ; >z2 = (5cm, 9cm) ; >z3 = 1cm * dir(angle (z2 - z1)) shifted z2; >draw z1 -- z3 ; >draw z1 -- z2 withcolor red; > \stopMPcode > \stoptext > > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
On Wed, 9 Dec 2020, Otared Kavian wrote: > Thanks a lot ! Indeed that does the job, which shows how wonderful Metafun is > ! Or, if you want to use high school algebra: \starttext \startMPcode z1 = (1cm,3cm) ; z2 = (5cm, 9cm) ; z3 = 1cm * dir(angle (z2 - z1)) shifted z2; draw z1 -- z3 ; draw z1 -- z2 withcolor red; \stopMPcode \stoptext 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
Hi Fabrice, Thanks a lot ! Indeed that does the job, which shows how wonderful Metafun is ! Best regards: Otared > On 9 Dec 2020, at 17:19, Fabrice L wrote: > > Hi, > >> Le 9 déc. 2020 à 10:57, Otared Kavian a écrit : >> >> Hi, >> >> I have a silly question: given two points in the plane >> z1 = (1cm,3cm) ; >> z2 = (5cm, 9cm) ; >> the command >> draw z1 -- z2 withpen pencircle scaled .5pt ; >> draws the line segment joining z1 and z2. How could I draw the line segment >> which goes a little further (say 1cm) than both the end points of this >> segment (that is in this example, a point before z1 and a point after z2 on >> the straight line) . >> Indeed it is possible to write the equation of the line and then compute by >> hand the coordinates of the new end points, but I think there is a simpler >> way in Metafun to do this. > > The shortened operation is the solution ! See MetaFun manual section 1.18 > > \starttext > \startMPpage > z1 = (1cm,3cm) ; > z2 = (5cm, 9cm) ; > draw (z1--z2) shortened -1cm withcolor blue ; > draw (z1--z2) withcolor red ; > > \stopMPpage > \stoptext > > Fabrice. > >> >> Thanks for any help: Otared >> >> >> ___ >> 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://context.aanhet.net >> archive : https://bitbucket.org/phg/context-mirror/commits/ >> wiki : http://contextgarden.net >> ___ > > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Metafun: how to draw a straight line past the end points
Hi, > Le 9 déc. 2020 à 10:57, Otared Kavian a écrit : > > Hi, > > I have a silly question: given two points in the plane > z1 = (1cm,3cm) ; > z2 = (5cm, 9cm) ; > the command > draw z1 -- z2 withpen pencircle scaled .5pt ; > draws the line segment joining z1 and z2. How could I draw the line segment > which goes a little further (say 1cm) than both the end points of this > segment (that is in this example, a point before z1 and a point after z2 on > the straight line) . > Indeed it is possible to write the equation of the line and then compute by > hand the coordinates of the new end points, but I think there is a simpler > way in Metafun to do this. The shortened operation is the solution ! See MetaFun manual section 1.18 \starttext \startMPpage z1 = (1cm,3cm) ; z2 = (5cm, 9cm) ; draw (z1--z2) shortened -1cm withcolor blue ; draw (z1--z2) withcolor red ; \stopMPpage \stoptext Fabrice. > > Thanks for any help: Otared > > > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Metafun: how to draw a straight line past the end points
Hi, I have a silly question: given two points in the plane z1 = (1cm,3cm) ; z2 = (5cm, 9cm) ; the command draw z1 -- z2 withpen pencircle scaled .5pt ; draws the line segment joining z1 and z2. How could I draw the line segment which goes a little further (say 1cm) than both the end points of this segment (that is in this example, a point before z1 and a point after z2 on the straight line) . Indeed it is possible to write the equation of the line and then compute by hand the coordinates of the new end points, but I think there is a simpler way in Metafun to do this. Thanks for any help: Otared ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Parallelizing typesetting of large documents with lots of cross-references
On 12/3/2020 12:04 PM, Stephen Gaito wrote: - very large (1,000+ pages), not that large, literate code is often verbatim so that doesn't take much runtime either - highly cross-referenced documents, ok, that demands runs - with embedded literate-programmed code (which needs concurrent compiling and execution), you only need to process those snippets when something has changed and there are ways in context to deal with that (like \typesetbuffer and such which only processes when something changed between runs) - containing multiple MetaFun graphics, those don't take time assuming effecitne metapost code 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Parallelizing typesetting of large documents with lots of cross-references
Hello, This email is largely a simple notification of one "Fool's" dream... ("Only Fools rush in where Angels fear to tread"). I am currently attempting to create "a" (crude) "tool" with which I can typeset: - very large (1,000+ pages), - highly cross-referenced documents, - with embedded literate-programmed code (which needs concurrent compiling and execution), - containing multiple MetaFun graphics, all based upon ConTeXt-LMTX. "In theory", it should be possible to typeset individual "sub-documents" (any section which is known to start on a page boundary rather than inside a page), and then re-combine the individual PDFs back into one single PDF for the whole document (complete with control over the page numbering). The inherent problem is that the *whole* of a ConTeXt document depends upon cross-references from *everywhere* else in the document. TeX and ConTeXt "solve" this problem by using a multi-pass approach (in, for example, 5 passes for the `luametatex` document). Between each pass, ConTeXt saves this multi-pass data (page numbers and cross-references) in the `*.tuc` file. Clearly any parallelization approach needs to have a process which coordinates the update and re-distribution of any changes in this multi-pass data obtained by typesetting each "sub-document". My current approach is to have a federation of Docker/Podman "pods". Each "pod" would have a number of ConTeXt workers, as well as (somewhere in the federation) a Lua based Multi-Pass-Data-coordinator. All work would be coordinated by messages sent and received over a corresponding federation of [NATS servers](https://nats.io/). (Neither [Podman](https://podman.io/) pods nor NATS message coordination are problems at the moment). **The real problem**, for typesetting a ConTeXt document, is the design of the critical process which will act as a "Multi-Pass-Data-coordinator". All ConTeXt sub-documents would be typeset in "once" mode using the latest complete set of "Multi-Pass-Data" obtained from the central coordinator. Then, once each typesetting run is complete, the resulting "Multi-Pass-Data" would be sent back to the coordinator to be used to update the coordinator's complete set of "Multi-Pass-Data" ready for any required next typesetting pass. (From the `context --help`: >mtx-context | --once only run once (no multipass data file is produced) I will clearly have to patch(?) the mtx-context.lua script to allow multipass data to be produced... this is probably not a problem). (There would also be a number of additional processes/containers for dependency analysis, build sequencing, compilation of code, execution or interpretation of the code, stitching the PDFs back into one PDF, etc -- these processes are also not the really critical problem at the moment). QUESTIONS: 1. Are there any other known attempts to parallelize context? 2. Are there any other obvious problems with my approach? 3. Is there any existing documentation on the contents of the `*.tuc` file? 4. If there is no such documentation, is there any naming pattern of the Lua functions which get/set this multi-pass information that I should be aware of? Many thanks for all of the very useful comments so far... Regards, Stephen Gaito ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Using ConTeXt-LMTX for modern Mathematically-Literate-Programming 1/2
Hans, As I said my desktop is elderly... it has a 2.8GHz processor, 16Gb of DDR3 memory, and a couple of old SATA1 hard disks, and only 3Mb of CPU cache... ... all well past its use by date for single threaded ConTeXt. ;-( So one way to get better performance for ConTeXt is to invest in a new ultra fast processor. Which will cost a lot, and use a lot of power which has to be cooled, which uses even more power Alternatively, for the same costs (or less), I can buy cheaper slower processors but have lots of threads (a cluster of Raspberry Pi 4 8Gb cards)... Alas this requires finding some way to parallelize ConTeXt (Fools rush in where Angels fear to tread ;-( Regards, Stephen Gaito On Wed, 2 Dec 2020 14:04:18 +0100 Hans Hagen wrote: > On 12/2/2020 10:40 AM, Stephen Gaito wrote: > > > Many thanks for your swift and helpful comments. > > > > After some *very crude* tests using the `luametatex` and > > `luametafun` documents, I find that while I *can* stop effective > > processing at various points in the LuaMetaTeX pipeline, the time > > difference overall is not really significant enough to bother with > > this approach. > > > > The principle problem is, as you suggested below, "stopping" the > > pipeline at the PDF stage (using for example the > > `pre_output_filter`) corrupted the `*.tuc` data which is for my > > purposes, critical. > > > > Your comment was: > > > >> but keep in mind that multipass data is flushed as part of the > >> shipout (because it is often location and order bound) > > > > For the record, using the `append_to_vlist_filter` callback, I did > > manage to drastically reduce the "pages" (which were all blank, not > > surprisingly). > > > > However, on my elderly desktop from 2008, both callbacks > > essentially cut only 6-8 seconds out of 18 seconds, for the > > `luametatex` document, and 190 seconds, for the `luametafun` > > document. > > hm, on my 2013 laptop the luametatex manual needs 10 sec (i have all > the fonts, so that includes a bunch) and a metafun manual should do > about 20 > > a test on am M1 mini needs half those times as reported yesterday > > i bet that on a modern desktop the luatex manual will do < 5 sec > > > In the case of the `luametafun` document, it is the MetaFun/MetaPost > > processing which, of course, is taking a long time (as it should, > > the graphics computations represent important but complex > > computations). > > One run or many due to xref? Maybe your machine has no significant > cpu cache? Do you run from disk or ssd? How much memory? > > > My ultimate goal is to parallelize the production of large, heavily > > cross-referenced, ConTeXt documents... more on this in a future > > email... > 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 > - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Using ConTeXt-LMTX for modern Mathematically-Literate-Programming 2/2
Hans, If my only constraints were ease of programming and moderate performance, I would completely agree that using mostly Lua plus (possibly) some C code for some targeted stuff that is really slow in Lua is the correct solution we are actually in agreement. Unfortunately, I have the *non-functional* requirement to *prove* the code's correctness this is the heart of what I have to write about. There is no getting out of this requirement So, some day it would be very useful to be able to directly embed a Lua wrapped ANSI-C shared library inside the new LuaMetaTex However, at the moment, as part of my parallelization attempts I can interact with my ANSI-C code over a network so I will use this approach for the near to medium time frames. Regards, Stephen Gaito On Wed, 2 Dec 2020 14:17:54 +0100 Hans Hagen wrote: > On 12/2/2020 11:43 AM, Stephen Gaito wrote: > > > Again, to my knowledge, Lua v5.4 has only one implementation (though > > this implementation *can* be compiled for a very wide range of > > CPU's). > > Lua has not many demands ... it can even run on tiny cpu's. It's all > rather plain C code. (And in luametatex we have no c++ ... all is > just C.) > > > Finally, the computational complexity of my proof engine, will be > > comparable to MetaFun/MetaPost... which I suspect you would not > > consider implementing in pure Lua. Some things are faster in C. > > Hard to say ... I think that the parser / expansion machinery in mp > is the bottleneck here (no fun to do that in lua). Redoing it in Lua > also is asking for compatibility issues. (btw, extensions are done in > lua anyway, as is the mp backend) > > > So yes I do need to implement it in ANSI-C wrapped in Lua (so that > > it can be used from *inside* ConTeXt). > > I would have to see the 'kind of code involved' in order to comment > on that. > > An option is to do most in lua and maybe some helpers for crititical > code in C. > 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 > - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Using ConTeXt-LMTX for modern Mathematically-Literate-Programming 2/2
On 12/2/2020 11:43 AM, Stephen Gaito wrote: Again, to my knowledge, Lua v5.4 has only one implementation (though this implementation *can* be compiled for a very wide range of CPU's). Lua has not many demands ... it can even run on tiny cpu's. It's all rather plain C code. (And in luametatex we have no c++ ... all is just C.) Finally, the computational complexity of my proof engine, will be comparable to MetaFun/MetaPost... which I suspect you would not consider implementing in pure Lua. Some things are faster in C. Hard to say ... I think that the parser / expansion machinery in mp is the bottleneck here (no fun to do that in lua). Redoing it in Lua also is asking for compatibility issues. (btw, extensions are done in lua anyway, as is the mp backend) So yes I do need to implement it in ANSI-C wrapped in Lua (so that it can be used from *inside* ConTeXt). I would have to see the 'kind of code involved' in order to comment on that. An option is to do most in lua and maybe some helpers for crititical code in C. 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Using ConTeXt-LMTX for modern Mathematically-Literate-Programming 1/2
On 12/2/2020 10:40 AM, Stephen Gaito wrote: Many thanks for your swift and helpful comments. After some *very crude* tests using the `luametatex` and `luametafun` documents, I find that while I *can* stop effective processing at various points in the LuaMetaTeX pipeline, the time difference overall is not really significant enough to bother with this approach. The principle problem is, as you suggested below, "stopping" the pipeline at the PDF stage (using for example the `pre_output_filter`) corrupted the `*.tuc` data which is for my purposes, critical. Your comment was: but keep in mind that multipass data is flushed as part of the shipout (because it is often location and order bound) For the record, using the `append_to_vlist_filter` callback, I did manage to drastically reduce the "pages" (which were all blank, not surprisingly). However, on my elderly desktop from 2008, both callbacks essentially cut only 6-8 seconds out of 18 seconds, for the `luametatex` document, and 190 seconds, for the `luametafun` document. hm, on my 2013 laptop the luametatex manual needs 10 sec (i have all the fonts, so that includes a bunch) and a metafun manual should do about 20 a test on am M1 mini needs half those times as reported yesterday i bet that on a modern desktop the luatex manual will do < 5 sec In the case of the `luametafun` document, it is the MetaFun/MetaPost processing which, of course, is taking a long time (as it should, the graphics computations represent important but complex computations). One run or many due to xref? Maybe your machine has no significant cpu cache? Do you run from disk or ssd? How much memory? My ultimate goal is to parallelize the production of large, heavily cross-referenced, ConTeXt documents... more on this in a future email... 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Using ConTeXt-LMTX for modern Mathematically-Literate-Programming 2/2
Hans, Many thanks for your comments... see below. On Mon, 30 Nov 2020 19:31:55 +0100 Hans Hagen wrote: > On 11/30/2020 10:51 AM, Stephen Gaito wrote: > > Hello (again), > > > > This email is further to my previous "Using ConTeXt-LMTX for modern > > Mathematically-Literate-Programming 1/2" email... > > > > My ultimate goal in using ConTeXt-LMTX as a > > Mathematically-Literate-Programming tool, is to actually write a > > kernel "Mathematical Language" in ANSI-C (wrapped in Lua) which is > > then imported back into ConTeXt-LMTX as a standard Lua module (with > > an ANSI-C shared library). > > Just curious: do you think that using c instead of lua for that has > advantages? This is a very good and important question. One I have asked myself repeatedly. My ultimate goal is to write a small mathematical kernel in ANSI-C, which is, using [Frama-C](https://frama-c.com/), proven *correct*. To my knowledge, Lua has no similar tool for correctness proofs. Equally importantly, there are a very wide range of very different compilers which compile ANSI-C for an equally very wide range of CPU's. Again, to my knowledge, Lua v5.4 has only one implementation (though this implementation *can* be compiled for a very wide range of CPU's). The problem here is that Mathematicians are inherently very conservative about the concept of "proof" (it has taken well over 2,000 hard years to develop our current understanding). My kernel will be an extensible "proof" engine. For mathematicians to trust it, this proof engine must itself be proven correct (or as correct as currently possible). It must also be simple enough to *see* that it is correct (hence the Literate-Programming approach), *and* (since I can not even hope to prove the compilers are *correct*), there must be many *different* compiler implementations (to show that the results are not artefacts of one particular implementation). Finally, the computational complexity of my proof engine, will be comparable to MetaFun/MetaPost... which I suspect you would not consider implementing in pure Lua. Some things are faster in C. So yes I do need to implement it in ANSI-C wrapped in Lua (so that it can be used from *inside* ConTeXt). Since this is a mathematical tool, "embedding" it in ConTeXt is ideal. As a mathematician writes, what they write gets proof-checked automatically... in the document they are writing, and by the typesetting tool they are using for the finished PDF. :-) ConTeXt (via LuaMetaTex) makes this possible in a way native TeX/LaTeX never could. So once again, many many thanks for the vision to create such a flexible tool! > > > This would allow the output of "code" in my "Mathematical Language" > > to be directly embedded/typeset in the output of my Mathematical > > document. > > > > (The ultimate goal is to ensure that there is NO wishful thinking > > that the code is "correct" ("just trust me")... all results would be > > directly visible in the PDF). > > > > Alas, while, for other reasons, trying to use the Lua-CJSON Lua > > module from within ConTeXt-LMTX (which also makes use of a shared > > library written in C), I find that the current ConTeXt-LMTX is > > missing (among potentially others) the `lua_checkstack` symbol: > > could be .. we dont' use it > > >> ...Xt/tex/texmf-context/tex/context/base/mkiv/l-package.lua:333: > >> error loading module 'cjson' from file > >> '/usr/local/lib/lua/5.4/cjson.so': > >> /usr/local/lib/lua/5.4/cjson.so: undefined symbol: lua_checkstack > > > > even when using the ConTeXt/LuaMetaTeX `--permiteloadlib` switch. > > > > (Note that this Lua-CJSON module does work with the native 5.4 Lua). > > why not use the build in helpers The test, which triggered the error message (above), was to prove that I could send [NATS](https://nats.io/) messages from *inside* ConTeXt. "Out of the box", the [Lua-NATS](https://github.com/DawnAngel/lua-nats) requires: - luasocket (which LuaMetaTex provides, many many thanks!) - lua-cjson (which is an external shared library and is what I was testing) Fortunately, I found a couple of pure Lua JSON tools which I could get Lua-NATS to use with a one line change. (And, for the record, I *can* send and receive messages from a NATS server from inside ConTeXt :-) If I find I need to make changes to the Lua-NATS code, I will probably use LuaMetaTeX's internal JSON implementation as you suggest below (again many thanks for embedding a JSON implementation). Using Lua-NATS is part of my larger goal to parallelize the typesetting of large documents using ConTeXt (more on this in another email). > > \usemodule[json] > > \starttext > >
Re: [NTG-context] Using ConTeXt-LMTX for modern Mathematically-Literate-Programming 1/2
Hans, Many thanks for your swift and helpful comments. After some *very crude* tests using the `luametatex` and `luametafun` documents, I find that while I *can* stop effective processing at various points in the LuaMetaTeX pipeline, the time difference overall is not really significant enough to bother with this approach. The principle problem is, as you suggested below, "stopping" the pipeline at the PDF stage (using for example the `pre_output_filter`) corrupted the `*.tuc` data which is for my purposes, critical. Your comment was: > but keep in mind that multipass data is flushed as part of the > shipout (because it is often location and order bound) For the record, using the `append_to_vlist_filter` callback, I did manage to drastically reduce the "pages" (which were all blank, not surprisingly). However, on my elderly desktop from 2008, both callbacks essentially cut only 6-8 seconds out of 18 seconds, for the `luametatex` document, and 190 seconds, for the `luametafun` document. In the case of the `luametafun` document, it is the MetaFun/MetaPost processing which, of course, is taking a long time (as it should, the graphics computations represent important but complex computations). My ultimate goal is to parallelize the production of large, heavily cross-referenced, ConTeXt documents... more on this in a future email... Again, many thanks for your comments! Regards, Stephen Gaito On Mon, 30 Nov 2020 19:59:07 +0100 Hans Hagen wrote: > On 11/30/2020 10:51 AM, Stephen Gaito wrote: > > Hello, > > > > I am slowly working on a Mathematical problem requiring underlying > > computation. > > > > As Mathematicians (myself included) are rather "conservative", I > > need to discuss each "chunk" of code with the full set of > > Mathematical notation. > > > > A couple of years ago I started using ConTeXt-MKIV as a > > Mathematically-Literate-Programming tool by using its excellent Lua > > interface to capture the code and dump it to disk for external > > compilation. > > > > I am now revisiting my original design and want to redo my tools > > using ConTeXt-LMTX. > > > > I would *like* to be able to "stop" the ConTeXt typesetting at > > various points for differing purposes: > > > > 1. After all macro expansions (and hence after *my* calls into Lua) > > but before line/paragraph/page layout begins. > > maybe something > > \startmystuff > > \stopmystuff > > and then you can hook something into startmystuff and \stopmystuff > > > 2. After line/paragraph/page layout but before PDF generation. > > pdf is generated per page, if needed one can kick in a shipout > overload > > but keep in mind that multipass data is flushed as part of the > shipout (because it is often location and order bound) > > > 3. After all PDF generated (ie. a "normal" "full" ConTeXt run). > > > > Stopping after all macro expansions would allow my code generation > > builds to proceed without the un-needed page setting or PDF > > generation. > > hm, the problem is always in the 'state' of all kind of variables > > > Stopping after the line/paragraph/page layout would allow multiple > > "faster(?)" ConTeXt runs while the "*.tuc" file converges to a > > complete set of page numbers and cross references (etc). Then, once > > the "*.tuc" file has converged, a full ConTeXt run with PDF output > > could be done. > > not sure what you mean here ... what is fast? or: how slow is it now? > what is the bottleneck? can you cache data that didn't change? > > a large document is normally split up in sections that can be > processed independent > > \starttext > \dorecurse{1}{\samplefile{ward}\par} > \stoptext > > runs on my 2013 laptop at over 65 pages per second > > quite often performance is hit by inefficient styling and such .. > it's no problem to bring a tex system a grinding halt > > > I am very aware that *internally* ConTeXt is probably structured as > > a tight pipeline with each of the "traditional" TeX stages "Mouth", > > "Stomach", "page setting", PDF generation tightly "chained"... > > This means that there is no "one" place in the code where all macro > > expansions have completed but before the page setting "starts", or > > similarly, after the page setting has finished but before the PDF > > generation "starts". > > yes and often something is left over for a next page so it's kind of > fluid > > > > > QUESTION: Is it possible to u
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
Thanks Taco! I understand much better now. I think it's best to leave the units out until the drawing stage as you suggest. Thanks again Keith McKay On Fri, 27 Nov 2020, 08:30 Taco Hoekwater, wrote: > > > > On 26 Nov 2020, at 16:09, Keith McKay wrote: > > > > Hi, > > > > I have been using xpart and ypart to extract these values from pairs of > points in a path but I wasn't getting the correct result. I was expecting: > > > > pair (2cm, 11cm) to give xpart 2 and ypart 11 > > As explained by various people, Metapost does not have dimensions. All > lengths are implicit Postscript big points > (72/inch). Variables like “cm” just add a multiplication factor to your > expressions, at no point is a dimension stored inside Metapost. > > Your equation: > > a0 = (2cm,11cm) > > first expands into > > a0 = (2*28.34645,11*28.34645) > > because “cm” is a variable with a value (Its definition in plain.mp is > "cm = 28.34645”) > > Then, the two expressions in the a0 equation are resolved before the > assignment, so what you actually wrote at the statement level is > > a0 = (56.6929, 311.8096); > > At no point is there a “cm”-sized dimension. > > === > > Perhaps another option would be for you to do all your work without units, > e.g. > > a0 = (2,11) % assume scaling will happen later > > and then in the end do the drawing on a scaled path: > > draw (pp scaled cm) … > > as that may be less confusing? If the precision is an issue, you could > counter the loss of precision you could use implied millimeters instead of > centimeters. > > Best wishes, > Taco > > > > > > > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > > ___ > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
> On 26 Nov 2020, at 16:09, Keith McKay wrote: > > Hi, > > I have been using xpart and ypart to extract these values from pairs of > points in a path but I wasn't getting the correct result. I was expecting: > > pair (2cm, 11cm) to give xpart 2 and ypart 11 As explained by various people, Metapost does not have dimensions. All lengths are implicit Postscript big points (72/inch). Variables like “cm” just add a multiplication factor to your expressions, at no point is a dimension stored inside Metapost. Your equation: a0 = (2cm,11cm) first expands into a0 = (2*28.34645,11*28.34645) because “cm” is a variable with a value (Its definition in plain.mp is "cm = 28.34645”) Then, the two expressions in the a0 equation are resolved before the assignment, so what you actually wrote at the statement level is a0 = (56.6929, 311.8096); At no point is there a “cm”-sized dimension. === Perhaps another option would be for you to do all your work without units, e.g. a0 = (2,11) % assume scaling will happen later and then in the end do the drawing on a scaled path: draw (pp scaled cm) … as that may be less confusing? If the precision is an issue, you could counter the loss of precision you could use implied millimeters instead of centimeters. Best wishes, Taco ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
/First « //uniformdeviate(1) - 0.5// » could be modified to « //uniformdeviate(0.5)//»./ / / /To add noise, you can use the randomized function of Metafun. For exemple, you can write:/ / / /draw pp randomized 1cm ;/ / / That's true Fabrice but in this use case I wanted a random number between -0.5 and +0.5, and I wasn't sure I would get that with randomized. Thanks again Keith McKay/ / On 26/11/2020 17:20, Fabrice L wrote: Keith, Le 26 nov. 2020 à 12:12, Keith McKay <mailto:mckaymeis...@gmail.com>> a écrit : Thanks Fabrice and Hans. I now see I can simplify some lines of the code: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:= a[i]; and pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now becomes pp := pp --- a[i +1] ; However I still have the problem in the calculation of xcoord and ycoord which are used in the creation of path pp: for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; I'm adding a small random amount to the x and ypart of the pair a[i] to produce a path that is like a squiggle (gribouiller in French, according to Google). I have to use cf to convert to the x and yparts to centimeters since they seem to loose the centimeter units on separation. I can't see anyway round this, or am I missing something? Thanks Keith McKay First « uniformdeviate(1) - 0.5 » could be modified to « uniformdeviate(0.5)». To add noise, you can use the randomized function of Metafun. For exemple, you can write: draw pp randomized 1cm ; Fabrice. On 26/11/2020 15:19, Fabrice L wrote: Hi keith, Le 26 nov. 2020 à 10:09, Keith McKay <mailto:mckaymeis...@gmail.com>> a écrit : Hi, I have been using xpart and ypart to extract these values from pairs of points in a path but I wasn't getting the correct result. I was expecting: pair (2cm, 11cm) to give xpart 2 and ypart 11 However I was getting: pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 After much head scratching and reading the MetaPost and MetaFun manuals, I realised that the units of xpart or ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart or ypart in cm I would have to use a correction factor. I had made the assumption that since the x and ypart in the pair was in cm that the result would be in cm, but I see now that this is not the case. Will I have to continue doing this or is there some magic within MetaFun which takes account of the units in a pair and outputs the result of x and ypart in the same units? The MWE belows shows what I have been doing. Thanks Keith McKay %%% MWE %%% \setuppapersize [A5, landscape][A4, portrait] \usecolors[crayola] \starttext \startMPpage StartPage; width := PaperWidth ; height := PaperHeight ; unit := cm ; numeric squig; pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) % cf := 72/2.54; %Converts points/in to points/cm% path pp; for i = 0 step 1 until 3: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; pp := pp --- cycle; if i < 3 : pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); fi; f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken colour % draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]); endfor; StopPage; \stopMPpage \stoptext %%%%%% MetaPost (MetaFun) is taking care of everything regarding units. As you ave discovered, everything is translated to a unique internal dimension. So you can write: a := (1cm,2in) ; with no problem. The « cm » and « in » parts of the expression will become numbers to translate this number on the right unit. Fabrice. ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist :ntg-context@ntg.nl <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage :http://www.pragma-ade.nl <http://www.pragma-ade.nl/>/http://context.aanhet.net <http://context.aanhet.net/> archive :https://bitbucket.org/phg/context-mirror/commits/ <https://bitbucket.org/phg/context-mirror/commits/> wiki :http://contextgarden.net <http://contextgarden.net/> ___ ___ If your qu
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
Thanks again Hans and Fabrice, for the time you have both taken with my question and thanks for the code snippet Hans. Just one last confirmation from the snippet. Hans uses the correction factor cf on the x and yparts of a[i]. I taking this as meaning that this has to be done because the x and yparts of a[i] are returned as postscript points units and not as centimeters as in the pair. I maybe didn't make this clear in my original query. Thanks for your patience. Keith McKay On 26/11/2020 17:25, Hans Hagen wrote: On 11/26/2020 6:12 PM, Keith McKay wrote: Thanks Fabrice and Hans. I now see I can simplify some lines of the code: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:= a[i]; and pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now becomes pp := pp --- a[i +1] ; However I still have the problem in the calculation of xcoord and ycoord which are used in the creation of path pp: for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; I'm adding a small random amount to the x and ypart of the pair a[i] to produce a path that is like a squiggle (gribouiller in French, according to Google). I have to use cf to convert to the x and yparts to centimeters since they seem to loose the centimeter units on separation. I can't see anyway round this, or am I missing something? for squig = 1 step 1 until 15: xcoord := (xpart a[i]/cf); ycoord := (ypart a[i]/cf); xcoord := xcoord randomized (xcoord/50); ycoord := ycoord randomized (ycoord/50); pp := pp .. { curl 100 } (xcoord*cm, ycoord*cm); endfor; Thanks Keith McKay On 26/11/2020 15:19, Fabrice L wrote: Hi keith, Le 26 nov. 2020 à 10:09, Keith McKay <mailto:mckaymeis...@gmail.com>> a écrit : Hi, I have been using xpart and ypart to extract these values from pairs of points in a path but I wasn't getting the correct result. I was expecting: pair (2cm, 11cm) to give xpart 2 and ypart 11 However I was getting: pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 After much head scratching and reading the MetaPost and MetaFun manuals, I realised that the units of xpart or ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart or ypart in cm I would have to use a correction factor. I had made the assumption that since the x and ypart in the pair was in cm that the result would be in cm, but I see now that this is not the case. Will I have to continue doing this or is there some magic within MetaFun which takes account of the units in a pair and outputs the result of x and ypart in the same units? The MWE belows shows what I have been doing. Thanks Keith McKay %%% MWE %%% \setuppapersize [A5, landscape][A4, portrait] \usecolors[crayola] \starttext \startMPpage StartPage; width := PaperWidth ; height := PaperHeight ; unit := cm ; numeric squig; pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) % cf := 72/2.54; %Converts points/in to points/cm% path pp; for i = 0 step 1 until 3: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; pp := pp --- cycle; if i < 3 : pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); fi; f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken colour % draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]); endfor; StopPage; \stopMPpage \stoptext %% MetaPost (MetaFun) is taking care of everything regarding units. As you ave discovered, everything is translated to a unique internal dimension. So you can write: a := (1cm,2in) ; with no problem. The « cm » and « in » parts of the expression will become numbers to translate this number on the right unit. Fabrice. ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist :ntg-context@ntg.nl <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage :http://www.pragma-ade.nl <http://www.pragma-ade.nl/>/http://context.aanhet.net <http://context.aanhet.net/> archive :https://bitbucket.org/phg/context-mirror/commits/ <https://bitbucket.org/phg/context-mirror/commits/> wiki :http:
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
Keith, > Le 26 nov. 2020 à 12:12, Keith McKay a écrit : > Thanks Fabrice and Hans. > > I now see I can simplify some lines of the code: > > pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:= a[i]; > > and > > pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now becomes pp := > pp --- a[i +1] ; > > However I still have the problem in the calculation of xcoord and ycoord > which are used in the creation of path pp: > > for squig = 1 step 1 until 15: > > xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); > > ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); > > pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); > > endfor; > > I'm adding a small random amount to the x and ypart of the pair a[i] to > produce a path that is like a squiggle (gribouiller in French, according to > Google). I have to use cf to convert to the x and yparts to centimeters since > they seem to loose the centimeter units on separation. I can't see anyway > round this, or am I missing something? > > Thanks > Keith McKay First « uniformdeviate(1) - 0.5 » could be modified to « uniformdeviate(0.5)». To add noise, you can use the randomized function of Metafun. For exemple, you can write: draw pp randomized 1cm ; Fabrice. > > On 26/11/2020 15:19, Fabrice L wrote: >> Hi keith, >> >>> Le 26 nov. 2020 à 10:09, Keith McKay >> <mailto:mckaymeis...@gmail.com>> a écrit : >>> >>> Hi, >>> >>> I have been using xpart and ypart to extract these values from pairs of >>> points in a path but I wasn't getting the correct result. I was expecting: >>> >>> pair (2cm, 11cm) to give xpart 2 and ypart 11 >>> >>> However I was getting: >>> >>> pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 >>> >>> After much head scratching and reading the MetaPost and MetaFun manuals, I >>> realised that the units of xpart or ypart are in Postcript points or Big >>> Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of >>> xpart or ypart in cm I would have to use a correction factor. I had made >>> the assumption that since the x and ypart in the pair was in cm that the >>> result would be in cm, but I see now that this is not the case. Will I have >>> to continue doing this or is there some magic within MetaFun which takes >>> account of the units in a pair and outputs the result of x and ypart in the >>> same units? >>> >>> The MWE belows shows what I have been doing. >>> >>> Thanks >>> >>> Keith McKay >>> >>> %%% MWE %%% >>> \setuppapersize [A5, landscape][A4, portrait] >>> \usecolors[crayola] >>> \starttext >>> \startMPpage >>> StartPage; >>> width := PaperWidth ; height := PaperHeight ; unit := cm ; >>> numeric squig; >>> pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = >>> (8cm,8cm); >>> show xpart a[0], ypart a[0]; %Example of result from x and ypart before >>> applying correction factor (cf) % >>> cf := 72/2.54; %Converts points/in to points/cm% >>> path pp; >>> for i = 0 step 1 until 3: >>> pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); >>> for squig = 1 step 1 until 15: >>> xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); >>> ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); >>> pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); >>> endfor; >>> pp := pp --- cycle; >>> if i < 3 : >>> pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); >>> fi; >>> f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken >>> colour % >>> draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 >>> withcolor (f[white,\MPcolor{BurntSienna}]); >>> endfor; >>> StopPage; >>> \stopMPpage >>> \stoptext >>> %% >>> >> >> MetaPost (MetaFun) is taking care of everything regarding units. As you ave >> discovered, everything is translated to a unique internal dimension. So you >> can write: >> >> a := (1cm,2in) ; >> >> with no problem. The « cm » and « in » parts of the exp
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
On 11/26/2020 6:12 PM, Keith McKay wrote: Thanks Fabrice and Hans. I now see I can simplify some lines of the code: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:= a[i]; and pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now becomes pp := pp --- a[i +1] ; However I still have the problem in the calculation of xcoord and ycoord which are used in the creation of path pp: for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; I'm adding a small random amount to the x and ypart of the pair a[i] to produce a path that is like a squiggle (gribouiller in French, according to Google). I have to use cf to convert to the x and yparts to centimeters since they seem to loose the centimeter units on separation. I can't see anyway round this, or am I missing something? for squig = 1 step 1 until 15: xcoord := (xpart a[i]/cf); ycoord := (ypart a[i]/cf); xcoord := xcoord randomized (xcoord/50); ycoord := ycoord randomized (ycoord/50); pp := pp .. { curl 100 } (xcoord*cm, ycoord*cm); endfor; Thanks Keith McKay On 26/11/2020 15:19, Fabrice L wrote: Hi keith, Le 26 nov. 2020 à 10:09, Keith McKay <mailto:mckaymeis...@gmail.com>> a écrit : Hi, I have been using xpart and ypart to extract these values from pairs of points in a path but I wasn't getting the correct result. I was expecting: pair (2cm, 11cm) to give xpart 2 and ypart 11 However I was getting: pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 After much head scratching and reading the MetaPost and MetaFun manuals, I realised that the units of xpart or ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart or ypart in cm I would have to use a correction factor. I had made the assumption that since the x and ypart in the pair was in cm that the result would be in cm, but I see now that this is not the case. Will I have to continue doing this or is there some magic within MetaFun which takes account of the units in a pair and outputs the result of x and ypart in the same units? The MWE belows shows what I have been doing. Thanks Keith McKay %%% MWE %%% \setuppapersize [A5, landscape][A4, portrait] \usecolors[crayola] \starttext \startMPpage StartPage; width := PaperWidth ; height := PaperHeight ; unit := cm ; numeric squig; pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) % cf := 72/2.54; %Converts points/in to points/cm% path pp; for i = 0 step 1 until 3: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; pp := pp --- cycle; if i < 3 : pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); fi; f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken colour % draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]); endfor; StopPage; \stopMPpage \stoptext %% MetaPost (MetaFun) is taking care of everything regarding units. As you ave discovered, everything is translated to a unique internal dimension. So you can write: a := (1cm,2in) ; with no problem. The « cm » and « in » parts of the expression will become numbers to translate this number on the right unit. Fabrice. ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist :ntg-context@ntg.nl <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage :http://www.pragma-ade.nl <http://www.pragma-ade.nl/>/http://context.aanhet.net <http://context.aanhet.net/> archive :https://bitbucket.org/phg/context-mirror/commits/ <https://bitbucket.org/phg/context-mirror/commits/> wiki :http://contextgarden.net <http://contextgarden.net/> ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
Thanks Fabrice and Hans. I now see I can simplify some lines of the code: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); now becomes pp:= a[i]; and pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); now becomes pp := pp --- a[i +1] ; However I still have the problem in the calculation of xcoord and ycoord which are used in the creation of path pp: for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; I'm adding a small random amount to the x and ypart of the pair a[i] to produce a path that is like a squiggle (gribouiller in French, according to Google). I have to use cf to convert to the x and yparts to centimeters since they seem to loose the centimeter units on separation. I can't see anyway round this, or am I missing something? Thanks Keith McKay On 26/11/2020 15:19, Fabrice L wrote: Hi keith, Le 26 nov. 2020 à 10:09, Keith McKay <mailto:mckaymeis...@gmail.com>> a écrit : Hi, I have been using xpart and ypart to extract these values from pairs of points in a path but I wasn't getting the correct result. I was expecting: pair (2cm, 11cm) to give xpart 2 and ypart 11 However I was getting: pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 After much head scratching and reading the MetaPost and MetaFun manuals, I realised that the units of xpart or ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart or ypart in cm I would have to use a correction factor. I had made the assumption that since the x and ypart in the pair was in cm that the result would be in cm, but I see now that this is not the case. Will I have to continue doing this or is there some magic within MetaFun which takes account of the units in a pair and outputs the result of x and ypart in the same units? The MWE belows shows what I have been doing. Thanks Keith McKay %%% MWE %%% \setuppapersize [A5, landscape][A4, portrait] \usecolors[crayola] \starttext \startMPpage StartPage; width := PaperWidth ; height := PaperHeight ; unit := cm ; numeric squig; pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) % cf := 72/2.54; %Converts points/in to points/cm% path pp; for i = 0 step 1 until 3: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; pp := pp --- cycle; if i < 3 : pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); fi; f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken colour % draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]); endfor; StopPage; \stopMPpage \stoptext %% MetaPost (MetaFun) is taking care of everything regarding units. As you ave discovered, everything is translated to a unique internal dimension. So you can write: a := (1cm,2in) ; with no problem. The « cm » and « in » parts of the expression will become numbers to translate this number on the right unit. Fabrice. ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist :ntg-context@ntg.nl <mailto:ntg-context@ntg.nl>/http://www.ntg.nl/mailman/listinfo/ntg-context <http://www.ntg.nl/mailman/listinfo/ntg-context> webpage :http://www.pragma-ade.nl <http://www.pragma-ade.nl/>/http://context.aanhet.net <http://context.aanhet.net/> archive :https://bitbucket.org/phg/context-mirror/commits/ <https://bitbucket.org/phg/context-mirror/commits/> wiki :http://contextgarden.net <http://contextgarden.net/> ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
On 11/26/2020 4:09 PM, Keith McKay wrote: Hi, I have been using xpart and ypart to extract these values from pairs of points in a path but I wasn't getting the correct result. I was expecting: pair (2cm, 11cm) to give xpart 2 and ypart 11 However I was getting: pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 After much head scratching and reading the MetaPost and MetaFun manuals, I realised that the units of xpart or ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart or ypart in cm I would have to use a correction factor. I had made the assumption that since the x and ypart in the pair was in cm that the result would be in cm, but I see now that this is not the case. Will I have to continue doing this or is there some magic within MetaFun which takes account of the units in a pair and outputs the result of x and ypart in the same units? The MWE belows shows what I have been doing. cm is not really a unit but a multiplier cf := 72/2.54; %Converts points/in to points/cm% message(cm); message(cf); Thanks Keith McKay %%% MWE %%% \setuppapersize [A5, landscape][A4, portrait] \usecolors[crayola] \starttext \startMPpage StartPage; width := PaperWidth ; height := PaperHeight ; unit := cm ; numeric squig; pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) % cf := 72/2.54; %Converts points/in to points/cm% path pp; for i = 0 step 1 until 3: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; pp := pp --- cycle; if i < 3 : pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); fi; f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken colour % draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]); endfor; StopPage; \stopMPpage \stoptext %% ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___ -- - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Units of xpart and ypart of a pair in MetaFun
Hi keith, > Le 26 nov. 2020 à 10:09, Keith McKay a écrit : > > Hi, > > I have been using xpart and ypart to extract these values from pairs of > points in a path but I wasn't getting the correct result. I was expecting: > > pair (2cm, 11cm) to give xpart 2 and ypart 11 > > However I was getting: > > pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 > > After much head scratching and reading the MetaPost and MetaFun manuals, I > realised that the units of xpart or ypart are in Postcript points or Big > Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart > or ypart in cm I would have to use a correction factor. I had made the > assumption that since the x and ypart in the pair was in cm that the result > would be in cm, but I see now that this is not the case. Will I have to > continue doing this or is there some magic within MetaFun which takes account > of the units in a pair and outputs the result of x and ypart in the same > units? > > The MWE belows shows what I have been doing. > > Thanks > > Keith McKay > > %%% MWE %%% > \setuppapersize [A5, landscape][A4, portrait] > \usecolors[crayola] > \starttext > \startMPpage > StartPage; > width := PaperWidth ; height := PaperHeight ; unit := cm ; > numeric squig; > pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); > show xpart a[0], ypart a[0]; %Example of result from x and ypart before > applying correction factor (cf) % > cf := 72/2.54; %Converts points/in to points/cm% > path pp; > for i = 0 step 1 until 3: > pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); > for squig = 1 step 1 until 15: > xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); > ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); > pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); > endfor; > pp := pp --- cycle; > if i < 3 : > pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); > fi; > f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken > colour % > draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 > withcolor (f[white,\MPcolor{BurntSienna}]); > endfor; > StopPage; > \stopMPpage > \stoptext > %% > MetaPost (MetaFun) is taking care of everything regarding units. As you ave discovered, everything is translated to a unique internal dimension. So you can write: a := (1cm,2in) ; with no problem. The « cm » and « in » parts of the expression will become numbers to translate this number on the right unit. Fabrice. > ___ > If your question is of interest to others as well, please add an entry to the > Wiki! > > maillist : ntg-context@ntg.nl <mailto:ntg-context@ntg.nl> / > http://www.ntg.nl/mailman/listinfo/ntg-context > <http://www.ntg.nl/mailman/listinfo/ntg-context> > webpage : http://www.pragma-ade.nl <http://www.pragma-ade.nl/> / > http://context.aanhet.net <http://context.aanhet.net/> > archive : https://bitbucket.org/phg/context-mirror/commits/ > <https://bitbucket.org/phg/context-mirror/commits/> > wiki : http://contextgarden.net <http://contextgarden.net/> > ___ > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Units of xpart and ypart of a pair in MetaFun
Hi, I have been using xpart and ypart to extract these values from pairs of points in a path but I wasn't getting the correct result. I was expecting: pair (2cm, 11cm) to give xpart 2 and ypart 11 However I was getting: pair (2cm, 11cm) -> xpart 56.6929 and ypart 311.8096 After much head scratching and reading the MetaPost and MetaFun manuals, I realised that the units of xpart or ypart are in Postcript points or Big Points (bp), and 1 bp is 1/72 of an inch, and thus to get the values of xpart or ypart in cm I would have to use a correction factor. I had made the assumption that since the x and ypart in the pair was in cm that the result would be in cm, but I see now that this is not the case. Will I have to continue doing this or is there some magic within MetaFun which takes account of the units in a pair and outputs the result of x and ypart in the same units? The MWE belows shows what I have been doing. Thanks Keith McKay %%% MWE %%% \setuppapersize [A5, landscape][A4, portrait] \usecolors[crayola] \starttext \startMPpage StartPage; width := PaperWidth ; height := PaperHeight ; unit := cm ; numeric squig; pair a[]; a0 = (2cm,11cm); a1 = (4cm,10cm); a2 = (6cm,9cm); a3 = (8cm,8cm); show xpart a[0], ypart a[0]; %Example of result from x and ypart before applying correction factor (cf) % cf := 72/2.54; %Converts points/in to points/cm% path pp; for i = 0 step 1 until 3: pp := ((xpart a[i])/cf*cm, (ypart a[i])/cf*cm); for squig = 1 step 1 until 15: xcoord := uniformdeviate(1) - 0.5 + (xpart a[i]/cf); ycoord := uniformdeviate(1) - 0.5+ (ypart a[i]/cf); pp := pp .. {curl 100}(xcoord*cm, ycoord*cm); endfor; pp := pp --- cycle; if i < 3 : pp := pp --- ((xpart a[i+1]/cf)*cm, (ypart a[i+1])/cf*cm); fi; f :=((1.4 - 0.6) * uniformdeviate(1)) + 0.8; % Factor to lighten/darken colour % draw pp withpen pencircle xscaled 0.5mm yscaled .1mm rotated 45 withcolor (f[white,\MPcolor{BurntSienna}]); endfor; StopPage; \stopMPpage \stoptext %% ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] new upload
On 11/25/2020 10:12 AM, Giulio Bertellini wrote: Great. Made a clean install from scratch and now metafun manual compiles great at first run: mkiv lua stats > used engine:*luametatex version: 2.0803, functionality level: 20201123*, format id: 547, compiler: gcc mkiv lua stats > tex properties: 740024 hash slots used of 2097152, approximate memory usage: 44 MB mkiv lua stats > lua properties: engine: lua 5.4, used memory: 140 MB, ctx: 123 MB, max: 123 MB, hash chars: min(64,40), symbol mask: utf (τεχ) mkiv lua stats > runtime: 20.182 seconds, 396 processed pages, 396 shipped pages, 19.621 pages/second Looks ok to me given the thousands of graphics. What are the specs of the machine? 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 - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] new upload
Great. Made a clean install from scratch and now metafun manual compiles great at first run: mkiv lua stats > used engine:* luametatex version: 2.0803, functionality level: 20201123*, format id: 547, compiler: gcc mkiv lua stats > tex properties: 740024 hash slots used of 2097152, approximate memory usage: 44 MB mkiv lua stats > lua properties: engine: lua 5.4, used memory: 140 MB, ctx: 123 MB, max: 123 MB, hash chars: min(64,40), symbol mask: utf (τεχ) mkiv lua stats > runtime: 20.182 seconds, 396 processed pages, 396 shipped pages, 19.621 pages/second giulio b. On Tue, Nov 24, 2020 at 8:07 PM Hans Hagen wrote: > Hi, > > A new upload. Mojca upgraded the build manager and we also updated some > machines so all binaries (platforms) should be in sync now. (No binaries > for apples M1 and microsofts SQ2 as we don't have these machines, so > just good old intel and arm it is.) > > On my rusty laptop the luametatex manual takes between 10 and 10.5 sec > (depending on load). On the raspberry pi 64 bit it takes 32.5 sec > (ubuntu, ssd on usb 3). The Windows Linux Subsystem (version 1) takes > some 11.5 seconds and the domotica fitlet with a low power AMD A10 needs > 27.5 sec.) The ratios match measurements of a while ago. In the meantime > the format file got smaller, memory more dynamic and the mem footprint > also smaller. I expect a modern intel laptop cpu to need some 5 seconds > and a decent desktop less but who knows. It's not easy to squeeze out > more (the bottleneck is in the lua code as the (con)tex(t) code is > pretty efficient so we pay a price for flexibility). > > (In the process I saw that I bugged the xetex logo but that has to wait > for a next upload. Hardly critital I suspect.) > > 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 > - > > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > > ___ > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Current LMTX unable to compile file metafun-positioning.tex - error on line 240
Dear All Unable to compile metafun manual with current release of LMTX for linux X86_64 and RPI 4 (both Raspberry PI OS 32 bit and Manjaro Linux ARM 64). engine: luametatex version: 2.0802, functionality level: 20201118 tex error > tex error on line 240 in file metafun-positioning.tex: Missing number, treated as zero. This problem never occurred in earlier compilations with LMTX. Commenting out file metafun-positioning.tex metafun manual compiles successfully. Same problem is exhibited in different version of ubuntu and arch linux X86_64 , Thank you all for your feedback. Giulio B. 234 \startsection[title={A more detailed view}] 235 236 As we know, a decent portion of \TEX's attention is focused on breaking 237 paragraphs into lines and determining the optimal point to split off the page. 238 Trying to locate the optimal points to break lines is a dynamic process. The 239 space between words is flexible and we don't know in advance when a \hpos {A-1} 240 >> {word} or piece of a word |<|maybe it's best to talk of typographic \hpos {A-2} 241 {globs} instead|>| will end up on the page. It might even cross the page 242 boundary. 243 A number should have been here; I inserted '0'. (If you can't figure out why I needed to see a number, look up 'weird error' in the index to The TeXbook.) mtx-context | fatal error: return code: 256 > > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] reusableMPgraphic not working
> On 18 Nov 2020, at 13:28, Rik Kabel wrote: > > > On 11/18/2020 08:11, Bruce Horrocks wrote: >> Just working through the Metafun manual and have hit a problem. In the >> following MWE the green circle appears but the blue one doesn't. Surely >> reusable graphics must be so commonly used that it has to be me that's doing >> something wrong? >> >> (Context version is: 2020.11.05 23:01) >> >> \starttext >> \startuseMPgraphic{name1} >> fill fullcircle scaled 100pt withcolor green ; >> \stopuseMPgraphic >> Green circle: \useMPgraphic{name1} >> >> \startreusableMPgraphic{name2} >> fill fullcircle scaled 100pt withcolor blue ; >> \stopreusableMPgraphic >> Blue circle:\reuseMPgraphic{name2} >> \stoptext >> > > Works as expected here, producing both circles. I am using 2020.11.17 12:39, > both LMTX and MkIV. Thanks. A complete wipe and reinstall of TeX Live and ConTeXt has fixed it for me. No idea what was corrupted though. -- Bruce Horrocks Hampshire, UK ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] reusableMPgraphic not working
On 11/18/2020 08:11, Bruce Horrocks wrote: Just working through the Metafun manual and have hit a problem. In the following MWE the green circle appears but the blue one doesn't. Surely reusable graphics must be so commonly used that it has to be me that's doing something wrong? (Context version is: 2020.11.05 23:01) \starttext \startuseMPgraphic{name1} fill fullcircle scaled 100pt withcolor green ; \stopuseMPgraphic Green circle: \useMPgraphic{name1} \startreusableMPgraphic{name2} fill fullcircle scaled 100pt withcolor blue ; \stopreusableMPgraphic Blue circle:\reuseMPgraphic{name2} \stoptext Works as expected here, producing both circles. I am using 2020.11.17 12:39, both LMTX and MkIV. -- RIk ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] reusableMPgraphic not working
Just working through the Metafun manual and have hit a problem. In the following MWE the green circle appears but the blue one doesn't. Surely reusable graphics must be so commonly used that it has to be me that's doing something wrong? (Context version is: 2020.11.05 23:01) \starttext \startuseMPgraphic{name1} fill fullcircle scaled 100pt withcolor green ; \stopuseMPgraphic Green circle: \useMPgraphic{name1} \startreusableMPgraphic{name2} fill fullcircle scaled 100pt withcolor blue ; \stopreusableMPgraphic Blue circle:\reuseMPgraphic{name2} \stoptext -- Bruce Horrocks Hampshire, UK ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] embed metapost figure into document
Hi, Sylvain. LuaMetaTeX and LuaTeX, the engines used by ConTeXt nowadays, use an embedded library, so external compilations/files are not necessary. Just out of curiosity, wouldn't it be easier to use a ConTeXt environment? E.g.: \starttext \startMPcode %\startuseMPgraphic{} if you want to reuse your graphic with \useMPgraphic{} draw fullcircle scaled cm %withcolor black % black is default ; \stopMPcode %\stopuseMPgraphic \stoptext More info here: https://wiki.contextgarden.net/MetaFun_-_MetaPost_in_ConTeXt To actually answer your question, if you actually want to load a Metapost graphic externally generated, you should have something like: %nice.mp %"begin ... endfig", as well as "end" are important beginfig (1); draw fullcircle scaled cm %withcolor black ; endfig; end so when you compile it via mpost nice.mp (obviously supposing you have Metapost installed) you'll get a file called nice.1 and \starttext \externalfigure[nice.1][width=4cm] \stoptext will work. However, as you can see, ConTeXt deals with such minutiae for you and extends Metapost capabilities too, so the second alternative is not the ConTeXt way to go. I hope it helps. Jairo :) El lun., 9 de nov. de 2020 a la(s) 16:59, Sylvain Hubert ( champign...@gmail.com) escribió: > Dear List, > > I'm trying to embed a metapost image into the document. According the MetaFun > manual <http://www.pragma-ade.com/general/manuals/metafun-p.pdf>, > "embedding such a graphic is done by: > \externalfigure[graphic.123][width=4cm]", but the following example > produces an empty page: > > % test.mkxl > \starttext > \externalfigure[test.123][width=4cm] > \stoptext > > % test.123 > draw fullcircle scaled cm withcolor black; > > Does anyone know how to properly embed a metapost image into a context > document? > > Thanks! > > Best, > Sylvain > > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > > ___ > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] embed metapost figure into document
Dear List, I'm trying to embed a metapost image into the document. According the MetaFun manual <http://www.pragma-ade.com/general/manuals/metafun-p.pdf>, "embedding such a graphic is done by: \externalfigure[graphic.123][width=4cm]", but the following example produces an empty page: % test.mkxl \starttext \externalfigure[test.123][width=4cm] \stoptext % test.123 draw fullcircle scaled cm withcolor black; Does anyone know how to properly embed a metapost image into a context document? Thanks! Best, Sylvain ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] About filling paths, unfill, etc.
Oh, cool. I've found some info in the Metafun manual too. I should read more carefully next time. Thank you very much! Jairo :) El mar., 3 de nov. de 2020 a la(s) 07:29, Hans Hagen (j.ha...@xs4all.nl) escribió: > On 11/3/2020 12:59 PM, Jairo A. del Rio wrote: > > Hi everyone. I want to know if nowadays (2020) Metafun is able to do an > > actual unfill, like above: > > > > > https://tex.stackexchange.com/questions/151068/how-can-i-fill-a-complex-path-with-metapost-metafun/218718#218718 > > > > Example of what I want to do: > > > > \startMPpage > > > > path A, B, C; > > > > A := unitcircle shifted (-center unitcircle); > > > > A := A scaled 4cm; > > > > B := unitcircle shifted (-center unitcircle); > > > > B := B scaled 1cm; > > > > %C := (reverse B) shifted (left*1.4cm); > > > > %It works for two paths > > > > fill (reverse B)-- A -- cycle withcolor red; > > > > %fill A -- (reverse B) -- C -- cycle withcolor red; > > > > %When I try the same with three paths, a thin, unwanted line appears > > > > \stopMPpage > > > > I'm aware of unfill and I've read somewhere else about using pens > > instead, but I want to know if a better solution is possible. Thank you > > in advance. > \startMPpage > path A; A := (unitcircle shifted (-center unitcircle)) scaled 4cm; > path B; B := (unitcircle shifted (-center unitcircle)) scaled 1cm; > path C; C := B shifted (left*1.4cm); > > nofill A; nofill B; eofill C; > \stopMPpage > > to be wikified > > - >Hans Hagen | PRAGMA ADE >Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > - > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] About filling paths, unfill, etc.
On 11/3/2020 12:59 PM, Jairo A. del Rio wrote: Hi everyone. I want to know if nowadays (2020) Metafun is able to do an actual unfill, like above: https://tex.stackexchange.com/questions/151068/how-can-i-fill-a-complex-path-with-metapost-metafun/218718#218718 Example of what I want to do: \startMPpage path A, B, C; A := unitcircle shifted (-center unitcircle); A := A scaled 4cm; B := unitcircle shifted (-center unitcircle); B := B scaled 1cm; %C := (reverse B) shifted (left*1.4cm); %It works for two paths fill (reverse B)-- A -- cycle withcolor red; %fill A -- (reverse B) -- C -- cycle withcolor red; %When I try the same with three paths, a thin, unwanted line appears \stopMPpage I'm aware of unfill and I've read somewhere else about using pens instead, but I want to know if a better solution is possible. Thank you in advance. \startMPpage path A; A := (unitcircle shifted (-center unitcircle)) scaled 4cm; path B; B := (unitcircle shifted (-center unitcircle)) scaled 1cm; path C; C := B shifted (left*1.4cm); nofill A; nofill B; eofill C; \stopMPpage to be wikified - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] About filling paths, unfill, etc.
Hi everyone. I want to know if nowadays (2020) Metafun is able to do an actual unfill, like above: https://tex.stackexchange.com/questions/151068/how-can-i-fill-a-complex-path-with-metapost-metafun/218718#218718 Example of what I want to do: \startMPpage path A, B, C; A := unitcircle shifted (-center unitcircle); A := A scaled 4cm; B := unitcircle shifted (-center unitcircle); B := B scaled 1cm; %C := (reverse B) shifted (left*1.4cm); %It works for two paths fill (reverse B)-- A -- cycle withcolor red; %fill A -- (reverse B) -- C -- cycle withcolor red; %When I try the same with three paths, a thin, unwanted line appears \stopMPpage I'm aware of unfill and I've read somewhere else about using pens instead, but I want to know if a better solution is possible. Thank you in advance. Regards, Jairo :) ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Changing the colors of Charts in luametafun
On 18.10.20 22:59, Henning Hraban Ramm wrote: > Hi juh, > >> Am 16.10.2020 um 15:34 schrieb Jan U. Hasecke : >> >> as I'll need to make some business charts in the near future I had a >> look into metafun xl. > > you might like the new charts module by Tamara Kocurová & Adriana Kašparová. Yes! I like it! > Download: https://akela.mendelu.cz/~thala/statcharts/ > Manual/presentation also at > https://meeting.contextgarden.net/2020/talks/2020-09-11-tamara-and-adriana-statistical-charts/AK-TK_charts.pdf > Thanks a lot for this hint. What a wonderful module and excellently documented! Chapeau! juh ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Changing the colors of Charts in luametafun
Hi juh, > Am 16.10.2020 um 15:34 schrieb Jan U. Hasecke : > > as I'll need to make some business charts in the near future I had a > look into metafun xl. you might like the new charts module by Tamara Kocurová & Adriana Kašparová. Download: https://akela.mendelu.cz/~thala/statcharts/ Manual/presentation also at https://meeting.contextgarden.net/2020/talks/2020-09-11-tamara-and-adriana-statistical-charts/AK-TK_charts.pdf Hraban ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Changing the colors of Charts in luametafun
On 10/16/2020 3:34 PM, Jan U. Hasecke wrote: Hi, as I'll need to make some business charts in the near future I had a look into metafun xl. Here is the first example: \startMPcode draw lmt_chart_circle [ samples = { { 1, 4, 3, 2, 5, 7, 6 } }, percentage = true, trace = true, ] ; \stopMPcode How can I change the colors used for the sample? fillcolors = { "red", "green", "blue", "yellow", "magenta", "cyan", "gray" }, - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Changing the colors of Charts in luametafun
Hi, as I'll need to make some business charts in the near future I had a look into metafun xl. Here is the first example: \startMPcode draw lmt_chart_circle [ samples = { { 1, 4, 3, 2, 5, 7, 6 } }, percentage = true, trace = true, ] ; \stopMPcode How can I change the colors used for the sample? juh ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Combining modes and MetaFun
Thank you Hans, this is exactly what I need. I will wikify the examples. Kind regards,Jan Willem Flamma From: Hans HagenSent: Friday, 4 September 2020 15:09To: mailing list for ConTeXt users; Jan Willem FlammaSubject: Re: [NTG-context] Combining modes and MetaFun On 9/4/2020 2:20 PM, Jan Willem Flamma wrote:> Dear list members,> > Is it possible to combine modes and MetaFun?> > In the below MWE, the \doifmode construction does not work.> > Kind regards,> > Jan Willem Flamma> > ===> > \enablemode[en]> > %\enablemode[nl]> > \starttext> > \startbuffer[square]> > u := 2cm ;> > draw unitsquare scaled u ;> > drawdblarrow (0,-0.2u)..(u,-0.2u) ;> > drawdblarrow (1.2u, 0)..(1.2u, u) ;> > %\doifmode{en}{label(\sometxt{length}, (0.5u,-0.4u)) ;}> > %\doifmode{nl}{label(\sometxt{lengte}, (0.5u,-0.4u)) ;}> > %\doifmode{en}{label(\sometxt{width}, (1.6u, 0.5u)) ;}> > %\doifmode{nl}{label(\sometxt{breedte}, (1.6u, 0.5u)) ;}> > \stopbuffer> > \placefigure> > [here,none][]{}> > {\scale[width=0.5\textwidth]{\processMPbuffer[square]}}> > \stoptextYou need to compensate these solutions by "wikifying" them: \starttext \startuseMPgraphic{whatever}{s::mode} u := 2cm ; draw unitsquare scaled u ; drawdblarrow (0,-0.2u)..(u,-0.2u) ; drawdblarrow (1.2u, 0)..(1.2u, u) ; if "\MPvar{mode}" = "en" : label("e", (0.5u,-0.4u)) ; label("n", (1.6u, 0.5u)) ; else : label("n", (0.5u,-0.4u)) ; label("l", (1.6u, 0.5u)) ; fi ;\stopuseMPgraphic \useMPgraphic{whatever}{mode=en} \blank\useMPgraphic{whatever}{mode=nl} \blank \startuseMPgraphic{whatever} u := 2cm ; draw unitsquare scaled u ; drawdblarrow (0,-0.2u)..(u,-0.2u) ; drawdblarrow (1.2u, 0)..(1.2u, u) ; if texmode("en") : label("e", (0.5u,-0.4u)) ; label("n", (1.6u, 0.5u)) ; else : label("n", (0.5u,-0.4u)) ; label("l", (1.6u, 0.5u)) ; fi ;\stopuseMPgraphic { \enablemode[en] \useMPgraphic{whatever} } \blank{ \useMPgraphic{whatever} } \blank \stoptext - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl- ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Combining modes and MetaFun
On 9/4/2020 2:20 PM, Jan Willem Flamma wrote: Dear list members, Is it possible to combine modes and MetaFun? In the below MWE, the \doifmode construction does not work. Kind regards, Jan Willem Flamma === \enablemode[en] %\enablemode[nl] \starttext \startbuffer[square] u := 2cm ; draw unitsquare scaled u ; drawdblarrow (0,-0.2u)..(u,-0.2u) ; drawdblarrow (1.2u, 0)..(1.2u, u) ; %\doifmode{en}{label(\sometxt{length}, (0.5u,-0.4u)) ;} %\doifmode{nl}{label(\sometxt{lengte}, (0.5u,-0.4u)) ;} %\doifmode{en}{label(\sometxt{width}, (1.6u, 0.5u)) ;} %\doifmode{nl}{label(\sometxt{breedte}, (1.6u, 0.5u)) ;} \stopbuffer \placefigure [here,none][]{} {\scale[width=0.5\textwidth]{\processMPbuffer[square]}} \stoptext You need to compensate these solutions by "wikifying" them: \starttext \startuseMPgraphic{whatever}{s::mode} u := 2cm ; draw unitsquare scaled u ; drawdblarrow (0,-0.2u)..(u,-0.2u) ; drawdblarrow (1.2u, 0)..(1.2u, u) ; if "\MPvar{mode}" = "en" : label("e", (0.5u,-0.4u)) ; label("n", (1.6u, 0.5u)) ; else : label("n", (0.5u,-0.4u)) ; label("l", (1.6u, 0.5u)) ; fi ; \stopuseMPgraphic \useMPgraphic{whatever}{mode=en} \blank \useMPgraphic{whatever}{mode=nl} \blank \startuseMPgraphic{whatever} u := 2cm ; draw unitsquare scaled u ; drawdblarrow (0,-0.2u)..(u,-0.2u) ; drawdblarrow (1.2u, 0)..(1.2u, u) ; if texmode("en") : label("e", (0.5u,-0.4u)) ; label("n", (1.6u, 0.5u)) ; else : label("n", (0.5u,-0.4u)) ; label("l", (1.6u, 0.5u)) ; fi ; \stopuseMPgraphic { \enablemode[en] \useMPgraphic{whatever} } \blank { \useMPgraphic{whatever} } \blank \stoptext - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] Combining modes and MetaFun
Dear list members, Is it possible to combine modes and MetaFun? In the below MWE, the \doifmode construction does not work. Kind regards,Jan Willem Flamma ===\enablemode[en]%\enablemode[nl] \starttext \startbuffer[square] u := 2cm ; draw unitsquare scaled u ; drawdblarrow (0,-0.2u)..(u,-0.2u) ; drawdblarrow (1.2u, 0)..(1.2u, u) ; %\doifmode{en}{label(\sometxt{length}, (0.5u,-0.4u)) ;} %\doifmode{nl}{label(\sometxt{lengte}, (0.5u,-0.4u)) ;} %\doifmode{en}{label(\sometxt{width}, (1.6u, 0.5u)) ;} %\doifmode{nl}{label(\sometxt{breedte}, (1.6u, 0.5u)) ;}\stopbuffer \placefigure [here,none][]{} {\scale[width=0.5\textwidth]{\processMPbuffer[square]}} \stoptext ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] memoir-style chapter heading
Thank you Otared. The power of ConTeXt never ceases to amaze me, though despite the excellent work done on the wiki recently, it is the little things like the use of \raise that could be better described, especially in a range of applied instances. We find it, combined with hbox, in reference to marginal and centered headers, but it is not intuitive - for me at least - to be able to apply it as you have done in your example. The little process we have gone through, which is step-by-step, is most helpful, and I feel that I can now use these ideas in other instances and in slightly different ways. Thank you. How important is the 'lohi' addition you made to \framed? I removed it to see what would happen and did not notice any appreciable difference in the output. Julian On 18/8/20 11:19 pm, Otared Kavian wrote: Hi Julian, Actually one can tweak more or less the height at which the chapter number appears: below is an example in which one uses \raise and \hbox. \setuppagenumbering[state=start,location=footer] \setuphead[chapter] [ % numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] %\define[2]\MemoirChapter % {\startoverlay % {#1} % {#2} % \stopoverlay} \define[2]\MemoirChapter {\framed[frame=off,width=broad,align={middle,lohi}] {\startoverlay {\raise1.5ex\hbox{\switchtobodyfont[48pt]#1}} {#2} \stopoverlay} } \starttext \startchapter[title={This is a test},ownnumber=1234] \input knuth.tex \stopchapter \stoptext Best regards: Otared On 18 Aug 2020, at 11:47, jbf wrote: Thanks Otared - and whether using the earlier example (Aditya's with my minor 'centering' adjustment)) or yours, I agree - the number is just a bit too low, and of course, using this method we probably can't make adjustments to that. So ultimately it looks like I'll have to get my skills up to working with layers as well as overlays, where minute adjustments of the kind can be made. But wouldn't it be great if we could just do a bit of vertical adjustment in the overlay! Julian On 18/8/20 6:45 pm, Otared Kavian wrote: Hi Julian, Indeed you can modify slightly what Aditya said to obtain what you want: you can put the overlay into a framed environment as in the following example. Though, to my taste the number is a little bit too low… %% begin example \setuppagenumbering[state=start,location=footer] \setuphead[chapter] [ numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] \define[2]\MemoirChapter {\framed[frame=off,width=broad,align=middle] {\startoverlay {#1} {#2} \stopoverlay} } \starttext \startchapter[title={This is a test}] \input knuth.tex \stopchapter \stoptext %% end example Best regards: Otared On 18 Aug 2020, at 01:18, jbf wrote: I meant to include an example of what I mean, since at least it seems to work (am including just the definition part of your example), So at least I can get middle and right alignment. \define[2]\MemoirChapter {\midaligned{\startoverlay {#1} {#2} \stopoverlay}} Julian On 17/8/20 4:54 pm, Aditya Mahajan wrote: On Mon, 17 Aug 2020, jbf wrote: Am completely new to using Metafun, which I presume I would need to use to achieve a Hansen Memoir-style Chapter heading (chapter title overlayed on a large lightgray number). Of course, I am assuming I would need to use Metafun to create this... So my first question is to ask if I could achieve the same effect without Metafun? I have read through the Metafun manual, and I think I can understand how to overlay text on a graphic (MP), but it would be currently beyond me to draw numbers of the kind we find in, say, the Memoir examples. Has anyone created such an example? I was keenly looking for one in the manual and elsewhere, in terms of ConTeXt/Metafun commands, but could not find one. But I'd be quite prepared to 'have a go' at this, if I had some pointers of just where to start! I assume I would have to \defineoverlay[number] and then add text on top \framed (but without the frame borders). Am I at least correct about this? You don't need metafun for something this simple. Here is a crude implementation: \setuphead[chapter] [ numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] \define[2]\MemoirChapter% {\startoverlay {#1} {#2} \stopoverlay} \starttext \startchapter[title={This is a test}] \stopchapter \stoptext Overlays don't allow tuning the location...for that you need layers. See the chapter
Re: [NTG-context] memoir-style chapter heading
Hi Julian, Indeed you can modify slightly what Aditya said to obtain what you want: you can put the overlay into a framed environment as in the following example. Though, to my taste the number is a little bit too low… %% begin example \setuppagenumbering[state=start,location=footer] \setuphead[chapter] [ numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] \define[2]\MemoirChapter {\framed[frame=off,width=broad,align=middle] {\startoverlay {#1} {#2} \stopoverlay} } \starttext \startchapter[title={This is a test}] \input knuth.tex \stopchapter \stoptext %% end example Best regards: Otared > On 18 Aug 2020, at 01:18, jbf wrote: > > I meant to include an example of what I mean, since at least it seems to work > (am including just the definition part of your example), So at least I can > get middle and right alignment. > > \define[2]\MemoirChapter > {\midaligned{\startoverlay > {#1} > {#2} > \stopoverlay}} > > Julian > > On 17/8/20 4:54 pm, Aditya Mahajan wrote: >> On Mon, 17 Aug 2020, jbf wrote: >> >>> Am completely new to using Metafun, which I presume I would need to use >>> to achieve a Hansen Memoir-style Chapter heading (chapter title >>> overlayed on a large lightgray number). Of course, I am assuming I would >>> need to use Metafun to create this... >>> >>> So my first question is to ask if I could achieve the same effect >>> without Metafun? >>> >>> I have read through the Metafun manual, and I think I can understand how >>> to overlay text on a graphic (MP), but it would be currently beyond me >>> to draw numbers of the kind we find in, say, the Memoir examples. >>> >>> Has anyone created such an example? I was keenly looking for one in the >>> manual and elsewhere, in terms of ConTeXt/Metafun commands, but could >>> not find one. But I'd be quite prepared to 'have a go' at this, if I had >>> some pointers of just where to start! I assume I would have to >>> \defineoverlay[number] and then add text on top \framed (but without the >>> frame borders). Am I at least correct about this? >> You don't need metafun for something this simple. Here is a crude >> implementation: >> >> \setuphead[chapter] >> [ >> numberstyle={\switchtobodyfont[48pt]}, >> numbercolor=gray, >> alternative=command, >> command=\MemoirChapter, >> ] >> >> \define[2]\MemoirChapter% >> {\startoverlay >> {#1} >> {#2} >> \stopoverlay} >> >> \starttext >> \startchapter[title={This is a test}] >> \stopchapter >> >> \stoptext >> >> Overlays don't allow tuning the location...for that you need layers. See the >> chapter on ornaments in the details manual, which also explains an >> alternative method to set title of chapters (toward the end of that >> chapter), which is useful if you need absolute positioning. >> >> 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://context.aanhet.net >> archive : https://bitbucket.org/phg/context-mirror/commits/ >> wiki : http://contextgarden.net >> ___ > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] memoir-style chapter heading
I meant to include an example of what I mean, since at least it seems to work (am including just the definition part of your example), So at least I can get middle and right alignment. \define[2]\MemoirChapter {\midaligned{\startoverlay {#1} {#2} \stopoverlay}} Julian On 17/8/20 4:54 pm, Aditya Mahajan wrote: On Mon, 17 Aug 2020, jbf wrote: Am completely new to using Metafun, which I presume I would need to use to achieve a Hansen Memoir-style Chapter heading (chapter title overlayed on a large lightgray number). Of course, I am assuming I would need to use Metafun to create this... So my first question is to ask if I could achieve the same effect without Metafun? I have read through the Metafun manual, and I think I can understand how to overlay text on a graphic (MP), but it would be currently beyond me to draw numbers of the kind we find in, say, the Memoir examples. Has anyone created such an example? I was keenly looking for one in the manual and elsewhere, in terms of ConTeXt/Metafun commands, but could not find one. But I'd be quite prepared to 'have a go' at this, if I had some pointers of just where to start! I assume I would have to \defineoverlay[number] and then add text on top \framed (but without the frame borders). Am I at least correct about this? You don't need metafun for something this simple. Here is a crude implementation: \setuphead[chapter] [ numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] \define[2]\MemoirChapter% {\startoverlay {#1} {#2} \stopoverlay} \starttext \startchapter[title={This is a test}] \stopchapter \stoptext Overlays don't allow tuning the location...for that you need layers. See the chapter on ornaments in the details manual, which also explains an alternative method to set title of chapters (toward the end of that chapter), which is useful if you need absolute positioning. 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] memoir-style chapter heading
Thanks Aditya. The 'quick and simple' explanation below helps me to grasp some concepts I had not been clear about earlier. While you say that overlays 'don't allow tuning' for positioning, is this only in terms of absolute positioning? It would be so helpful if we could get at least a middle or right alignment with this simple approach. I have read the 'Details' approach you have indicated, though am still to get my head around it. Understanding overlays is one thing. Understanding layers yet another. Julian On 17/8/20 4:54 pm, Aditya Mahajan wrote: On Mon, 17 Aug 2020, jbf wrote: Am completely new to using Metafun, which I presume I would need to use to achieve a Hansen Memoir-style Chapter heading (chapter title overlayed on a large lightgray number). Of course, I am assuming I would need to use Metafun to create this... So my first question is to ask if I could achieve the same effect without Metafun? I have read through the Metafun manual, and I think I can understand how to overlay text on a graphic (MP), but it would be currently beyond me to draw numbers of the kind we find in, say, the Memoir examples. Has anyone created such an example? I was keenly looking for one in the manual and elsewhere, in terms of ConTeXt/Metafun commands, but could not find one. But I'd be quite prepared to 'have a go' at this, if I had some pointers of just where to start! I assume I would have to \defineoverlay[number] and then add text on top \framed (but without the frame borders). Am I at least correct about this? You don't need metafun for something this simple. Here is a crude implementation: \setuphead[chapter] [ numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] \define[2]\MemoirChapter% {\startoverlay {#1} {#2} \stopoverlay} \starttext \startchapter[title={This is a test}] \stopchapter \stoptext Overlays don't allow tuning the location...for that you need layers. See the chapter on ornaments in the details manual, which also explains an alternative method to set title of chapters (toward the end of that chapter), which is useful if you need absolute positioning. 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] memoir-style chapter heading
On Mon, 17 Aug 2020, jbf wrote: > Am completely new to using Metafun, which I presume I would need to use > to achieve a Hansen Memoir-style Chapter heading (chapter title > overlayed on a large lightgray number). Of course, I am assuming I would > need to use Metafun to create this... > > So my first question is to ask if I could achieve the same effect > without Metafun? > > I have read through the Metafun manual, and I think I can understand how > to overlay text on a graphic (MP), but it would be currently beyond me > to draw numbers of the kind we find in, say, the Memoir examples. > > Has anyone created such an example? I was keenly looking for one in the > manual and elsewhere, in terms of ConTeXt/Metafun commands, but could > not find one. But I'd be quite prepared to 'have a go' at this, if I had > some pointers of just where to start! I assume I would have to > \defineoverlay[number] and then add text on top \framed (but without the > frame borders). Am I at least correct about this? You don't need metafun for something this simple. Here is a crude implementation: \setuphead[chapter] [ numberstyle={\switchtobodyfont[48pt]}, numbercolor=gray, alternative=command, command=\MemoirChapter, ] \define[2]\MemoirChapter% {\startoverlay {#1} {#2} \stopoverlay} \starttext \startchapter[title={This is a test}] \stopchapter \stoptext Overlays don't allow tuning the location...for that you need layers. See the chapter on ornaments in the details manual, which also explains an alternative method to set title of chapters (toward the end of that chapter), which is useful if you need absolute positioning. 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] memoir-style chapter heading
Am completely new to using Metafun, which I presume I would need to use to achieve a Hansen Memoir-style Chapter heading (chapter title overlayed on a large lightgray number). Of course, I am assuming I would need to use Metafun to create this... So my first question is to ask if I could achieve the same effect without Metafun? I have read through the Metafun manual, and I think I can understand how to overlay text on a graphic (MP), but it would be currently beyond me to draw numbers of the kind we find in, say, the Memoir examples. Has anyone created such an example? I was keenly looking for one in the manual and elsewhere, in terms of ConTeXt/Metafun commands, but could not find one. But I'd be quite prepared to 'have a go' at this, if I had some pointers of just where to start! I assume I would have to \defineoverlay[number] and then add text on top \framed (but without the frame borders). Am I at least correct about this? Julian ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] A dumb question about MetaFun
I found another workaround, but I'm going to try this. Thank you, Keith, and thank you, Taco. Cordially, Jairo :) El dom., 16 de ago. de 2020 3:36 p. m., Taco Hoekwater escribió: > > > > On 16 Aug 2020, at 21:09, Keith McKay wrote: > > > > Jairo > > > > Try > > > > draw unitsquare scaled 1cm shifted (xcm, ycm); > > > > Page 11 of the manual metafun-p.pdf is your friend here. My recent > conversation with Taco on this list will be usefull as well. > > Also: > > \starttext > \startMPpage > % puts the center of the bbox of path p at the point t > primarydef p centered t = > hide(xshift := xpart t - (xpart urcorner p + xpart llcorner p)/2 ; > yshift := ypart t - (ypart urcorner p + ypart llcorner p)/2 ; ) > p shifted (xshift,yshift) > enddef; > > draw fullsquare scaled 2cm shifted (50,3) centered (100,100); > > % just for reference: > drawdot origin withpen pencircle scaled 10 withcolor red; > drawdot (100,100) withpen pencircle scaled 10 withcolor green; > \stopMPpage > \stoptext > > (I thought there was a metafun definition for that but I cannot find it). > > Best wishes, > Taco > > ___ > 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://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > > ___ > ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] A dumb question about MetaFun
> On 16 Aug 2020, at 21:09, Keith McKay wrote: > > Jairo > > Try > > draw unitsquare scaled 1cm shifted (xcm, ycm); > > Page 11 of the manual metafun-p.pdf is your friend here. My recent > conversation with Taco on this list will be usefull as well. Also: \starttext \startMPpage % puts the center of the bbox of path p at the point t primarydef p centered t = hide(xshift := xpart t - (xpart urcorner p + xpart llcorner p)/2 ; yshift := ypart t - (ypart urcorner p + ypart llcorner p)/2 ; ) p shifted (xshift,yshift) enddef; draw fullsquare scaled 2cm shifted (50,3) centered (100,100); % just for reference: drawdot origin withpen pencircle scaled 10 withcolor red; drawdot (100,100) withpen pencircle scaled 10 withcolor green; \stopMPpage \stoptext (I thought there was a metafun definition for that but I cannot find it). Best wishes, Taco ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] A dumb question about MetaFun
Jairo Try draw unitsquare scaled 1cm shifted (xcm, ycm); Page 11 of the manual metafun-p.pdf is your friend here. My recent conversation with Taco on this list will be usefull as well. Best Wishes Keith On 16/08/2020 18:06, Jairo A. del Rio wrote: Hi list! A simple question: is there an equivalent of thetextext for a normal picture (an "image(draw ... ;)")? I want to move the center of a picture to an specific point, like this: \startMPpage draw thetextext("\tttf hello", origin) ; draw unitsquare scaled 1cm; \stopMPpage The "hello" is centered at the origin. I want to achieve the same result for pictures. I've seen such a command some time ago, but I've forgotten and I cannot find it again in documentation. Thanks and sorry for any inconvenience. Regards, Jairo :) ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___ ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] A dumb question about MetaFun
Hi list! A simple question: is there an equivalent of thetextext for a normal picture (an "image(draw ... ;)")? I want to move the center of a picture to an specific point, like this: \startMPpage draw thetextext("\tttf hello", origin) ; draw unitsquare scaled 1cm; \stopMPpage The "hello" is centered at the origin. I want to achieve the same result for pictures. I've seen such a command some time ago, but I've forgotten and I cannot find it again in documentation. Thanks and sorry for any inconvenience. Regards, Jairo :) ___ 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://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___