No sé si es un duplicado o no, pero podemos cerrarlo si lo es.
He estado tratando de aprender ConTeXt
. Me encantan especialmente los formatos de encabezado y número de página que veo en la documentación que he descargado, logrados mediante el uso de Metapost
/ Metafun
. He estado tratando de lograr este efecto en \chapter
(producido en LaTeX a través de egreg
'sgmp
paquete.
Para ello he copiado y pegado códigos de varios archivos encontrados enaquí. Este es el resultado que estoy obteniendo por ahora.
con este código.
\setuppapersize[A4][A4]
\setuplayout[topspace=0.5in, backspace=1in, header=24pt, footer=36pt,
height=middle, width=middle]
\def\MPclipOne#1#2#3#4#5%
{\startuseMPgraphic{clip:one}
w := #1; width := 100; wfactor := w/width;
h := #2; height := 100; hfactor := h/height;
%
color lightred; lightred := (.90,.50,.50);
color lightgray; lightgray := (.95,.95,.95);
color gray; gray := (.50,.50,.50);
%
def random_delta (expr d) =
d-(uniformdeviate 2d)
enddef;
%
z1 = (0,height);
z2 = (0,0);
z3 = (width,0);
z4 = (width,height);
%
z5 = (width+random_delta(.2width),height+random_delta(.2height));
z6 = (.5width+random_delta(.1width),height+random_delta(.1height));
%
pickup pencircle
xscaled (#3/wfactor)
yscaled (#3/(2*hfactor))
rotated 30;
%
draw z5..z1..z2..z3..z4..z6 withcolor #4;
%
pickup pencircle
xscaled (#3/wfactor)
yscaled (#3/hfactor);
%
draw z1 withcolor #5;
draw z2 withcolor #5;
draw z3 withcolor #5;
draw z4 withcolor #5;
draw z5 withcolor #5;
draw z6 withcolor #5;
%
newwidth := (xpart (urcorner currentpicture)) -
(xpart (llcorner currentpicture));
newheight := (ypart (urcorner currentpicture)) -
(ypart (llcorner currentpicture));
%
currentpicture := currentpicture
xscaled (w/newwidth) yscaled (h/newheight);
\stopuseMPgraphic
\useMPgraphic{clip:one}{}}
\defineoverlay
[KopAchtergrond]
[\MPclipOne{\overlaywidth}{\overlayheight}{10pt}{gray}{red}]
\def\HeadCommand#1#2%
{\alignedline{\v!outer}{\v!left}
{\framed
[\c!background=KopAchtergrond,
\c!width=\v!fit,
\c!height=\v!fit,
\c!frame=\v!off,
\c!strut=\v!no,
\c!offset=24pt,
\c!align=\v!middle]
{\doifmode{*sectionnumber}
{#1\kern.5em% strut niet geset, zou wel moeten
\hbox{\color[headrule]{\vrule\!!width1pt\!!height1.5\ht\strutbox\!!depth1.25\dp\strutbox}}%
\kern.5em}%
#2}}}
\setuphead
[\v!chapter]
[\c!command=\HeadCommand,
\v!appendix\c!label=none,
\c!page=,
\c!before=\vskip36pt plus 6pt minus 6pt,
\c!after=\vskip24pt]
\starttext
\chapter{Sample chapter}
\stoptext
Por favor, háganme entender qué está sucediendo aquí y cómo lograr el efecto deseado.
Respuesta1
Te falta un \unprotect
.. \protect
bloque y un \unexpanded
.
\setuppapersize[A4][A4]
\setuplayout[topspace=0.5in, backspace=1in, header=24pt, footer=36pt,
height=middle, width=middle]
\unprotect
\def\MPclipOne#1#2#3#4#5%
{\startuseMPgraphic{clip:one}
w := #1; width := 100; wfactor := w/width;
h := #2; height := 100; hfactor := h/height;
%
color lightred; lightred := (.90,.50,.50);
color lightgray; lightgray := (.95,.95,.95);
color gray; gray := (.50,.50,.50);
%
def random_delta (expr d) =
d-(uniformdeviate 2d)
enddef;
%
z1 = (0,height);
z2 = (0,0);
z3 = (width,0);
z4 = (width,height);
%
z5 = (width+random_delta(.2width),height+random_delta(.2height));
z6 = (.5width+random_delta(.1width),height+random_delta(.1height));
%
pickup pencircle
xscaled (#3/wfactor)
yscaled (#3/(2*hfactor))
rotated 30;
%
draw z5..z1..z2..z3..z4..z6 withcolor #4;
%
pickup pencircle
xscaled (#3/wfactor)
yscaled (#3/hfactor);
%
draw z1 withcolor #5;
draw z2 withcolor #5;
draw z3 withcolor #5;
draw z4 withcolor #5;
draw z5 withcolor #5;
draw z6 withcolor #5;
%
newwidth := (xpart (urcorner currentpicture)) -
(xpart (llcorner currentpicture));
newheight := (ypart (urcorner currentpicture)) -
(ypart (llcorner currentpicture));
%
currentpicture := currentpicture
xscaled (w/newwidth) yscaled (h/newheight);
\stopuseMPgraphic
\useMPgraphic{clip:one}{}}
\defineoverlay
[KopAchtergrond]
[\MPclipOne{\overlaywidth}{\overlayheight}{10pt}{gray}{red}]
\unexpanded\def\HeadCommand#1#2%
{\alignedline{\v!outer}{\v!left}
{\framed
[\c!background=KopAchtergrond,
\c!width=\v!fit,
\c!height=\v!fit,
\c!frame=\v!off,
\c!strut=\v!no,
\c!offset=24pt,
\c!align=\v!middle]
{\doifmode{*sectionnumber}
{#1\kern.5em% strut niet geset, zou wel moeten
\hbox{\color[headrule]{\vrule\!!width1pt\!!height1.5\ht\strutbox\!!depth1.25\dp\strutbox}}%
\kern.5em}%
#2}}}
\setuphead
[\v!chapter]
[\c!command=\HeadCommand,
\v!appendix\c!label=none,
\c!page=,
\c!before=\vskip36pt plus 6pt minus 6pt,
\c!after=\vskip24pt]
\protect
\starttext
\chapter{Sample chapter}
\stoptext
Pero este es un código ConTeXt realmente antiguo. Aquí la comunicación entre TeX y Metapost se realiza a través de parámetros macro. Simplemente usaría parámetros clave-valor para la comunicación. Aquí hay una posible solución, donde uso dotcolot
la clave para especificar el color del punto.
\setupexternalfigures[location={local,global}]
\startuseMPgraphic{randomcircle}
width := 100; wfactor := OverlayWidth/width;
height := 100; hfactor := OverlayHeight/height;
%
color dotcolor; dotcolor := \MPcolor{\framedparameter{dotcolor}};
def random_delta (expr d) =
d-(uniformdeviate 2d)
enddef;
%
z1 = (0,height);
z2 = (0,0);
z3 = (width,0);
z4 = (width,height);
%
z5 = (width, height) randomized (0.2width, 0.2height);
z6 = (0.5width, height) randomized (0.1width, 0.1height);
%
pickup pencircle
xscaled (OverlayLineWidth/wfactor)
yscaled (OverlayLineWidth/(2*hfactor))
rotated 30;
%
draw z5..z1..z2..z3..z4..z6 withcolor OverlayLineColor;
%
pickup pencircle
xscaled (OverlayLineWidth/wfactor)
yscaled (OverlayLineWidth/hfactor);
%
draw z1 withcolor dotcolor;
draw z2 withcolor dotcolor;
draw z3 withcolor dotcolor;
draw z4 withcolor dotcolor;
draw z5 withcolor dotcolor;
draw z6 withcolor dotcolor;
%
newwidth := (xpart (urcorner currentpicture)) -
(xpart (llcorner currentpicture));
newheight := (ypart (urcorner currentpicture)) -
(ypart (llcorner currentpicture));
%
currentpicture := currentpicture
xscaled (OverlayWidth/newwidth) yscaled (OverlayHeight/newheight);
\stopuseMPgraphic
\defineoverlay
[randomcircle]
[\useMPgraphic{randomcircle}]
Ahora la superposición randomcircle
se puede utilizar con cualquier comando que acepte una superposición. Por ejemplo, un marco y una figura:
que se obtuvo usando:
\definecolor[gray][r=0.5, g=0.5, b=0.5]
\starttext
\startTEXpage[offset=10mm]
\dontleavehmode
\framed[background=randomcircle, dotcolor=red, framecolor=gray, offset=24pt, rulethickness=10pt, frame=off]
{ Hello World}
\hskip 6em
\externalfigure[cow.pdf]
[width=3cm,
background=randomcircle, dotcolor=red, framecolor=gray,
backgroundoffset=24pt, rulethickness=10pt, frame=off]
\stopTEXpage
\stoptext
Ahora, colocar el gráfico alrededor del encabezado de la sección es simplemente una cuestión de configurar la command
clave de \setuphead
.