Am 30.06.2025 um 05:32 schrieb Emanuel Han via ntg-context:
I want my custom color rose_color to be applied for background color for \framed inside lmt_text. For fill fullcircle, it works. With predefined colors as green, it works.

\starttext

\startMPcode

color rose_color; rose_color = 1/256(255,204,255);

%not working
draw lmt_text [text ="\framed[background=color,backgroundcolor=rose_color,frame=on, location=low]{a rose box}",];

%working
draw lmt_text [text ="\framed[background=color,backgroundcolor=green,frame=on, location=low] {a green box}",] shifted (1cm,1cm);

%working
fill fullcircle scaled 2cm shifted (0,3cm) withcolor rose_color;

\stopMPcode

\stoptext

The color modes in TeX and MetaPost are separate systems and while you can't use MetaPost defined colors in TeX the reverse is possible, to use TeX defined color use \MPcolor{...} or "...".

%%%% begin example
\starttext

\startMPcode
draw fullcircle scaled 1cm withcolor red ; % MetaPost color
draw fullcircle scaled 2cm withcolor \MPcolor{green} ; % TeX color
draw fullcircle scaled 3cm withcolor "blue" ; % TeX color
\stopMPcode

\stoptext
%%%% end example

A new feature in LMTX is to create TeX based colors in MetaPost with the definecolor function but you can only use it within MetaPost.

%%%% begin example
\definecolor [my_red]  [r=1]
\definecolor [my_blue] [b=1]
%\definecolor [my_blue] [c=1] % possible

\starttext

\startMPcode
definecolor [ name = "my_green", g = 1 ] ;
%definecolor [ name = "my_blue",  g = 1 ] ; % not possible
\stopMPcode

my_red   \doifelsecolor{my_red}  {does}{doesn’t} exist.\par
my_green \doifelsecolor{my_green}{does}{doesn’t} exist.\par
my_blue  \doifelsecolor{my_blue} {does}{doesn’t} exist.\par

\startMPcode
draw fullcircle scaled 1cm withcolor "my_red"   ;
draw fullcircle scaled 2cm withcolor "my_green" ;
draw fullcircle scaled 3cm withcolor "my_blue"  ;
\stopMPcode

\stoptext
%%%% end example

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to