5

I would like to draw a custom frame for the framed environment using Metafun. I am currently hard-coding the frame color within the Metafun definition. However, I would like the Metafun frame to reference the framecolor option of the framed environment and change color accordingly. This is what I have so far with hard-coded color options:

\startuniqueMPgraphic{box}
path p;
p := unitcircle xscaled \overlaywidth yscaled \overlayheight;

fill p withcolor .85white;
draw p withpen pencircle scaled 2pt withcolor .625red;
\stopuniqueMPgraphic

\defineoverlay[box][\uniqueMPgraphic{box}]

\starttext

\framed[framecolor=blue, background=box]{test}

\stoptext

Does the Metafun definition have access to framed options or is there another way to do this?

1 Answer 1

4

You can use \framedparameter{framecolor} to access the parameter. This results in an error if framecolor is not set. You can use \MPcolor with \framedparameter to fix that. Example:

\startuniqueMPgraphic{box}
  path p;
  p := unitcircle xscaled \overlaywidth yscaled \overlayheight;

  fill p withcolor .85white;
  draw p withpen pencircle scaled 2pt withcolor \MPcolor{\framedparameter{framecolor}};
\stopuniqueMPgraphic

\defineoverlay
  [box]
  [\uniqueMPgraphic{box}]

\starttext
  \framed[framecolor=blue, background=box]{test}
  \framed[background=box]{foobar}
\stoptext

result

3
  • Thanks! To get a better understanding of the solution, is the \[environment]parameter type command general? Could I use something similar in contexts outside of just framed?
    – ssokolen
    Jun 11, 2018 at 20:20
  • 1
    Yes, it's a general command. Also see ConTeXt: How do you create your own commands? This doesn't mean it works for every command. Only the ones that actually use the mentioned mechanisms.
    – Marco
    Jun 11, 2018 at 20:33
  • 3
    @Marco You can also use the OverlayLineColor variable to access the framecolor value. This variable and many others are listed in the MetaFun manual. Jun 11, 2018 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .