[NTG-context] Why does this example from the MetaFun manual not work?

Gerben Wierda gerben.wierda at rna.nl
Wed Apr 8 12:20:35 CEST 2020


I would like to use the result of transparent() straight in my macros, so I can pass the colors with transparency using a single parameter. That should be possible if I understand the MetaFun manual (where I’ve copy-pasted this example from):

\starttext
\startMPpage[instance=doublefun]

vardef SampleText (expr t, c) =
  save p ; picture p ;
  p := image (draw t infont "\truefontname{Regular}") ;
  draw (p shifted (- xpart center p,0)) scaled 5 withcolor c;
enddef ;
SampleText ("Much Of This"   , transparent(1, .5, red  )) ;
SampleText ("Functionality"  , transparent(1, .5, green)) ;
SampleText ("Was Written"    , transparent(1, .5, blue )) ;
SampleText ("While Listening", transparent(1, .5, cmyk(1,0,0,0))) ;
SampleText ("To the CD's Of" , transparent(1, .5, cmyk(0,1,0,0))) ;
SampleText ("Tori Amos"      , transparent(1, .5, cmyk(0,0,1,0))) ;

\stopMPpage
\stoptext

But it results in:

system          > files > jobname 'testcolor', input './testcolor', result 'testcolor'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > level 2, order 3, name './testcolor.tex'
fonts           > preloading latin modern fonts (second stage)
fonts           > 'fallback modern-designsize rm 12pt' is loaded
metapost        > initializing instance 'doublefun:1' using format 'metafun' and method 'double'
metapost        > loading 'metafun' as '/usr/local/context-osx-64/tex/texmf-context/metapost/context/base/mpiv/metafun.mpxl' using method 'double'
metapost        > initializing number mode 'double'
metapost log    > 
metapost log    > loading metafun, including plain.mp version 1.004 for metafun iv and xl
metapost log    > 
metapost log    > ! Missing ')' has been inserted.
metapost log    > <to be read again> 
metapost log    >                    withprescript
metapost log    > transparent->(1)withprescript
metapost log    >                              "tr_alternative="&decimal.transparency_alternat...
metapost log    > <*> ... ("Much Of This" , transparent(1, .5, red )
metapost log    >                                                   ) ; SampleText ("Functiona...
metapost log    > 
backend         > xmp > using file '/usr/local/context-osx-64/tex/texmf-context/tex/context/base/mkiv/lpdf-pdx.xml'
pages           > flushing realpage 1, userpage 1, subpage 1
close source    > level 2, order 3, name './testcolor.tex'
close source    > level 1, order 3, name 'cont-yes.mkiv'

For me, it is not about passing colour on to ConTeXt to typeset text, these are colors that normally would be drawn with “withcolor ca withtransparency (method,factor)” but that requires the passing of many more parameters and a lot more work in coding.

Does transparent() maybe produce a string that looks like “ca withtransparency (method,factor)” so something only usable in draw/fill/etc statements? But in that case how does that work without scantokens to parse the string?

Is there a way I can do this without having twice the parameters (and I have to pass multiple colours)  in my macros everywhere?

Thanks,

G
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20200408/f5e4a868/attachment.htm>


More information about the ntg-context mailing list