我是 ConTeXt 的新用户,用于编写课程。我编写了一个命令来生成标题页。我想传递一些可选参数。
%#1 is used for cover color,
%#2 is used for changing color of title
%#3 is for title
%#4 is for author name
%#5 is optional - for rotating title (0-90-270 degree)
%#6 is optional - for displaying an image centered on page
\def\TitlePage[#1][#2]#3#4#5#6
{
\definelayout[cover][backspace=10mm,topspace=25mm,width=19cm,height=27cm]
\definelayer[site2][x=10mm, y=10mm, width=\paperwidth, height=\paperheight]
\definelayer[site][x=60mm, y=10mm, width=\paperwidth, height=\paperheight, corner={top,right}]
\definelayer[logo][x=.5\paperwidth-2.5cm, y=.5\paperheight-2.5cm, width=5cm, height=5cm]
\definefont[BigFont][SansBold at 60pt]
\definefont[MedFont][SansBold at 30pt]
\definefont[SmallFont][SansBold at 14pt]
\definecolor[bkg][{#1}]
\definecolor[Gray][s=#2]
\setlayer[site2]{\externalfigure[logo2.png][width=5cm]}
\setlayer[site]{\externalfigure[logo.png][width=5cm]}
\ifcase#6\relax
\setlayer[logo]{\externalfigure[{#6}] [width=5cm, height=5cm]}
\fi
\setupbackgrounds[page][background={color,site,site2,logo},backgroundcolor=bkg]
\startstandardmakeup
\dontcomplain
\BigFont \setupinterlinespace \vfill \setupalign[left] \let\\=\par
\ifcase#5\relax
\noindent\color[Gray]{#3}\par
\else
\noindent\rotate[rotation=#5]{\color[Gray]{#3}}\par
\fi
\SmallFont\color[Gray]{#4}
\stopstandardmakeup
\setupbackgrounds[page][background=]
\setuplayout[reset]
}
在我的文档中,我想写
\TitlePage[r=.5, g=.5, b=.5][.45]{Title of course}{Author}{90}{python.png}
或者
\TitlePage[r=.5, g=.5, b=.5][.45]{Title of course}{Author}{}{python.png}
或者
\TitlePage[r=.5, g=.5, b=.5][.45]{Title of course}{Author}{90}{}
或者
\TitlePage[r=.5, g=.5, b=.5][.45]{Title of course}{Author}{}{}
但只有第一个会起作用(如果我删除 \ifcase 命令)有人能帮助我吗?谢谢!(抱歉我的英语不好 :( )
答案1
这实际上不是问题的答案,但 ConTeXt 执行此类操作的方式是使用键和值。在这里,我使用 定义一组键,\setvariables
并使用 检索值\getvariable
。这使得界面更加简洁,并允许您轻松为所有值指定合理的默认值。
% Add default to the set of locations to get access to ConTeXt's beautiful
% sample pictures
\setupexternalfigures[location={default,local,global}]
\definelayout
[cover]
[backspace=10mm,
topspace=25mm,
width=19cm,
height=27cm]
\definelayer
[site2]
[x=10mm,
y=10mm,
width=\paperwidth,
height=\paperheight]
\definelayer
[site]
[x=60mm,
y=10mm,
width=\paperwidth,
height=\paperheight,
corner={top,right}]
\definelayer
[logo]
[x=.5\paperwidth-2.5cm,
y=.5\paperheight-2.5cm,
width=5cm,
height=5cm]
\definefont[BigFont][SansBold at 60pt]
\definefont[MedFont][SansBold at 30pt]
\definefont[SmallFont][SansBold at 14pt]
% Defaults for the title page
\setlayer[site2]{\externalfigure[hacker.jpg][width=5cm]}
\setlayer[site]{\externalfigure[mill.png][width=5cm]}
\setvariables
[TitlePage]
[color={r=.5, g=.5, b=.5},
gray={.45},
title={oeps},
author={oeps},
rotate={0},
image={}]
% typesetting the title page
\unexpanded\def\TitlePage{\dosingleempty\doTitlePage}
\def\doTitlePage[#1]{%
\setvariables[TitlePage][#1]%
%
\edef\TitlePageColor{\getvariable{TitlePage}{color}}%
\edef\TitlePageGray{\getvariable{TitlePage}{gray}}%
\edef\TitlePageRotate{\getvariable{TitlePage}{rotate}}%
\edef\TitlePageImage{\getvariable{TitlePage}{image}}%
%
\expanded{\definecolor[bkg][\TitlePageColor]}%
\expanded{\definecolor[Gray][s=\TitlePageGray]}%
%
\doifsomething{\TitlePageImage}{%
\setlayer[logo]{\externalfigure[\TitlePageImage][width=5cm, height=5cm]}%
}%
%
\setupbackgrounds
[page]
[background={color,site,site2,logo},
backgroundcolor=bkg]%
%
\startstandardmakeup
\dontcomplain
\BigFont\setupinterlinespace
\setupalign[left]
\let\\=\par
\noindent\rotate[rotation=\TitlePageRotate]{\color[Gray]{\getvariable{TitlePage}{title}}}\par
\SmallFont\color[Gray]{\getvariable{TitlePage}{author}}
\stopstandardmakeup
%
\setupbackgrounds[page][background=]
\setuplayout[reset]
}
\starttext
\TitlePage
[color={r=.5, g=.5, b=.5},
gray=.45,
title={Title of course},
author={Author},
rotate=90,
image={cow.pdf}]
\stoptext
答案2
谢谢!我正在尝试将 ConTeXt 与 wiki 结合使用,但它在某些方面有点过时了。我为此更改了我的宏
\doifsomething{#6}
{
\setlayer[logo]{\externalfigure[{#6}] [width=5cm, height=5cm]}
}
和
\doifnumberelse{#5}
{
\noindent\rotate[rotation=#5]{\color[Gray]{#3}}\par
}
{
\noindent\color[Gray]{#3}\par
}
现在它开始工作了!
多谢你们 !