Problems with uniqueMPgraphic
I have this small test case: and it comes out with the wrong colors. So, I think I know that this is because of the same dimensions but I want to have different colors for the same overlay-dimensions. How do I do that? bye, Adam.
Adam Duck wrote:
I have this small test case:
------------------------------------------------------------------------
and it comes out with the wrong colors. So, I think I know that this is because of the same dimensions but I want to have different colors for the same overlay-dimensions. How do I do that?
\setupcolors[state=start] ----------------------------------------------------------------- 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 -----------------------------------------------------------------
Here is another approach % small extension to underbar, accepts [settings] \unprotected \def\underbarparameter#1{\getvalue{\??on#1}} \unexpanded\def\dounderbar#1% {\let\betweenisolatedwords#1% \dosingleempty\redounderbar} \unexpanded\def\redounderbar[#1]#2% {\iffirstargument\setupunderbar[#1]\fi \processisolatedwords{#2}\dodounderbar \egroup} % roughly the same \startuniqueMPgraphic{underline}{color,width,height,depth} numeric w,h; w := \MPvar{width} ; h := \MPvar{height} ; d := \MPvar{depth} ; path p; p := (0, -h)..(w/2,0 + (h/3 randomized h/3))..(w, -h); p := p shifted (0,-d) ; draw p withpen pencircle scaled 1 withcolor \MPvar{color} ; setbounds currentpicture to unitsquare xyscaled (OverlayWidth,OverlayHeight); \stopuniqueMPgraphic hook into underbar: \unprotect \def\underbarmethodx#1#2#3% mp {\hbox to #1{\uniqueMPgraphic {underline}{width=#1,height=#2,depth=\underbarparameter\c!bottomoffset,color=\underbarparameter\c!color}}} \protect % usage: \setupunderbar[alternative=x,bottomoffset=1ex,color=red] \startitemize \item test: \underbars[color=blue]{how are you?} \item test: \underbars{how are you?} \item test: \underbars{how are you?} \stopitemize \stoptext in your case, in order to make the graphic unique, you need to pass the second arg in order to make them unique (uniqueness is determined by dimensions and a few more things; another option would be to use the backgroundcolor of inframed which is accessible by \OverlayColor and also determines uniqueness \startuniqueMPgraphic{underline}{color} alternative \startuniqueMPgraphic{underline} numeric w,h; w := OverlayWidth; h := ExHeight/6; path p; p := (0, -h)..(w/2,0 + (h/3 randomized h/3))..(w, -h); draw p withpen pencircle scaled 1 withcolor OverlayColor ; setbounds currentpicture to unitsquare xyscaled (OverlayWidth,OverlayHeight); \stopuniqueMPgraphic \defineoverlay[underline][\uniqueMPgraphic{underline}] \def\aidul{\dosingleempty\doaidul} \def\doaidul[#1]{\inframed[background=underline,frame=off,#1]} \setupcolors[state=start] \startitemize \item test: \aidul[backgroundcolor=red]{how} \aidul[color=green]{are} \aidul[color=blue]{you?} \item test:\aidul[backgroundcolor=blue]{how} \aidul[color=green]{how} \aidul[color=red]{how} \stopitemize 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 -----------------------------------------------------------------
Hans Hagen
alternative
\startuniqueMPgraphic{underline} numeric w,h; w := OverlayWidth; h := ExHeight/6; path p; p := (0, -h)..(w/2,0 + (h/3 randomized h/3))..(w, -h); draw p withpen pencircle scaled 1 withcolor OverlayColor ; setbounds currentpicture to unitsquare xyscaled (OverlayWidth,OverlayHeight); \stopuniqueMPgraphic
\defineoverlay[underline][\uniqueMPgraphic{underline}]
\def\aidul{\dosingleempty\doaidul} \def\doaidul[#1]{\inframed[background=underline,frame=off,#1]}
\setupcolors[state=start]
Thanks for the fast response and the many lines you've written (although I didn't understand everything). The OverlayColor works fine and as underlining is in the background, I'll take this aproach. So, one last question remains: why doesn't this work? \def\uli{backgroundcolor=peachpuff} \aidul[\uli]{test} bye, Adam.
Adam Duck wrote:
\def\aidul{\dosingleempty\doaidul} \def\doaidul[#1]{\inframed[background=underline,frame=off,#1]}
So, one last question remains: why doesn't this work?
\def\uli{backgroundcolor=peachpuff} \aidul[\uli]{test}
parsing .... \def\doaidul[#1]{\expanded{\inframed[background=underline,frame=off,#1]}} would work however, in that case i'd go for: \def\doaidul[#1]{\inframed[background=underline,frame=off,backgroundcolor=#1]} \definecolor[important][red] \definecolor[notimportant][green] and \aidul[important]{test} as well as \aidul[notimportant]{test} since one can redefine the colors 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 -----------------------------------------------------------------
participants (3)
-
Adam Duck
-
h h extern
-
Hans Hagen