これが重複かどうかはわかりませんが、重複している場合は閉じることができます。
私は を学ぼうとしています。特に、私がダウンロードしたドキュメントで/ConTeXt
を使って実現した見出しとページ番号の書式設定が気に入っています。私は(LaTeX で'sを使って生成)でこの効果を実現しようとしています。Metapost
Metafun
\chapter
egreg
gmp
パッケージ。
この目的のために、私はいくつかのファイルからコードをコピーして貼り付けました。ここ現時点では、これが出力結果です。
このコードで。
\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
ここで何が起こっているのか、そして望む効果をどのように達成できるのか教えてください。
答え1
\unprotect
..\protect
ブロックと\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
しかし、これは本当に古い ConTeXt コードです。ここでは、TeX と Metapost 間の通信はマクロ パラメータを介して行われます。通信にはキー値パラメータを使用します。ここでは、dotcolot
キーを使用してドットの色を指定します。
\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}]
これで、オーバーレイを受け入れる任意のコマンドでオーバーレイrandomcircle
を使用できるようになりました。たとえば、フレームと図:
これは以下を使用して取得されました:
\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
command
これで、セクション見出しの周囲にグラフィックを配置するには、のキーを設定するだけです\setuphead
。