Background
Looking to parameterize a horizontal rule (for headers and footers) that has three colour stops (A to B to C) and a variable thickness. For example:
Single Stop Code
The following code draws lines in the document header and footer using linear_shade
:
\setupcolors[pagecolormodel=auto]
% Colour Stop #1
\definecolor[BrandTertiaryColour][h=FF6A00]
% Colour Stop #2
\definecolor[BrandPrimaryColour][h=E61739]
% Colour Stop #3
\definecolor[BrandSecondaryColour][h=991F3D]
% Define the graphics for the header and footer separator line
\startMPinclusions
% t is the line thickness (in points)
def create_line( expr t ) =
path pbegan;
pbegan := envelope pensquare of ((0, 0) -- (OverlayWidth, 0)) yscaled t;
linear_shade(
pbegan, 0, \MPcolor{BrandTertiaryColour}, \MPcolor{BrandPrimaryColour}
);
enddef;
\stopMPinclusions
\startuseMPgraphic{HeaderSeparator}
create_line( 2pt );
\stopuseMPgraphic
\startuseMPgraphic{FooterSeparator}
create_line( 0.5pt );
\stopuseMPgraphic
\defineoverlay[HeaderSeparatorOverlay][
\useMPgraphic{HeaderSeparator}
]
\defineoverlay[FooterSeparatorOverlay][
\useMPgraphic{FooterSeparator}
]
% Draw the header and footer rules.
\setupbackgrounds[header][text][
background=HeaderSeparatorOverlay,
]
\setupbackgrounds[footer][text][
background=FooterSeparatorOverlay,
]
\starttext
\input knuth
\stoptext
Questions
I am wondering:
- Where do I find the prototype definition for
linear_shade
(i.e., does it support multiple colour stops)? - How can the duplicate Overlays (HeaderSeparatorOverlay, FooterSeparatorOverlay) be eliminated?
Ideas
I was thinking of two calls to linear_shade
:
path pbegan;
path pended;
pbegan := envelope pensquare of ((0, 0) -- ((OverlayWidth/2), 0)) yscaled t;
pended := envelope pensquare of (((OverlayWidth/2), 0) -- (OverlayWidth, 0)) yscaled t;
linear_shade(
pbegan, 0, \MPcolor{BrandTertiaryColour}, \MPcolor{BrandPrimaryColour}
);
linear_shade(
pended, 0, \MPcolor{BrandPrimaryColour}, \MPcolor{BrandSecondaryColour}
);
But there's probably a way to write it with fewer lines of--or less brittle--code.
Related
- lost linear_shade output
- (ConTeXt MkIV) Text in PiechartMP
- https://www.tug.org/docs/metapost/mpman.pdf
- http://www.ctex.org/documents/context/metafun-p.pdf
- https://tex.stackexchange.com/a/330016/2148
- http://wiki.contextgarden.net/Command/useMPgraphic
- http://wiki.contextgarden.net/Command/startMPinclusions
`kpsexpand '$TEXMFCONTEXT'`/metapost/context/base/mpiv/mp-mlib.mpiv
– Henri Menke Jan 12 '18 at 23:20