跳转至

ConTeXt rule学习笔记

欢迎加入本人建的"LuaTeX ConTeXt 学习互助"群:431714622,互助学习LuaTeX ConTeXt LaTeX相关技术,以及通过Lua、Python实现格式化文本、数据的自动排版。

本文主要是学习HANS HAGEN的RULES: A CONTEXT MKIV MANUAL的笔记,讲的是与文本紧密捆绑的一类条线(rule),可以制作紧随文本的画线、符号、图案等

文本画线#

参考:

在lua中,文本画线bar的rule当是在shipouts类的nodes.rules.handler中注入的,在字模结点后(其前有禁止断行的罚点)。

图形定义#

1
2
3
4
5
6
7
8
\startuseMPgraphic{rules:under:...}
draw
    ((0,RuleDepth) -- (RuleWidth,RuleDepth))
    shifted (0,RuleFactor*RuleOffset)
    withpen pencircle scaled RuleThickness
    withcolor RuleColor ;
setbounds currentpicture to unitsquare xysized(RuleWidth,RuleHeight) ;
\stopuseMPgraphic
variable type meaning
RuleDirection string 线条方向
RuleOption string 回调发现能用的任何东西
RuleWidth number 条线请求的宽度
RuleHeight number 条线请求的高度
RuleDepth number 条线请求的深度
RuleThickness number 线条宽度
RuleFactor number 条线设置的因子/倍数(e.g. an ex)
RuleOffset number 嵌套时(可选的)偏置量
RuleColor color 颜色

RuleFactor可用作RuleOffset的乘数。

用文字代替图形#

\definebar[xbarone][text=\lower\exheight\hbox{\darkred \infofont .}, repeat=yes] \definebar[xbartwo][text=\lower\exheight\hbox{\darkblue\infofont .}, repeat=yes, continue=yes] % 波浪线 \definebar[xbartwo][text=\lower\exheight\hbox{\blue\infofont \rotate[rotation=-10]{\textasciitilde}}, repeat=yes, continue=yes]

Klein: \xbarone{\samplefile{klein}\removeunwantedspaces}\par

Sapolsky : \xbartwo{\samplefile{sapolsky}\removeunwantedspaces}\par

变换#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
% 上标
\defineshift
[shiftup]
[method=0,
dy=-1,
unit=ex,
continue=yes,
style=\txx]

% 下标
\defineshift
[shiftdown]
[method=1,
dy=.3,
unit=ex,
continue=yes,
style=\txx,
color=]

filler 填充器#

在行首、行尾的空白处填充rule。

  • \definelinefiller
  • \setuplinefiller
  • \startlinefiller...\stoplinefiller

使用条线rule#

TEX认识的图形元素只有字符和条线。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
hrule{\darkred\hrule width 10cm height 3mm depth 2mm}\par
vrule{\darkred\vrule width 10cm height 3mm depth 2mm}\par
hrule{\darkred\hrule width 10cm}\par
vrule{\darkred\vrule height 3mm depth 2mm}\par
hrule{\darkred\leaders\hrule height 1mm\relax\hfill}hrule\par

% 方框条线
\color[darkred]{\frule
    width 10cm
    height 1cm
    line  1mm
\relax}

% 圆角框横盒子
\ruledhbox\bgroup
    \darkgray
    \frule width 100mm height 10mm depth 8mm radius 2mm line 2pt type fill\relax
    \hskip-100mm
    \darkred
    \frule width 100mm height 10mm depth 8mm radius 2mm line 2pt\relax
    \hskip-100mm
    \hbox to 100mm{\white \bold \hfill some handy word with frames\hfill}%
\egroup

% 椭圆框横盒子(使用MetaPost)
\startuseMPgraphic{demoshape:back}
fill
    unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
    withcolor RuleColor ;
\stopuseMPgraphic

\startuseMPgraphic{demoshape:fore}
draw
    unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
    withcolor RuleColor
    withpen pencircle scaled 4RuleThickness ;
\stopuseMPgraphic

\hbox\bgroup
    \darkgray \frule width 100mm height 10mm depth 8mm type mp line 2pt
    data {\includeMPgraphic{demoshape:back}}
    \relax
    \hskip-100mm
    \darkred \frule width 100mm height 10mm depth 8mm type mp line 2pt
    data {\includeMPgraphic{demoshape:fore}}
    \relax
    \hskip-100mm
    \hbox to 100mm{\white \bold \hfill some handy word with frames\hfill}
\egroup

% 黑条线
% \setupblackrules
\blackrule
[width=10cm,
height=1cm,
depth=1cm,
color=darkred]

% 黑条线(使用MetaPost)
\blackrule
[width=10cm,
height=1cm,
depth=1cm,
color=darkred,
type=mp,
mp=demoshape:back]

隐藏文本#

可制作完型填空。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
\definebar
    [hiddenbar] [underbar]
    [continue=yes,empty=yes,
    left=\zwj,right=\zwj]

\definebar
    [widehiddenbar]
    [hiddenbar]
    [left={\quads[3]},
    right={\quads[3]}]

表格化#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
% \setuptabulate
\starttabulate
    \NL[darkred]
    foo \NC bar \NC \NR
    \NL[darkgreen]
    foo \NC bar \NC \NR
    \NL[darkblue]
    foo \NC \samplefile{tufte} \NC \NR
    \NL[darkgray]
    foo \NC bar \NC \NR
    \NL[darkyellow] foo \NC bar \NC \NR
    \LL
\stoptabulate

评论