* metafun & \sometxt: should black be "black" or "textcolor"? @ 2006-08-06 2:32 Mojca Miklavec 2006-08-06 8:52 ` Taco Hoekwater 0 siblings, 1 reply; 11+ messages in thread From: Mojca Miklavec @ 2006-08-06 2:32 UTC (permalink / raw) Hello, Does anyone have any idea about what's going on here? I get blue text, but a black square, although both are supposed to come out black (I wouldn't mind so much, but the problem is that some text is blue and some is black - I have some other testcases where this happens, but I have to create a minimal example first). \setupcolors [state=start,textcolor=blue] \starttext \startMPcode draw \sometxt{abc} withcolor black; % come out blue draw \sometxt{def} shifted (3cm,0) withcolor red; draw unitsquare xyscaled (3cm,2cm) withcolor black; \stopMPcode \stoptext Thanks, Mojca ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 2:32 metafun & \sometxt: should black be "black" or "textcolor"? Mojca Miklavec @ 2006-08-06 8:52 ` Taco Hoekwater 2006-08-06 11:26 ` Mojca Miklavec 0 siblings, 1 reply; 11+ messages in thread From: Taco Hoekwater @ 2006-08-06 8:52 UTC (permalink / raw) Mojca Miklavec wrote: > Hello, > > Does anyone have any idea about what's going on here? I get blue text, > but a black square, although both are supposed to come out black (I > wouldn't mind so much, but the problem is that some text is blue and > some is black - I have some other testcases where this happens, but I > have to create a minimal example first). use \textext. \sometxt will use the text color, because it never reaches metapost (I assume it would be possible to intercept drawing options like withcolor, but that doesn't happen at the moment). Cheers, taco ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 8:52 ` Taco Hoekwater @ 2006-08-06 11:26 ` Mojca Miklavec 2006-08-06 14:37 ` Taco Hoekwater 0 siblings, 1 reply; 11+ messages in thread From: Mojca Miklavec @ 2006-08-06 11:26 UTC (permalink / raw) On 8/6/06, Taco Hoekwater wrote: > Mojca Miklavec wrote: > > Hello, > > > > Does anyone have any idea about what's going on here? I get blue text, > > but a black square, although both are supposed to come out black (I > > wouldn't mind so much, but the problem is that some text is blue and > > some is black - I have some other testcases where this happens, but I > > have to create a minimal example first). > > use \textext. \sometxt will use the text color, because it never > reaches metapost (I assume it would be possible to intercept > drawing options like withcolor, but that doesn't happen at the > moment). But the other \sometxt was indeed red - withcolor seems to work, but only conditionally. And I have some weird examples of two texts one after another. In some cases (if something else is drawn inbetween and a color changed twice), then the second text will be black. But it's quite unpredictable (that one might even be bug in my code, so I don't want to complain before I have an example). I while ago I also posted an interesting example with colored table (withcolor colored only some of the cells), but that is alredy a very complex example. And I can't afford to use \textext. It's was too slow (approximately factor 10) and it runs out of TeX memmory after 10 or 12 plots on average. Thanks, Mojca A question for you or Hans: can please someone explain me in a few words what's the main strategy/philosophy behind \sometxt. I don't understand exactly how TeX processes it (and metapost shrinks/expands/shifts/colors) it inline. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 11:26 ` Mojca Miklavec @ 2006-08-06 14:37 ` Taco Hoekwater 2006-08-06 17:02 ` Mojca Miklavec ` (2 more replies) 0 siblings, 3 replies; 11+ messages in thread From: Taco Hoekwater @ 2006-08-06 14:37 UTC (permalink / raw) Hi Mojca, Mojca Miklavec wrote: > > But the other \sometxt was indeed red - withcolor seems to work, but > only conditionally. And I have some weird examples of two texts one > after another. In some cases (if something else is drawn inbetween and > a color changed twice), then the second text will be black. But it's > quite unpredictable (that one might even be bug in my code, so I don't > want to complain before I have an example). Ok, I looked into this again, and I was definately wrong. The actual problem appears to be that metapost does not write a color switch for 'black' when it appears at the start of a file, it simply assumes the start color is black. This could be considered a bug in MetaPost or a missing feature in ConTeXt (i have not decided yet :-)). Quick fix: You can start your MP code with an explicit color initialization. \startMPcode special "0 setgray"; ...... \stopMPcode A hack, I know. MetaPost should be able to distinguish between draw p and draw p withcolor (0,0,0) but currently it can't (because the structure is initialized as (0,0,0)). It is not quite a bug either, because there may well be MP code out there that depends on this. In fact, probably code by Knuth, Hobby, Jacko, and Hans ;-) > > A question for you or Hans: can please someone explain me in a few > words what's the main strategy/philosophy behind \sometxt. I don't > understand exactly how TeX processes it (and metapost > shrinks/expands/shifts/colors) it inline. TeX typesets the argument of the \sometxt macro in a hbox and writes its box dimensions to <jobname-mpgraph.mpb>. To the metapost file, a zero-padded serial number is written instead, and MP uses the dimensions it finds in <jobname-mpgraph.mpb> for the positioning of that label. ConTeXt then replaces the metapost label number with the TeX material while interpreting the Metapost result. This is the short version, the actual situation is a little bit more complex (not a whole lot though). The actual code is in meta-tex.tex and mp-txts.mp Cheers, taco ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 14:37 ` Taco Hoekwater @ 2006-08-06 17:02 ` Mojca Miklavec 2006-08-06 21:48 ` Hans Hagen 2006-08-06 22:02 ` Hans Hagen 2 siblings, 0 replies; 11+ messages in thread From: Mojca Miklavec @ 2006-08-06 17:02 UTC (permalink / raw) On 8/6/06, Taco Hoekwater wrote: > Hi Mojca, > > Mojca Miklavec wrote: > > > > But the other \sometxt was indeed red - withcolor seems to work, but > > only conditionally. And I have some weird examples of two texts one > > after another. In some cases (if something else is drawn inbetween and > > a color changed twice), then the second text will be black. But it's > > quite unpredictable (that one might even be bug in my code, so I don't > > want to complain before I have an example). > > Ok, I looked into this again, and I was definately wrong. > > The actual problem appears to be that metapost does not write a > color switch for 'black' when it appears at the start of a file, What a pitty that metapost wasn't one of Knuth's programs ;) > it simply assumes the start color is black. This could be > considered a bug in MetaPost or a missing feature in ConTeXt > (i have not decided yet :-)). > > Quick fix: You can start your MP code with an explicit color > initialization. > > \startMPcode > special "0 setgray"; > ...... > \stopMPcode > > > A hack, I know. MetaPost should be able to distinguish between > draw p > and > draw p withcolor (0,0,0) > but currently it can't (because the structure is initialized > as (0,0,0)). It is not quite a bug either, because there may > well be MP code out there that depends on this. > In fact, probably code by Knuth, Hobby, Jacko, and Hans ;-) Well, now to be honest: color "zero" (not "0 setgray", but the first color in Gnuplot) is not supposed to be black, but should be "foreground color" according to the guidelines (not that other divices are configurable in that respect, but anyway). So it might indeed make more sense to inherit the "textcolor". What do you think? I spotted the problem when I was using a dark background with white text on it. I'm not sure if I indeed want black or not. I want to make the colors configurable anyway (which they're currently not, but I have to figure out how to do that first), probably with something like \defineconversion[color set x][white,red,yellow,green] \setupGNUPLOT[colorset=color set x] % or perhaps even something like "foregroundcolor|maincolor=white" So I actually liked the fact that the numbers on the plot were white without having to configure anything (red and green were clearly seen on the background), but the plot as a whole was useless since the borders were still black & invisible and on some plots some text was black as well (in a pseudo random way). So rather than using that hack I would prefer to ask: which color should I define in the module to make the border of the same color as "textcolor"? Or (a question for later, it's not on the top priority right now): how can I extract the color from \setupGNUPLOT[foregroundcolor=yellow] and store it to a variable "color gp_foregroundcolor;" defined in a module? Any other thoughts about it? > > A question for you or Hans: can please someone explain me in a few > > words what's the main strategy/philosophy behind \sometxt. I don't > > understand exactly how TeX processes it (and metapost > > shrinks/expands/shifts/colors) it inline. > > TeX typesets the argument of the \sometxt macro in a hbox and > writes its box dimensions to <jobname-mpgraph.mpb>. > > To the metapost file, a zero-padded serial number is written > instead, and MP uses the dimensions it finds in <jobname-mpgraph.mpb> > for the positioning of that label. > > ConTeXt then replaces the metapost label number with the TeX material > while interpreting the Metapost result. > > This is the short version, the actual situation is a little bit more > complex (not a whole lot though). The actual code is in meta-tex.tex > and mp-txts.mp Thanks for the wonderful explanation! Thank you again, Mojca ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 14:37 ` Taco Hoekwater 2006-08-06 17:02 ` Mojca Miklavec @ 2006-08-06 21:48 ` Hans Hagen 2006-08-06 22:02 ` Hans Hagen 2 siblings, 0 replies; 11+ messages in thread From: Hans Hagen @ 2006-08-06 21:48 UTC (permalink / raw) Taco Hoekwater wrote: > Quick fix: You can start your MP code with an explicit color > initialization. > > \startMPcode > special "0 setgray"; > ...... > \stopMPcode > > > A hack, I know. MetaPost should be able to distinguish between > draw p > and > draw p withcolor (0,0,0) > but currently it can't (because the structure is initialized > as (0,0,0)). It is not quite a bug either, because there may > well be MP code out there that depends on this. > In fact, probably code by Knuth, Hobby, Jacko, and Hans ;-) > -) i think that (given that in principle mp produces stand alone ps code) it should start out with black; when embedding as eps or when used as xform in pdf thsi probably is automatically taken care of it makes sense to let mp do that for you; there are a few places where context forces the defaultcolor; we can make it an opion in the mp topdf converter as well Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 14:37 ` Taco Hoekwater 2006-08-06 17:02 ` Mojca Miklavec 2006-08-06 21:48 ` Hans Hagen @ 2006-08-06 22:02 ` Hans Hagen 2006-08-07 8:04 ` Mojca Miklavec 2 siblings, 1 reply; 11+ messages in thread From: Hans Hagen @ 2006-08-06 22:02 UTC (permalink / raw) Taco Hoekwater wrote: > Hi Mojca, > > Mojca Miklavec wrote: > >> But the other \sometxt was indeed red - withcolor seems to work, but >> only conditionally. And I have some weird examples of two texts one >> after another. In some cases (if something else is drawn inbetween and >> a color changed twice), then the second text will be black. But it's >> quite unpredictable (that one might even be bug in my code, so I don't >> want to complain before I have an example). >> > > Ok, I looked into this again, and I was definately wrong. > > The actual problem appears to be that metapost does not write a > color switch for 'black' when it appears at the start of a file, > it simply assumes the start color is black. This could be > considered a bug in MetaPost or a missing feature in ConTeXt > (i have not decided yet :-)). > > Quick fix: You can start your MP code with an explicit color > initialization. > > \startMPcode > special "0 setgray"; > ...... > \stopMPcode > > > A hack, I know. MetaPost should be able to distinguish between > draw p > and > draw p withcolor (0,0,0) > but currently it can't (because the structure is initialized > as (0,0,0)). It is not quite a bug either, because there may > well be MP code out there that depends on this. > In fact, probably code by Knuth, Hobby, Jacko, and Hans ;-) > > in meta-pdf.tex: \chardef\blackoutMPgraphic\plusone \def\finishMPgraphic {\stopMPresources \egroup \setbox\scratchbox\vbox {\forgetall \hbox {\PDFcode{q \MPxscale\space 0 0 \MPyscale\space \MPxoffset\space \MPyoffset\space cm}% \ifcase\blackoutMPgraphic\or\PDFcode{0 g 0 G}\fi \lower\MPyshift\box\scratchbox % unscaled shift \PDFcode{Q}}}% \ht\scratchbox\MPheight \wd\scratchbox\MPwidth \dp\scratchbox\zeropoint\relax \dopackageMPgraphic\scratchbox \egroup \endinput} \starttext \color[red]{\startMPcode draw fullcircle scaled 5cm ; draw btex test etex ; \stopMPcode red} \startreusableMPgraphic{test} draw fullcircle scaled 5cm ; draw btex test etex ; \stopreusableMPgraphic \color[red]{red \reuseMPgraphic{test} red} \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-06 22:02 ` Hans Hagen @ 2006-08-07 8:04 ` Mojca Miklavec 2006-08-07 8:15 ` Taco Hoekwater 0 siblings, 1 reply; 11+ messages in thread From: Mojca Miklavec @ 2006-08-07 8:04 UTC (permalink / raw) On 8/7/06, Hans Hagen wrote: > Taco Hoekwater wrote: > > Hi Mojca, > > > > Mojca Miklavec wrote: > > > >> But the other \sometxt was indeed red - withcolor seems to work, but > >> only conditionally. And I have some weird examples of two texts one > >> after another. In some cases (if something else is drawn inbetween and > >> a color changed twice), then the second text will be black. But it's > >> quite unpredictable (that one might even be bug in my code, so I don't > >> want to complain before I have an example). > >> > > > > Ok, I looked into this again, and I was definately wrong. > > > > The actual problem appears to be that metapost does not write a > > color switch for 'black' when it appears at the start of a file, > > it simply assumes the start color is black. This could be > > considered a bug in MetaPost or a missing feature in ConTeXt > > (i have not decided yet :-)). > > > > Quick fix: You can start your MP code with an explicit color > > initialization. > > > > \startMPcode > > special "0 setgray"; > > ...... > > \stopMPcode > > > > > > A hack, I know. MetaPost should be able to distinguish between > > draw p > > and > > draw p withcolor (0,0,0) > > but currently it can't (because the structure is initialized > > as (0,0,0)). It is not quite a bug either, because there may > > well be MP code out there that depends on this. > > In fact, probably code by Knuth, Hobby, Jacko, and Hans ;-) > > > > > in meta-pdf.tex: > > \chardef\blackoutMPgraphic\plusone > > \def\finishMPgraphic > {\stopMPresources > \egroup > \setbox\scratchbox\vbox > {\forgetall > \hbox > {\PDFcode{q \MPxscale\space 0 0 \MPyscale\space \MPxoffset\space \MPyoffset\space cm}% > \ifcase\blackoutMPgraphic\or\PDFcode{0 g 0 G}\fi > \lower\MPyshift\box\scratchbox % unscaled shift > \PDFcode{Q}}}% > \ht\scratchbox\MPheight > \wd\scratchbox\MPwidth > \dp\scratchbox\zeropoint\relax > \dopackageMPgraphic\scratchbox > \egroup > \endinput} > > > \starttext > > \color[red]{\startMPcode > draw fullcircle scaled 5cm ; > draw btex test etex ; > \stopMPcode red} > > \startreusableMPgraphic{test} > draw fullcircle scaled 5cm ; > draw btex test etex ; > \stopreusableMPgraphic > > \color[red]{red \reuseMPgraphic{test} red} > > \stoptext Thanks! This indeed solves the problem. However, I'm not sure any more whether blackoutMPgraphic should be true or false by default. One of my old files (when I was learning metapost from the manual): def star (expr size, n, pos) = for a=0 step 360/n until round(360*(1-1/n)) : draw (origin -- (size/2,0)) rotatedaround (origin,a) shifted pos ; endfor ; enddef ; beginfig(803) ; pickup pencircle scaled 2mm ; star(2cm,5,origin) ; endfig ; -------------------------------- \useexternalfigure[pentastar][star.803][height=4cm] \starttext \placefigure {A five||point star drawn by \METAPOST.} {\color[green]{\externalfigure[pentastar]}} % I wanted it to be green \stoptext -------------------------------- I tried that one once more because I remember that I was very happy to be able to color the star from outside without modifying the figure itself (I didn't use any explicit color to make it black though). I don't mind it either way (now that I know how to switch it on or off), but I'm not sure if there are not other people using the same trick as well. The "real problem" appears in the following figure where the first black is ignored and the second one is not, so it's rather inconsistent: \setupcolors [state=start,textcolor=blue] \chardef\blackoutMPgraphic 0 \starttext \startMPcode draw \sometxt{blue} withcolor black; draw \sometxt{red} shifted (1.5cm,0) withcolor red; draw \sometxt{black} shifted (3cm,0) withcolor black; \stopMPcode \stoptext I can image a "fair solution" to draw "withcolor black" in black and to let the parts with no explicit color and an empty drawoptions() string to use the "default color" (perhaps with gsave/grestore). But I'm not entitled to judge about it. In any case I'll have to use a solution which will not depend on this behaviour. Is there any chance to get "withcolor somecolor", where "somecolor" is the color set with "textcolor=somecolor"? Thanks a lot, Mojca ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-07 8:04 ` Mojca Miklavec @ 2006-08-07 8:15 ` Taco Hoekwater 2006-08-07 9:40 ` Mojca Miklavec 0 siblings, 1 reply; 11+ messages in thread From: Taco Hoekwater @ 2006-08-07 8:15 UTC (permalink / raw) Mojca Miklavec wrote: > > The "real problem" appears in the following figure where the first > black is ignored and the second one is not, so it's rather > inconsistent: It is not really inconsistent, the rule is very simple: all use of "withcolor <black>" upto the first non-zero color is ignored by metapost. > I can image a "fair solution" to draw "withcolor black" in black and > to let the parts with no explicit color and an empty drawoptions() > string to use the "default color" (perhaps with gsave/grestore). But > I'm not entitled to judge about it. Yes, that's what I thought. But I need to patch metapost for that, so that solution won't be available in a reliable way for quite some time yet. > In any case I'll have to use a solution which will not depend on this > behaviour. Is there any chance to get "withcolor somecolor", where > "somecolor" is the color set with "textcolor=somecolor"? Maybe withcolor \MPcolor{textcolor} ? (I am guessing) Cheers, Taco ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-07 8:15 ` Taco Hoekwater @ 2006-08-07 9:40 ` Mojca Miklavec 2006-08-07 10:25 ` Hans Hagen 0 siblings, 1 reply; 11+ messages in thread From: Mojca Miklavec @ 2006-08-07 9:40 UTC (permalink / raw) On 8/7/06, Taco Hoekwater wrote: > > Mojca Miklavec wrote: > > > > The "real problem" appears in the following figure where the first > > black is ignored and the second one is not, so it's rather > > inconsistent: > > It is not really inconsistent, the rule is very simple: > > all use of "withcolor <black>" upto the first non-zero color > is ignored by metapost. OK, I "give up". I just have to reimplement the terminal to fist store everything and then write out the black stuff before anything else ;) > > I can image a "fair solution" to draw "withcolor black" in black and > > to let the parts with no explicit color and an empty drawoptions() > > string to use the "default color" (perhaps with gsave/grestore). But > > I'm not entitled to judge about it. > > Yes, that's what I thought. But I need to patch metapost for > that, so that solution won't be available in a reliable way > for quite some time yet. I realise that and I'll try to implement in an independant way. > > In any case I'll have to use a solution which will not depend on this > > behaviour. Is there any chance to get "withcolor somecolor", where > > "somecolor" is the color set with "textcolor=somecolor"? > > Maybe withcolor \MPcolor{textcolor} ? (I am guessing) Something that seems to work after some trial-and-error: \definecolor[textcolor][\@@cltextcolor] But I'm guessing as well. Let's wait for the next bug in the module then ;) I now used \definecolor[textcolor][\@@cltextcolor] % \MPextensions, should be specific to \startGNUPLOTgraphic \startMPextensions if unknown context_gplot: input mp-gnuplot.mp ; fi; % overloading gp_color_foreground := \MPcolor{textcolor}; gp_color_lt[-2] := gp_color_foreground; \stopMPextensions (because there's probably no way to put \MPcolor{textcolor} to *.mp file) But now there's a minor problem. I have to initialize "\setupcolors[textcolor=blue]" *before* loading the gnuplot module, otherwise it's all black. In contrast, if I use \setupcolors[state=start,textcolor=blue] \usemodule[gnuplot] a graphic here will be blue \setupcolors[textcolor=red] a graphic here will be red, but text will still be blue And \usemodule[gnuplot] \setupcolors[state=start,textcolor=blue] a graphic here will be black \setupcolors[textcolor=red] a graphic here will be black, but text will still be blue I suspect what's going on: as long as textcolor= is undefined, \@@cltextcolor will expand to black and remain black even if I set "textcolor=something" later. If it's initialised before loading the module, it will expand to some color and if I change "textcolor=someothercolor" later, the color will follow the new definition. What's the best remedy for it? (And sorry for way too many questions.) Thanks, Mojca (some files to play with are under http://pub.mojca.org/gnuplot/temp/) ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: metafun & \sometxt: should black be "black" or "textcolor"? 2006-08-07 9:40 ` Mojca Miklavec @ 2006-08-07 10:25 ` Hans Hagen 0 siblings, 0 replies; 11+ messages in thread From: Hans Hagen @ 2006-08-07 10:25 UTC (permalink / raw) Mojca Miklavec wrote: > On 8/7/06, Taco Hoekwater wrote: > >> Mojca Miklavec wrote: >> >>> The "real problem" appears in the following figure where the first >>> black is ignored and the second one is not, so it's rather >>> inconsistent: >>> >> It is not really inconsistent, the rule is very simple: >> >> all use of "withcolor <black>" upto the first non-zero color >> is ignored by metapost. >> > > OK, I "give up". I just have to reimplement the terminal to fist store > everything and then write out the black stuff before anything else ;) > i adapted context to default to black so don't worry Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-08-07 10:25 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-08-06 2:32 metafun & \sometxt: should black be "black" or "textcolor"? Mojca Miklavec 2006-08-06 8:52 ` Taco Hoekwater 2006-08-06 11:26 ` Mojca Miklavec 2006-08-06 14:37 ` Taco Hoekwater 2006-08-06 17:02 ` Mojca Miklavec 2006-08-06 21:48 ` Hans Hagen 2006-08-06 22:02 ` Hans Hagen 2006-08-07 8:04 ` Mojca Miklavec 2006-08-07 8:15 ` Taco Hoekwater 2006-08-07 9:40 ` Mojca Miklavec 2006-08-07 10:25 ` Hans Hagen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).