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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
if not modules then modules = { } end modules ['typo-par'] = {
version = 1.001,
comment = "companion to node-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
-- Just some experimental stuff .. trying to improve some ancient metafun manual
-- hackery that has been on the angenda for too long already. Names might names
-- anyway.
local insert, remove = table.insert, table.remove
local texget = tex.get
local texset = tex.set
local shiftparshape = tex.shiftparshape
local sequencers = utilities.sequencers
local appendaction = sequencers.appendaction
local enableaction = sequencers.enableaction
local disableaction = sequencers.disableaction
local stack = { }
local top = nil
local enabled = false
interfaces.implement {
name = "pushparagraphtweak",
public = true,
protected = true,
arguments = "string",
actions = function(t)
insert(stack,top)
if not top then
enableaction("paragraphcontext","builders.checkparcontext")
enabled = true
end
top = t
end
}
interfaces.implement {
name = "popparagraphtweak",
public = true,
protected = true,
actions = function()
top = remove(stack)
if not top then
disableaction("paragraphcontext","builders.checkparcontext")
enabled = false
end
end
}
function builders.checkparcontext(where)
if top and where == "normal" then
if top == "cycle" then
local s = texget("parshape",true)
if s then
local p = texget("prevgraf")
while p > s do
p = p - s
end
shiftparshape(p,true)
end
return true
elseif top == "shift" then
shiftparshape(texget("prevgraf"))
return true
end
end
end
appendaction("paragraphcontext","system","builders.checkparcontext")
-- Another experiment: continuing parshapes with alternative definitions:
--
-- left d | right d | left d right d | both d | left d hsize d |
-- copy n | reset | repeat | done
do
local scanners = tokens.scanners
local scanword = scanners.word
local scandimen = scanners.dimen
local scancardinal = scanners.cardinal
interfaces.implement {
name = "setparagraphshape",
protected = true,
actions = function()
local t = { }
local n = 0
local h = texget("hsize")
while true do
local key = scanword()
::AGAIN::
if key == "left" then
local l = scandimen()
key = scanword()
if key == "right" then
n = n + 1 ; t[n] = { l, h - l - scandimen() }
elseif key == "hsize" then
n = n + 1 ; t[n] = { l, scandimen() }
else
n = n + 1 ; t[n] = { l, h }
goto AGAIN
end
elseif key == "right" then
n = n + 1 ; t[n] = { 0, h - scandimen() }
elseif key == "both" then
local b = scandimen()
n = n + 1 ; t[n] = { b, h - b - b }
elseif key == "copy" then
local c = scancardinal()
for i=1,c do
local m = n + 1
t[m] = t[n]
n = m
end
elseif key == "done" then
-- in case the user ended with "done"
scanword()
break
elseif key == "repeat" then
t["repeat"] = true
elseif key == "reset" then
n = n + 1 ; t[n] = { 0, h }
break
else
logs.report("system","bad key %a in paragraphshape",key)
break
end
end
texset("parshape",t)
end,
}
local NC = context.NC
local NR = context.NR
local VL = context.VL
interfaces.implement {
name = "showparagraphshape",
protected = true,
public = true,
actions = function()
local p = texget("parshape")
if p then
-- only english interface (for now)
context.inleftmargin(
{
align = "flushright",
strut = "no",
width = "0pt",
-- voffset = "-\\lineheight"
}, function()
context.starttabulate {
before = "",
after = "",
unit = "2pt",
rulethickness = ".1pt",
format = "|rb{\\smallinfofont}|lb{\\smallinfofont}|"
}
for i=1,#p do
NC() context("%P",p[i][1])
VL() context("%P",p[i][2])
NC() NR()
end
context.stoptabulate()
end
)
end
end
}
end
|