Debian Codegraph @

texmf-dist/source/luatex/lua-widow-control/lwc-manual.mkxl

raw
1 % lua-widow-control
2 % https://github.com/gucci-on-fleek/lua-widow-control
3 % SPDX-License-Identifier: MPL-2.0+
4 % SPDX-FileCopyrightText: 2022 Max Chernoff
5
6 \startenvironment[lwc-manual]
7 \unprotect
8
9 \mainlanguage[en]
10
11 %%%%%%%%%%%%%%%%%%%%%%%%%%
12 %%%%% Font Selection %%%%%
13 %%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 \startluacode
16 fonts.handlers.otf.addfeature {
17 name = "emdash_kern", -- Increase sidebearings on em-dash
18 type = "single",
19 data = {
20 ["—"] = { 100, 0, 200, 0 },
21 }
22 }
23 \stopluacode
24
25 \definefontfeature[default][default][
26 protrusion=quality,
27 expansion=quality,
28 onum=yes,
29 script=latn,
30 emdash_kern=yes,
31 trep=yes,
32 ]
33 \setupalign[hz, hanging]
34
35 \definefontfeature[lining][onum=no,lnum=yes]
36 \definefontfeature[allsmall][c2sc=yes, smcp=yes]
37 \define\lining{\feature[+][lining]}
38
39 \starttypescript[lwc-fonts]
40 \definetypeface[lwc-fonts] [rm] [serif][pagella] [default]
41 \definetypeface[lwc-fonts] [ss] [sans] [libertinus] [default] [rscale=1.07]
42 \definetypeface[lwc-fonts] [tt] [mono] [plex] [default] [rscale=0.89]
43 \definetypeface[lwc-fonts] [mm] [math] [pagella] [default]
44 \stoptypescript
45
46 \setupbodyfont[lwc-fonts, 11pt]
47
48 \setupbodyfontenvironment[default][em=italic]
49
50
51 %%%%%%%%%%%%%%%%%%%%%%%
52 %%%%% Page Layout %%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%
54
55 \setuppapersize[letter]
56
57 \setupindenting[yes, 3em]
58 \setupinterlinespace[2.75ex]
59
60 \input lang-frq.mkxl % For \averagecharwidth
61
62 \setuplayout[
63 width=75\averagecharwidth,
64 backspace=\dimexpr(\paperwidth - \makeupwidth) / 2,
65 topspace=\dimexpr\backspace - \headerheight,
66 footerdistance=3\baselineskip,
67 footer=\baselineskip,
68 height=8.75in,
69 margin=\dimexpr\backspace - \margindistance - 0.25cm,
70 ]
71
72 %%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%% PDF Settings %%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%
75
76 % PDF/UA
77 \setupbackend[format=PDF/UA-1]
78 \setupinteraction[state=start, focus=standard]
79 \setuptagging[state=start]
80 \setupstructure[state=start, method=auto]
81
82 % Bookmarks
83 \placebookmarks[section, subsection][section, subsection][number=no]
84 \setupinteractionscreen[option=bookmark]
85
86 %%%%%%%%%%%%%%%%%%%%%%
87 %%%%% Formatting %%%%%
88 %%%%%%%%%%%%%%%%%%%%%%
89
90 \setuppagenumbering[location=footer, style=\ss\lining]
91 \let\old@tex=\tex
92 \def\tex#1{\expandafter\old@tex\normalexpanded{{#1}}} % Allow expansion in the \tex macro (for \allowbreak)
93
94 % Acronym styling
95 \definecharacterkerning[acronymkerning][factor=0.05]
96 \definealternativestyle[acronymstyle][{\feature[+][allsmall]\switchtobodyfont[1.2em]\setcharacterkerning[acronymkerning]}][]
97 \definehighlight[acronym][style=acronymstyle]
98
99 \startsetups[commandtable]
100 \setupTABLE[frame=off]
101 \setupTABLE[column][first][roffset=1.5em]
102 \setupTABLE[row][first][toffset=0.25ex]
103 \stopsetups
104
105 \startsetups[booktabs]
106 \setupTABLE[each][each][frame=off]
107 \setupTABLE[row][first][topframe=on, rulethickness=1.2bp]
108 \setupTABLE[row][2] [topframe=on, rulethickness=0.6bp]
109 \setupTABLE[row][last] [bottomframe=on, rulethickness=1.2bp]
110 \setupTABLE[column][first][loffset=0.5em]
111 \setupTABLE[column][last][roffset=0.5em]
112 \stopsetups
113
114 \setupitemize[each][
115 style=\lining,
116 inbetween={\blank[quarterline]},
117 ]
118 \setupcaptions[
119 headstyle=\ssbf\lining,
120 style=\ss,
121 ]
122
123 \setupdelimitedtext[blockquote][
124 style=\ss,
125 before=\noindentation,
126 after={\blank[medium]}
127 ]
128
129 \define[1]\meta{\m{\langle}\italic{#1}\m{\rangle}}
130 \define[1]\githubissue{\goto{(Issue~\##1)}[url(https://github.com/gucci-on-fleek/lua-widow-control/issues/#1)]}
131
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 %%%%% Section Commands %%%%%
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
136 \definecharacterkerning[titlekern][factor=0.2]
137
138 \protected\def\interwordspace{\scaledfontdimen2\font}
139
140 % Section
141 \startsetups[style:section]
142 \setcharacterkerning[titlekern]
143 \switchtobodyfont[adventor]
144 \WORD
145 \bfb
146 \feature[+][allsmall]
147 \interwordspace=0.4em
148 \veryraggedcenter
149 \stopsetups
150
151 \setuphead[section][
152 before={\blank[big, preference]},
153 after={\blank[medium, samepage]},
154 textstyle=\setups{style:section},
155 number=no,
156 ]
157
158 % Subsection
159 \setuphead[subsection][
160 before={\blank[medium, preference]},
161 after=,
162 textstyle=\ss,
163 alternative=margintext,
164 number=no,
165 ]
166
167 % TOC
168 \def\secondleveltoc{subsection}
169 \starttexdefinition protected SectionTOCcommand #1#2#3
170 \startcurrentlistentrywrapper % Make the whole line a link
171 \midaligned{ % Have the title and page number "glued" to the middle
172 \llap{\currentlistentrytitle}
173 \hskip 1em
174 \rlap{\color[\interactionparameter{color}]{\bf \currentlistentrypagenumber}}
175 }
176 \stopcurrentlistentrywrapper
177
178 \par
179 \nobreak
180
181 \setbox0=\vbox{\framedtext[ % Align the subsection titles under the section title
182 frame=off,
183 width=\dimexpr\textwidth/2 - 0.5em,
184 align={flushright, wide},
185 offset=none,
186 toffset=-\lineheight,
187 ]{
188 \global\firstsubsectiontrue
189 \placelist[\secondleveltoc][criterium=local]
190 }}
191 \iffirstsubsection
192 \blank[quarterline] % No subsections here
193 \else
194 \box0
195 \fi
196
197 \goodbreak
198 \stoptexdefinition
199
200 \newif\iffirstsubsection
201
202 \define\tocspace{\hskip 0.5em plus 0.5em minus 0.2em\relax}
203
204 \unexpanded\def\toc_link#1{%
205 \startcurrentlistentrywrapper%
206 \hbox{#1}%
207 \stopcurrentlistentrywrapper%
208 }
209
210 \starttexdefinition protected SubsectionTOCcommand #1#2#3
211 \ss\itx
212 \dontleavehmode
213 \iffirstsubsection
214 \global\firstsubsectionfalse
215 \toc_link{#2}
216 \else
217 \discretionary{}{
218 \toc_link{#2} % No interpunct if the line splits here
219 }{
220 \tocspace{\bfa·}\tocspace\toc_link{#2}
221 }
222 \fi
223 \stoptexdefinition
224
225 \setupcombinedlist[content][list=section]
226 \setuplist[section][
227 alternative=command,
228 command=\SectionTOCcommand,
229 ]
230
231 \setuplist[subsection][
232 alternative=command,
233 command=\SubsectionTOCcommand,
234 ]
235
236 %%%%%%%%%%%%%%%%%%%%%%%
237 %%%%% Title Block %%%%%
238 %%%%%%%%%%%%%%%%%%%%%%%
239
240 \setupdocument[
241 title={},
242 author={},
243 version={},
244 ctan={},
245 github={},
246 ]
247
248 \startluacode
249 local function strip_url(str)
250 local url_table = url.hashed(str)
251 url_table.fragment = nil
252 url_table.scheme = nil
253 url_table.authority = url_table.authority:gsub("^www%.", "")
254 tex.sprint(-2, url.decode(url.construct(url_table)))
255 end
256
257 interfaces.implement {
258 name = "strip_url",
259 actions = strip_url,
260 arguments = "1 string"
261 }
262 \stopluacode
263
264 \define[1]\strippedurl{%
265 \goto{\tt\hyphenatedurl{\clf_strip_url{#1}}}[url(#1)]
266 }
267
268 \startsetups[titleblock]
269 \startalignment [middle]
270 \begingroup
271 \setups[style:section]\bfc
272 \documentvariable{title}
273 \par
274 \endgroup
275
276 \blank[big]
277
278 \begingroup
279 \ssa\lining
280 \documentvariable{author}
281 \blank[medium]
282 v\,\documentvariable{version}
283 \par
284 \endgroup
285
286 \dontleavehmode
287 \blackrule[depth=-0.25\baselineskip, height=\dimexpr0.25\baselineskip + 0.4pt, width=8em]
288 \par
289
290 \doifdocumentvariable{ctan}{
291 \strippedurl{\documentvariable{ctan}}
292 }
293 \doifdocumentvariable{github}{
294 \strippedurl{\documentvariable{github}}
295 }
296 \blank[big]
297
298 \noindentation
299 \stopalignment
300 \stopsetups
301
302 \startsetups[document:start]
303 \setup[titleblock]
304
305 \setupinteraction[
306 title=\documentvariable{title},
307 author=\documentvariable{author},
308 ]
309 \stopsetups
310
311 %%%%%%%%%%%%%%%%%%%%%%%%
312 %%%%% Bibliography %%%%%
313 %%%%%%%%%%%%%%%%%%%%%%%%
314 \usebtxdefinitions[apa]
315
316 \resetsetups[apa:list:sameauthor]
317
318 \setupbtx[apa:list][
319 stopper:initials=,
320 separator:initials=\btxnbsp,
321 interaction=start,
322 ]
323
324 \setupbtxlabeltext[en][
325 apa:Retrieved={}
326 ]
327
328 \setupbtxrendering[apa][
329 numbering=yes,
330 sorttype=used,
331 ]
332
333 \setupbtx[apa:cite][alternative=num]
334
335 \defineshift[citeshift][
336 method=0,
337 dy=-1,
338 unit=ex,
339 continue=yes,
340 style=\tfx\lining,
341 ]
342
343 \setupbtx[apa:cite:num][
344 command=\citeshift,
345 left=,
346 right=,
347 separator:2=\citeshift{,\,},
348 separator:3=\citeshift{--}
349 ]
350
351 \setupbtxlist[apa][
352 alternative=a,
353 before=,
354 after={\blank[quarterline]},
355 style=\lining,
356 margin=0pt,
357 width=1.5em,
358 ]
359
360 \starttexdefinition mutable protected btx:apa:url
361 \strippedurl{\clf_btxflush{\currentbtxdataset}{\currentbtxtag}{url}
362 }
363 \stoptexdefinition
364
365 \define[1]\lwc_doi{\goto{\acronym{DOI:}\,\tt\hyphenatedurl{#1}}[url(https://dx.doi.org/#1)]}
366 \starttexdefinition mutable protected btx:apa:doi
367 \lwc_doi{\clf_btxflush{\currentbtxdataset}{\currentbtxtag}{doi}}
368 \stoptexdefinition
369
370
371 %%%%%%%%%%%%%%%%
372 %%% Markdown %%%
373 %%%%%%%%%%%%%%%%
374
375 \startluacode
376 sandbox.registerrunner {
377 name = "pandoc",
378 program = "pandoc",
379 method = "resultof",
380 template = "--from markdown --to context %filename%",
381 checkers = {
382 filename = "readable",
383 path = "string",
384 }
385 }
386
387 interfaces.implement {
388 name = "markdownInput",
389 public = true,
390 arguments = { "string" },
391 actions = function (str)
392 -- local out = sandbox.getrunner("pandoc"){
393 -- filename = str,
394 -- }
395 --
396 -- context(out)
397 end
398 }
399 \stopluacode
400
401 \protect
402 \stopenvironment