luatex-style.tex /size: 10 Kb    last modification: 2021-10-28 13:50
1% language=us engine=luatex runpath=texruns:manuals/luatex
2
3\startenvironment luatex-style
4
5% todo: use \useMPlibrary[lua]
6
7\enabletrackers[fonts.usage]
8
9\usemodule[fonts-statistics]
10
11\setuplayout
12  [height=middle,
13   width=middle,
14   backspace=2cm,
15   topspace=10mm,
16   bottomspace=10mm,
17   header=10mm,
18   footer=10mm,
19   footerdistance=10mm,
20   headerdistance=10mm]
21
22\setuppagenumbering
23  [alternative=doublesided]
24
25\setuptolerance
26  [stretch,tolerant]
27
28\setuptype
29  [lines=hyphenated]
30
31\setuptyping
32  [lines=hyphenated]
33
34\setupitemize
35  [each]
36  [packed]
37
38\definesymbol[1][\Uchar"2023]
39\definesymbol[2][\endash]
40\definesymbol[3][\wait]      % we want to catch it
41
42\setupitemize
43  [each]
44  [headcolor=maincolor,
45   symbolcolor=maincolor,
46   color=maincolor]
47
48\setupwhitespace
49  [medium]
50
51\setuptabulate
52  [blank={small,samepage},
53   headstyle=bold,
54   rulecolor=maincolor,
55   rulethickness=1pt,
56   foregroundcolor=white,
57   foregroundstyle=\ss\bfx\WORD,
58   backgroundcolor=maincolor]
59
60\setupcaptions
61  [headcolor=darkblue]
62
63\startluacode
64    local skipped = table.tohash { 'id', 'subtype', 'next', 'prev' }
65
66    function document.functions.showfields(s)
67        local t = string.split(s,',')
68        local f = node.fields(t[1],t[2])
69        if f then
70            local d = false
71            for i=1,#f do
72                local fi = f[i]
73                if skipped[fi] then
74                    -- okay
75                elseif d then
76                    context(', {\tttf %s}', fi)
77                else
78                    context('{\tttf %s}', fi)
79                    d = true
80                end
81            end
82        end
83    end
84
85    function document.functions.showid(s)
86        local t = string.split(s,',')
87        context('{tttf %s}',node.id(t[1]))
88        if t[2] then
89            context(', {tttf %s}',node.subtype(t[2]))
90        end
91    end
92
93    function document.functions.showsubtypes(s)
94        local s = node.subtypes(s)
95        local d = false
96        for k, v in table.sortedhash(s) do
97            if d then
98                context(', %s = {\\tttf %s}',k,v)
99            else
100                context('%s = {\\tttf %s}',k,v)
101                d = true
102            end
103        end
104    end
105\stopluacode
106
107\unexpanded\def\showfields  #1{\ctxlua{document.functions.showfields("#1")}}
108\unexpanded\def\showid      #1{\ctxlua{document.functions.showid("#1")}}
109\unexpanded\def\showsubtypes#1{\ctxlua{document.functions.showsubtypes("#1")}}
110
111\definecolor[blue]      [b=.5]
112\definecolor[red]       [r=.5]
113\definecolor[green]     [g=.5]
114\definecolor[maincolor] [b=.5]
115\definecolor[keptcolor] [b=.5]
116\definecolor[othercolor][r=.5,g=.5]
117
118\writestatus{luatex manual}{}
119\writestatus{luatex manual}{defining lucodaot} \usebodyfont  [lucidaot]
120\writestatus{luatex manual}{defining pagella}  \usebodyfont  [pagella]
121\writestatus{luatex manual}{defining cambria}  \usebodyfont  [cambria]
122\writestatus{luatex manual}{defining modern}   \usebodyfont  [modern]
123\writestatus{luatex manual}{defining dejavu}   \setupbodyfont[dejavu,10pt]
124\writestatus{luatex manual}{}
125
126\setuphead [chapter]      [align={flushleft,broad},style=\bfd]
127\setuphead [section]      [align={flushleft,broad},style=\bfb]
128\setuphead [subsection]   [align={flushleft,broad},style=\bfa]
129\setuphead [subsubsection][align={flushleft,broad},style=\bf]
130
131\setuphead [chapter]      [color=maincolor]
132\setuphead [section]      [color=maincolor]
133\setuphead [subsection]   [color=maincolor]
134\setuphead [subsubsection][color=maincolor]
135
136\setupfloats
137  [ntop=4]
138
139\definehead
140  [remark]
141  [subsubsubject]
142
143\setupheadertexts
144  []
145
146% \setuplayout
147%   [style=bold,
148%    color=maincolor]
149
150\definemixedcolumns
151  [twocolumns]
152  [n=2,
153   balance=yes,
154   before=\blank,
155   after=\blank]
156
157\definemixedcolumns
158  [threecolumns]
159  [twocolumns]
160  [n=3]
161
162\definemixedcolumns
163  [fourcolumns]
164  [threecolumns]
165  [n=4]
166
167% if we do this we also need to do it in table cells
168%
169% \setuptyping
170%   [color=maincolor]
171%
172% \setuptype
173%   [color=maincolor]
174
175\definetyping
176  [functioncall]
177
178\startMPdefinitions
179
180    color   luaplanetcolor ; luaplanetcolor := \MPcolor{maincolor} ;
181    color   luaholecolor   ; luaholecolor   := white ;
182    numeric luaextraangle  ; luaextraangle  := 0 ;
183    numeric luaorbitfactor ; luaorbitfactor := .25 ;
184
185    vardef lualogo = image (
186
187        % Graphic design by A. Nakonechnyj. Copyright (c) 1998, All rights reserved.
188
189        save d, r, p ; numeric d, r, p ;
190
191        d := sqrt(2)/4 ; r := 1/4 ; p := r/8 ;
192
193        fill fullcircle scaled 1
194            withcolor luaplanetcolor ;
195        draw fullcircle rotated 40.5 scaled (1+r)
196            dashed evenly scaled p
197            withpen pencircle scaled (p/2)
198            withcolor (luaorbitfactor * luaholecolor) ;
199        fill fullcircle scaled r shifted (d+1/8,d+1/8)
200            rotated - luaextraangle
201            withcolor luaplanetcolor ;
202        fill fullcircle scaled r shifted (d-1/8,d-1/8)
203            withcolor luaholecolor   ;
204        luaorbitfactor := .25 ;
205    ) enddef ;
206
207\stopMPdefinitions
208
209\startuseMPgraphic{luapage}
210    StartPage ;
211
212        fill Page withcolor \MPcolor{othercolor} ;
213
214        luaorbitfactor := 1 ;
215
216        picture p ; p := lualogo ysized (5*\measure{paperheight}/10) ;
217        draw p
218            shifted - center p
219            shifted (
220                \measure{spreadwidth} - .5*\measure{paperwidth} + \measure{spinewidth},
221                .375*\measure{paperheight}
222            )
223        ;
224
225    StopPage ;
226\stopuseMPgraphic
227
228% \starttexdefinition luaextraangle
229%     % we can also just access the last page and so in mp directly
230%     \ctxlua {
231%         context(\lastpage == 0 and 0 or \realfolio*360/\lastpage)
232%     }
233% \stoptexdefinition
234
235\startuseMPgraphic{luanumber}
236  % luaextraangle  := \luaextraangle;
237    luaextraangle  := if (LastPageNumber < 10) : 10 else : (RealPageNumber / LastPageNumber) * 360  fi;
238    luaorbitfactor := 0.25 ;
239    picture p ; p := lualogo ;
240    setbounds p to boundingbox fullcircle ;
241    draw p ysized 1cm ;
242\stopuseMPgraphic
243
244\definelayer
245  [page]
246  [width=\paperwidth,
247   height=\paperheight]
248
249\setupbackgrounds
250  [leftpage]
251  [background=page]
252
253\setupbackgrounds
254  [rightpage]
255  [background=page]
256
257\definemeasure[banneroffset][\bottomspace-\footerheight-\footerdistance+2cm]
258
259\startsetups pagenumber:right
260  \setlayerframed
261    [page]
262    [preset=rightbottom,x=1.0cm,y=\measure{banneroffset}]
263    [frame=off,height=1cm,offset=overlay]
264    {\strut\useMPgraphic{luanumber}}
265  \setlayerframed
266    [page]
267    [preset=rightbottom,x=2.5cm,y=\measure{banneroffset}]
268    [frame=off,height=1cm,width=1cm,offset=overlay,
269     foregroundstyle=bold,foregroundcolor=maincolor]
270    {\strut\pagenumber}
271  \setlayerframed
272    [page]
273    [preset=rightbottom,x=3.5cm,y=\measure{banneroffset}]
274    [frame=off,height=1cm,offset=overlay,
275     foregroundstyle=bold,foregroundcolor=maincolor]
276    {\strut\getmarking[chapter]}
277\stopsetups
278
279\startsetups pagenumber:left
280  \setlayerframed
281    [page]
282    [preset=leftbottom,x=3.5cm,y=\measure{banneroffset}]
283    [frame=off,height=1cm,offset=overlay,
284     foregroundstyle=bold,foregroundcolor=maincolor]
285    {\strut\getmarking[chapter]}
286  \setlayerframed
287    [page]
288    [preset=leftbottom,x=2.5cm,y=\measure{banneroffset}]
289    [frame=off,height=1cm,width=1cm,offset=overlay,
290     foregroundstyle=bold,foregroundcolor=maincolor]
291    {\strut\pagenumber}
292  \setlayerframed
293    [page]
294    [preset=leftbottom,x=1.0cm,y=\measure{banneroffset}]
295    [frame=off,height=1cm,offset=overlay]
296    {\strut\useMPgraphic{luanumber}}
297\stopsetups
298
299\unexpanded\def\nonterminal#1>{\mathematics{\langle\hbox{\rm #1}\rangle}}
300
301% taco's brainwave -) .. todo: create a typing variant so that we can avoid the !crlf
302
303\newcatcodetable\syntaxcodetable
304
305\unexpanded\def\makesyntaxcodetable
306  {\begingroup
307   \catcode`\<=13 \catcode`\|=12
308   \catcode`\!= 0 \catcode`\\=12
309   \savecatcodetable\syntaxcodetable
310   \endgroup}
311
312\makesyntaxcodetable
313
314\unexpanded\def\startsyntax {\begingroup\catcodetable\syntaxcodetable  \dostartsyntax}
315\unexpanded\def\syntax      {\begingroup\catcodetable\syntaxcodetable  \dosyntax}
316           \let\stopsyntax   \relax
317
318\unexpanded\def\syntaxenvbody#1%
319  {\par
320   \tt
321   \startnarrower
322 % \maincolor
323   #1
324   \stopnarrower
325   \par}
326
327\unexpanded\def\syntaxbody#1%
328  {\begingroup
329 % \maincolor
330   \tt #1%
331   \endgroup}
332
333\bgroup \catcodetable\syntaxcodetable
334
335!gdef!dostartsyntax#1\stopsyntax{!let<!nonterminal!syntaxenvbody{#1}!endgroup}
336!gdef!dosyntax     #1{!let<!nonterminal!syntaxbody{#1}!endgroup}
337
338!egroup
339
340\definetyping
341  [texsyntax]
342% [color=maincolor]
343
344% end of wave
345
346\setupinteraction
347  [state=start,
348   focus=standard,
349   style=,
350   color=,
351   contrastcolor=]
352
353\placebookmarks
354  [chapter,section,subsection]
355
356\setuplist
357  [chapter,section,subsection,subsubsection]
358  [interaction=all,
359   width=3em]
360
361\setuplist
362  [chapter]
363  [style=bold,
364   before={\testpage[4]\blank},
365   color=keptcolor]
366
367\setuplist
368  [section]
369  [before={\testpage[3]}]
370
371\setuplist
372  [subsection,subsubsection]
373  [margin=3em,
374   width=5em]
375
376\definestartstop
377  [notabene]
378  [style=slanted]
379
380\definestartstop
381  [preamble]
382  [style=normal,
383   before=\blank,
384   after=\blank]
385
386% Hans doesn't like the bookmarks opening by default so we comment this:
387%
388% \setupinteractionscreen
389%   [option=bookmark]
390
391\startbuffer[stylecalculations]
392
393    \normalexpanded{\definemeasure[spinewidth] [0pt]}
394    \normalexpanded{\definemeasure[paperwidth] [\the\paperwidth ]}
395    \normalexpanded{\definemeasure[paperheight][\the\paperheight]}
396    \normalexpanded{\definemeasure[spreadwidth][\measure{paperwidth}]}
397
398\stopbuffer
399
400\getbuffer[stylecalculations]
401
402\dontcomplain
403
404\environment luatex-logos
405
406\defineregister[topicindex]
407\defineregister[primitiveindex]
408\defineregister[callbackindex]
409\defineregister[nodeindex]
410\defineregister[libraryindex]
411
412\unexpanded\def\lpr#1{\doifmode{*bodypart}{\primitiveindex[#1]{\bf\tex {#1}}}\tex {#1}}
413\unexpanded\def\prm#1{\doifmode{*bodypart}{\primitiveindex[#1]{\tex    {#1}}}\tex {#1}}
414\unexpanded\def\orm#1{\doifmode{*bodypart}{\primitiveindex[#1]{\tex    {#1}}}\tex {#1}}
415\unexpanded\def\cbk#1{\doifmode{*bodypart}{\callbackindex [#1]{\type   {#1}}}\type{#1}}
416\unexpanded\def\nod#1{\doifmode{*bodypart}{\nodeindex     [#1]{\bf\type{#1}}}\type{#1}}
417\unexpanded\def\whs#1{\doifmode{*bodypart}{\nodeindex     [#1]{\type   {#1}}}\type{#1}}
418\unexpanded\def\noa#1{\doifmode{*bodypart}{\nodeindex     [#1]{\type   {#1}}}\type{#1}}
419
420\hyphenation{sub-nodes}
421
422\def\currentlibraryindex{\namedstructureuservariable{section}{library}}
423
424\setupregister
425  [libraryindex]
426  [indicator=no,before=]
427
428\setupregister
429  [libraryindex]
430  [1]
431  [textstyle=\ttbf]
432
433\setupregister
434  [libraryindex]
435  [2]
436  [textstyle=\tttf]
437
438\unexpanded\def\lib     #1{\doifmode{*bodypart}{\expanded{\libraryindex{\currentlibraryindex+#1}}\type{\currentlibraryindex.#1}}}
439\unexpanded\def\libindex#1{\doifmode{*bodypart}{\expanded{\libraryindex{\currentlibraryindex+#1}}}}
440\unexpanded\def\libidx#1#2{\doifmode{*bodypart}{\expanded{\libraryindex{#1+#2}}\type{#1.#2}}}
441\unexpanded\def\lix   #1#2{\doifmode{*bodypart}{\expanded{\libraryindex{#1+#2}}}}
442
443% \setstructurepageregister[][keys:1=,entries:1=]
444
445\stopenvironment
446