结语

结语

我想用章节标题做一些愚蠢的 Metapost 东西,因此设置一个命令来开始:

\setuphead[chapter][command=\ChapterTitle]

在该自定义命令中,我执行了以下内容,将编号和标题传递给应返回单独页面的 MetaPost 绘图:

\unexpanded\def\ChapterTitle#1#2{%
\setMPtext{number}{#1}
\setMPtext{title}{#2}
\startMPpage
\includeMPgraphic{chaptertitle}
\stopMPpage

所述绘图具有背景并处理这些变量。

\startuseMPgraphic{chaptertitle}{number,title}
StartPage;
fill unitsquare xyscaled( PaperWidth, PaperHeight ) withcolor red;
% Funky typographic stuff with number and title and more graphic thingies
StopPage;
\stopuseMPgraphic

所有这些放在一起作为 MWE:

\showframe

\setuppapersize[A8][A5,landscape]
\setuppaper[nx=4,ny=2]
\setuplayout[page][location=middle,marking=on]
\setuparranging[XY]

\setupbodyfont[8pt]

\startuseMPgraphic{chaptertitle}{number,title}
StartPage;
fill unitsquare xyscaled( PaperWidth, PaperHeight ) withpen pencircle scaled 1bp withcolor red;
StopPage;
\stopuseMPgraphic

\unexpanded\def\ChapterTitle#1#2{%
\setMPtext{number}{#1}
\setMPtext{title}{#2}
\startMPpage
\includeMPgraphic{chaptertitle}
\stopMPpage
}

\setuphead[chapter][command=\ChapterTitle]

\starttext
\startchapter[title={A chapter}]
\input ward
\stopchapter
\startchapter[title={Another chapter}]
\input tufte
\stopchapter
\startchapter[title={Another chapter}]
\input knuth
\stopchapter
\stoptext

我认为\startMPpage...\stopMPpage命令必须返回一个单独的页面,没有布局并调整到其绘图的大小,但是当与键结合时command\setuphead将绘图放在常规页面内,与文本区域稍微对齐:

MWE 的输出

作为一种解决方法,我尝试使用化妆页面将代码包装在自定义命令中,但无法使其工作。如果我定义自定义化妆,比如

\definemakeup[chaptertitle]

并为其设置布局所以它会自动与化妆品一起使用

\definelayout[chaptertitle][backspace=\zeropoint,header=\zeropoint,topspace=\zeropoint,margin=\zeropoint]

这将是同样的事情,因为看起来布局和构成并不耦合,但我不知道如何做到这一点)。如果我使用标准构成,则顶部偏移会消失,但不知道如何摆脱左边的偏移。

所有这些修饰都有点儿不靠谱。为了\setuphead以防万一,我尝试了其他参数,结果(令我惊讶的是)那个margin参数确实影响了左偏移,尽管左偏移似乎等于退格宽度加上某物我猜不出来。还是有解决办法的。

不确定我是否犯了一些新手错误或遗漏了一些愚蠢的东西,但我怎样才能让那些 MetaPost 页面标题实际上绘制为常规\startMPpage...\stopMPpage页面而不是常规页面?

答案1

像这样吗?

\showframe
\usecolors[svg]
\setuppapersize[A8][A5,landscape]
\setuppaper[nx=4,ny=2]
\setuplayout[page][location=middle,marking=on]
\setuparranging[XY]
\setupbodyfont[8pt]
\startuseMPgraphic{ChapterBG}
StartPage;
fill Page withcolor red;

%%% Just an example of what is possible here

fill fullcircle scaled 2cm shifted (1/4PaperWidth*left + center Page) withcolor resolvedcolor("turquoise");

%%% \structurenumber is the current structure (i.e. chapter)
%%% number. The same applies to \structuretitle

picture Pic;
Pic := image(draw outlinetext.d("\Romannumerals\structurenumber") (withcolor green);); 
draw Pic shifted (-center Pic) scaled 10 slanted 1/2 shifted center Page;
draw thetextext("\blue\ttbf\structuretitle",origin) scaled 2 rotated -45 shifted center Page;
StopPage;
\stopuseMPgraphic
\definelayer[ChapterBG]
%%% Our background setups
\startsetups lol
\setlayer[ChapterBG]{\useMPgraphic{ChapterBG}}%
\setupbackgrounds[page][background=ChapterBG]%
\page% Force a page break
\stopsetups
%%%
\setuphead[chapter]
    [placehead=no, %So no head in running text
     header=none,  %In order to avoid page numbers
     footer=none,  %Just in case
     insidesection=\setups{lol}] %Our setups are applied here
\starttext
\startchapter[title={A chapter}]
\input ward
\stopchapter
\startchapter[title={Another chapter}]
\input tufte
\stopchapter
\startchapter[title={Another chapter}]
\input knuth
\stopchapter
\stoptext

在此处输入图片描述

答案2

我找到了另一种(黑客式的)解决方案,从 Jairo A. del Río 发布的一些小线索开始,因为我暂时不想处理层,并且发现了\defineheadalternative一种我认为更为优雅的方法。

然而,当我这样做的时候,我发现了 MetaFun 上关于纸张尺寸的一个错误,我认为这些尺寸并不精确,并且(部分)导致了最初问题中 MWE 上显示的那些奇怪的间隙。

首先,完整的 MWE:

\showframe
\setuppapersize[A8][A5,landscape]
\setuppaper[nx=4,ny=2]
\setuplayout[page][location=middle,marking=on]
\setuparranging[XY]

\setupbodyfont[8pt]

\startuseMPgraphic{chaptertitle}
StartPage;
path p;
p := unitsquare xyscaled(52mm, 74mm);
fill p withcolor red;
draw thetextext("\blue\headnumbercontent",origin) scaled 2 rotated 45 shifted center Page;
draw thetextext("\green\headtextcontent",origin) scaled 1 rotated 45 shifted center Page;
% your own stuffz with chapter titles and numbers
setbounds currentpicture to p;
StopPage;
\stopuseMPgraphic

\startsetups set:chaptertitle
\startMPpage[height=max]
\includeMPgraphic{chaptertitle}
\stopMPpage
\stopsetups

\defineheadalternative[ChapterTitle][renderingsetup=set:chaptertitle]

\setuphead[chapter][margin=-\backspace,alternative=ChapterTitle]

\starttext
\startchapter[title={A chapter}]
\input ward
\stopchapter
\startchapter[title={Another chapter}]
\input tufte
\stopchapter
\startchapter[title={Another chapter}]
\input knuth
\stopchapter
\stoptext

由此产生了如下结果:

MWE 的输出

在对它进行了大量修改后,我发现 OP MWE 中最左边的间隙与退格尺寸相同,因此设置

\setuphead[章节][边距=-\backspace]

摆脱了它们。这没什么大不了的,但我认为没有必要。为了消除顶部间隙,我发现\startMPpage继承\setupframed属性,所以在对其进行了大量修改之后,我发现设置height=max几乎正好位于顶部边界。

经过几个小时的头痛和反复的尝试,我发现 MetaPost/MetaFun 的PaperWidth\the\paperwidth(和PaperHeight或) 输出的尺寸似乎与 ConTeXt 的(和)\the\paperheight输出的尺寸不完全相同。因此,如果我将绘图的尺寸设置为\paperwidth\paperheight

p := unitsquare xyscaled(PaperWidth, PaperHeight);

p := unitsquare xyscaled(52mm, 74mm); % those being the dimensions of A8 paper size

顶部的小缝隙消失了。

结语

我仍然认为在这种情况下不需要这些东西,而我得到的结果更多的是 ConTeXt 在这个特定场景中相当不直观的行为(或错误)的产物\setuphead[chapter][margin=-\backspace]height=max

更新

自从我最初发布这个问题以来,我对此进行了一些摆弄,弄清楚了如何将新布局与化妆设置结合起来,并将其用作包含图形的页面 - 因此不再需要[height=max]和黑客了:margin=-\backspace

\showframe
\setuppapersize[A8][A5,landscape]
\setuppaper[nx=4,ny=2]
\setuplayout[page][location=middle,marking=on]
\definelayout[chapter][margindistance=\zeropoint,edgedistance=\zeropoint,backspace=\zeropoint,top=\zeropoint,topspace=\zeropoint,header=\zeropoint,headerdistance=\zeropoint]% ...basically making the textarea fill the whole page
\definemakeup[chapter][pagestate=start]
\setuparranging[XY]

\setupbodyfont[8pt]

\startuseMPgraphic{chaptertitle}
StartPage;
path p;
p := unitsquare xyscaled(52mm, 74mm);
fill p withcolor red;
draw thetextext("\blue\headnumbercontent",origin) scaled 2 rotated 45 shifted center Page;
draw thetextext("\green\headtextcontent",origin) scaled 1 rotated 45 shifted center Page;
% your own stuffz with chapter titles and numbers
setbounds currentpicture to p;
StopPage;
\stopuseMPgraphic

\startsetups set:chaptertitle
\startMPpage
\includeMPgraphic{chaptertitle}
\stopMPpage
\stopsetups

\defineheadalternative[ChapterTitle][renderingsetup=set:chaptertitle]

\setuphead[chapter][alternative=ChapterTitle,before={\startmakeup[chapter]},after={\stopmakeup}]

\starttext
\startchapter[title={A chapter}]
\input ward
\stopchapter
\startchapter[title={Another chapter}]
\input tufte
\stopchapter
\startchapter[title={Another chapter}]
\input knuth
\stopchapter
\stoptext

另外,发现grid=yes由于某种原因,设置会干扰图形的垂直位置,因此对于新的布局,最好使用 进行设置grid=no

相关内容