another update to the manual (+ some cleanup in libs) (HH)
[luatex.git] / manual / luatex-style.tex
blob7ac0267470f31ec0f4ef5231e4eff9445409a2b3
1 \startenvironment luatex-style
3 \usemodule[abr-02]
5 \setuplayout
6 [height=middle,
7 width=middle,
8 backspace=2cm,
9 topspace=10mm,
10 bottomspace=10mm,
11 header=10mm,
12 footer=10mm,
13 footerdistance=10mm,
14 headerdistance=10mm]
16 \setuppagenumbering
17 [alternative=doublesided]
19 \setuptolerance
20 [stretch,tolerant]
22 \setuptype
23 [lines=hyphenated]
25 \setuptyping
26 [lines=hyphenated]
28 \setupitemize
29 [each]
30 [packed]
32 \setupwhitespace
33 [medium]
35 \startluacode
36 local skipped = table.tohash { 'id', 'subtype', 'next', 'prev' }
38 function document.functions.showfields(s)
39 local t = string.split(s,',')
40 local r = { }
41 for _, a in pairs(node.fields(t[1],t[2])) do
42 if not skipped[a] then
43 table.insert(r,'\\type{'.. a .. '}')
44 end
45 end
46 tex.sprint(table.concat(r, ', '))
47 end
49 function document.functions.showid(s)
50 local t = string.split(s,',')
51 tex.sprint('\\type{'.. node.id(t[1]) .. '}')
52 if t[2] then
53 tex.sprint(', \\type{'.. node.subtype(t[2]) .. '}')
54 end
55 end
57 function document.functions.showsubtypes(s)
58 local s = node.subtypes(s)
59 local d = false
60 for k, v in table.sortedhash(s) do
61 if d then
62 context(', %s = {\\tttf %s}',k,v)
63 else
64 context('%s = {\\tttf %s}',k,v)
65 d = true
66 end
67 end
68 end
69 \stopluacode
71 \unexpanded\def\showfields #1{\ctxlua{document.functions.showfields("#1")}}
72 \unexpanded\def\showid #1{\ctxlua{document.functions.showid("#1")}}
73 \unexpanded\def\showsubtypes#1{\ctxlua{document.functions.showsubtypes("#1")}}
75 \definecolor[blue] [b=.5]
76 \definecolor[red] [r=.5]
77 \definecolor[green] [g=.5]
78 \definecolor[maincolor] [b=.5]
79 \definecolor[keptcolor] [b=.5]
80 \definecolor[othercolor][r=.5,g=.5]
82 \setupbodyfont[modern] % we need this in examples so we predefine
84 % \doifmodeelse {atpragma} {
86 % % \setupbodyfont
87 % % [lucidaot,10pt]
89 % \setupbodyfont
90 % [dejavu,10pt]
92 % \setuphead [chapter] [style=\bfd]
93 % \setuphead [section] [style=\bfb]
94 % \setuphead [subsection] [style=\bfa]
95 % \setuphead [subsubsection][style=\bf]
97 % } {
99 % \definetypeface[mainfacenormal] [ss][sans] [iwona] [default]
100 % \definetypeface[mainfacenormal] [rm][serif][palatino] [default]
101 % \definetypeface[mainfacenormal] [tt][mono] [modern] [default][rscale=1.1]
102 % \definetypeface[mainfacenormal] [mm][math] [iwona] [default]
104 % \definetypeface[mainfacemedium] [ss][sans] [iwona-medium][default]
105 % \definetypeface[mainfacemedium] [rm][serif][palatino] [default]
106 % \definetypeface[mainfacemedium] [tt][mono] [modern] [default][rscale=1.1]
107 % \definetypeface[mainfacemedium] [mm][math] [iwona-medium][default]
109 % \setupbodyfont
110 % [mainfacenormal,10pt]
112 % \setuphead [chapter] [style=\mainfacemedium\bfd]
113 % \setuphead [section] [style=\mainfacemedium\bfb]
114 % \setuphead [subsection] [style=\mainfacemedium\bfa]
115 % \setuphead [subsubsection][style=\mainfacemedium\bf]
119 \writestatus{luatex manual}{we assume that dejavu math is available}
121 \setupbodyfont % assumes dejavu-math
122 [dejavu,10pt]
124 \setuphead [chapter] [align={flushleft,broad},style=\bfd]
125 \setuphead [section] [align={flushleft,broad},style=\bfb]
126 \setuphead [subsection] [align={flushleft,broad},style=\bfa]
127 \setuphead [subsubsection][align={flushleft,broad},style=\bf]
129 \setuphead [chapter] [color=maincolor]
130 \setuphead [section] [color=maincolor]
131 \setuphead [subsection] [color=maincolor]
132 \setuphead [subsubsection][color=maincolor]
134 \definehead
135 [remark]
136 [subsubsubject]
138 \setupheadertexts
141 \definemixedcolumns
142 [twocolumns]
143 [n=2,
144 balance=yes,
145 before=\blank,
146 after=\blank]
148 \definemixedcolumns
149 [threecolumns]
150 [twocolumns]
151 [n=3]
153 \definemixedcolumns
154 [fourcolumns]
155 [threecolumns]
156 [n=4]
158 \setuptyping
159 [color=maincolor]
161 \setuptype
162 [color=maincolor]
164 \definetyping
165 [functioncall]
167 \startMPdefinitions
169 color luaplanetcolor ; luaplanetcolor := \MPcolor{maincolor} ;
170 color luaholecolor ; luaholecolor := white ;
171 numeric luaextraangle ; luaextraangle := 0 ;
172 numeric luaorbitfactor ; luaorbitfactor := .25 ;
174 vardef lualogo = image (
176 % Graphic design by A. Nakonechnyj. Copyright (c) 1998, All rights reserved.
178 save d, r, p ; numeric d, r, p ;
180 d := sqrt(2)/4 ; r := 1/4 ; p := r/8 ;
182 fill fullcircle scaled 1
183 withcolor luaplanetcolor ;
184 draw fullcircle rotated 40.5 scaled (1+r)
185 dashed evenly scaled p
186 withpen pencircle scaled (p/2)
187 withcolor (luaorbitfactor * luaholecolor) ;
188 fill fullcircle scaled r shifted (d+1/8,d+1/8)
189 rotated luaextraangle
190 withcolor luaplanetcolor ;
191 fill fullcircle scaled r shifted (d-1/8,d-1/8)
192 withcolor luaholecolor ;
193 luaorbitfactor := .25 ;
194 ) enddef ;
196 \stopMPdefinitions
198 \startuseMPgraphic{luapage}
199 StartPage ;
201 fill Page withcolor \MPcolor{othercolor} ;
203 luaorbitfactor := 1 ;
204 picture p ; p := lualogo xsized (3PaperWidth/5) ;
205 draw p shifted center Page shifted (0,-.5ypart center ulcorner p) ;
207 StopPage ;
208 \stopuseMPgraphic
210 \starttexdefinition luaextraangle
211 % we can also just access the last page and so in mp directly
212 \ctxlua {
213 context(\lastpage == 0 and 0 or \realfolio*360/\lastpage)
215 \stoptexdefinition
217 \startuseMPgraphic{luanumber}
218 luaextraangle := \luaextraangle;
219 luaorbitfactor := 0.25 ;
220 picture p ; p := lualogo ;
221 setbounds p to boundingbox fullcircle ;
222 draw p ysized 1cm ;
223 \stopuseMPgraphic
225 \definelayer
226 [page]
227 [width=\paperwidth,
228 height=\paperheight]
230 \setupbackgrounds
231 [leftpage]
232 [background=page]
234 \setupbackgrounds
235 [rightpage]
236 [background=page]
238 \startsetups pagenumber:right
239 \setlayerframed
240 [page]
241 [preset=rightbottom,offset=1cm]
242 [frame=off,height=1cm,offset=overlay]
243 {\useMPgraphic{luanumber}}
244 \setlayerframed
245 [page]
246 [preset=rightbottom,offset=1cm,x=1.5cm]
247 [frame=off,height=1cm,width=1cm,offset=overlay]
248 {\pagenumber}
249 \setlayerframed
250 [page]
251 [preset=rightbottom,offset=1cm,x=2.5cm]
252 [frame=off,height=1cm,offset=overlay]
253 {\getmarking[chapter]}
254 \stopsetups
256 \startsetups pagenumber:left
257 \setlayerframed
258 [page]
259 [preset=leftbottom,offset=1cm,x=2.5cm]
260 [frame=off,height=1cm,offset=overlay]
261 {\getmarking[chapter]}
262 \setlayerframed
263 [page]
264 [preset=leftbottom,offset=1cm,x=1.5cm]
265 [frame=off,height=1cm,width=1cm,offset=overlay]
266 {\pagenumber}
267 \setlayerframed
268 [page]
269 [preset=leftbottom,offset=1cm]
270 [frame=off,height=1cm,offset=overlay]
271 {\useMPgraphic{luanumber}}
272 \stopsetups
274 \unexpanded\def\nonterminal#1>{\mathematics{\langle\hbox{\rm #1}\rangle}}
276 % taco's brainwave -)
278 \newcatcodetable\syntaxcodetable
280 \unexpanded\def\makesyntaxcodetable
281 {\begingroup
282 \catcode`\<=13 \catcode`\|=12
283 \catcode`\!= 0 \catcode`\\=12
284 \savecatcodetable\syntaxcodetable
285 \endgroup}
287 \makesyntaxcodetable
289 \unexpanded\def\startsyntax {\begingroup\catcodetable\syntaxcodetable \dostartsyntax}
290 \unexpanded\def\syntax {\begingroup\catcodetable\syntaxcodetable \dosyntax}
291 \let\stopsyntax \relax
293 \unexpanded\def\syntaxenvbody#1%
294 {\par
296 \startnarrower
297 \maincolor #1
298 \stopnarrower
299 \par}
301 \unexpanded\def\syntaxbody#1%
302 {\begingroup
303 \maincolor \tt #1%
304 \endgroup}
306 \bgroup \catcodetable\syntaxcodetable
308 !gdef!dostartsyntax#1\stopsyntax{!let<!nonterminal!syntaxenvbody{#1}!endgroup}
309 !gdef!dosyntax #1{!let<!nonterminal!syntaxbody{#1}!endgroup}
311 !egroup
313 % end of wave
315 \setupinteraction
316 [state=start,
317 focus=standard,
318 style=,
319 color=,
320 contrastcolor=]
322 \placebookmarks
323 [chapter,section,subsection]
325 \setuplist
326 [chapter,section,subsection,subsubsection]
327 [interaction=all,
328 width=6em]
330 \setuplist
331 [chapter]
332 [style=bold,
333 color=keptcolor]
335 % Hans doesn't like the bookmarks opening by default so we comment this:
337 % \setupinteractionscreen
338 % [option=bookmark]
340 \stopenvironment