Debian Codegraph @

texmf-dist/doc/lualatex/ligtype/ligtype.tex

raw
1 \documentclass[
2 ukenglish,%
3 twoside=false,%
4 fontsize=10pt,%
5 bibliography=totoc,%
6 numbers=autoenddot,%
7 headings=normalsize,%
8 overfullrule,%
9 headings=optiontotoc,%
10 ]
11 {scrartcl}
12
13 \makeatletter
14 \providecommand\@ix{9.6}
15 \providecommand\@xi{10.4}
16 \providecommand\@xiii{13.15}
17 \def\subfootnotesize{%
18 \@setfontsize%
19 \subfootnotesize%
20 {7.6}{8}%
21 }
22 \def\supernormalsize{%
23 \@setfontsize%
24 \supernormalsize%
25 \@xi{12}%
26 }
27 \def\subnormalsize{%
28 \@setfontsize%
29 \subnormalsize%
30 \@ix{11}%
31 }
32 \def\sublarge{%
33 \@setfontsize%
34 \sublarge%
35 {11.2}{13}%
36 }
37 \def\superlarge{%
38 \@setfontsize%
39 \superlarge%
40 \@xiii{16}%
41 }
42 \makeatother
43
44 \newcommand*{\sectionas}{2.3ex plus .2ex}
45 \newcommand*{\sectionbs}{-3.5ex plus -1ex minus -.2ex}
46 \newcommand*{\sectiontbs}{3.6pt}
47 \newcommand*{\subsectiontbs}{1.2pt}
48 \newcommand*{\subsectionas}{1.5ex plus .2ex}
49 \newcommand*{\subsectionbs}{-3.25ex plus -1ex minus -.2ex}
50 \newcommand*{\subsubsectionas}{\subsectionas}
51 \newcommand*{\subsubsectionbs}{\subsectionbs}
52 \newcommand*{\paragraphas}{-1em}
53 \newcommand*{\paragraphbs}{.8\baselineskip}
54
55 \newlength{\tnwsection}
56 \newlength{\tnwsubsection}
57 \newlength{\tnwsubsubsection}
58 \newlength{\tnwparagraph}
59 \newlength{\tisection}
60 \newlength{\tisubsection}
61 \newlength{\tisubsubsection}
62 \newlength{\tiparagraph}
63
64 \setlength{\tnwsection}{1.2em}
65 \addtolength{\tnwsection}{.6em}
66 \setlength{\tnwsubsection}{\tnwsection}
67 \addtolength{\tnwsubsection}{.75em}
68 \setlength{\tnwsubsubsection}{\tnwsubsection}
69 \addtolength{\tnwsubsubsection}{.75em}
70 \setlength{\tnwparagraph}{\tnwsubsubsection}
71 \addtolength{\tnwparagraph}{.75em}
72
73 \setlength{\tisection}{0em}
74 \setlength{\tisubsection}{\tisection}
75 \addtolength{\tisubsection}{\tnwsection}
76 \setlength{\tisubsubsection}{\tisubsection}
77 \addtolength{\tisubsubsection}{\tnwsubsection}
78 \setlength{\tiparagraph}{\tisubsubsection}
79 \addtolength{\tiparagraph}{\tnwsubsubsection}
80
81 \RedeclareSectionCommands[%
82 tocraggedentrytext=true,%
83 ]%
84 {section,subsection,subsubsection,paragraph}
85
86 \RedeclareSectionCommand[%
87 tocindent=\tisection,%
88 tocnumwidth=\tnwsection,%
89 tocbeforeskip=\sectiontbs,%
90 tocentryformat=\supernormalsize\sffamily\bfseries,%
91 tocentrynumberformat=\supernormalsize\sffamily\bfseries,%
92 tocpagenumberformat=\supernormalsize\sffamily\bfseries%
93 ]%
94 {section}
95
96 \RedeclareSectionCommand[%
97 tocindent=\tisubsection,%
98 tocnumwidth=\tnwsubsection,%
99 tocbeforeskip=\subsectiontbs,%
100 tocentryformat=\subnormalsize,%
101 tocentrynumberformat=\subnormalsize,%
102 tocpagenumberformat=\subnormalsize%
103 ]%
104 {subsection}
105
106 \RedeclareSectionCommand[%
107 tocindent=\tisubsubsection,%
108 tocnumwidth=\tnwsubsubsection,%
109 tocbeforeskip=\sectiontbs%
110 ]%
111 {subsubsection}
112
113 \RedeclareSectionCommand[%
114 afterskip=\paragraphas,%
115 beforeskip=\paragraphbs,%
116 tocindent=\tiparagraph,%
117 tocnumwidth=\tnwparagraph,%
118 tocbeforeskip=\sectiontbs%
119 ]%
120 {paragraph}
121
122 \linespread{1.1}
123
124 \newcommand*{\hs}{\hspace{.45em}}
125
126 \usepackage{fontspec}
127
128 \directlua{
129
130 fonts.handlers.otf.addfeature {
131 name = "onumkern",
132 type = "kern",
133 data = {
134 ["v"] = { ["zero.taboldstyle"] = 80 },
135 ["two.taboldstyle"] = { ["zero.taboldstyle"] = 30, ["/"] = 50 },
136 ["five.taboldstyle"] = { ["/"] = 20 },
137 ["»"] = { ["I"] = 50 },
138 },
139 }
140
141 }
142
143 \setmainfont{Tangent}[
144 BoldFont = *-Medium,
145 ItalicFont = *-Italic,
146 Ligatures = {Common, TeX},
147 Numbers = OldStyle,
148 RawFeature = +onumkern
149 ]
150
151 \setsansfont{SegoeUI}[
152 BoldFont = seguisb.ttf,
153 Ligatures = {Discretionary, TeX},
154 Numbers = OldStyle
155 ]
156
157 \setmonofont{Consolas}[
158 ItalicFont = *-Italic,
159 Numbers = OldStyle
160 ]
161
162 \newcommand*{\mono}[1]{%
163 {\subnormalsize\texttt{#1}}%
164 }
165
166 \newcommand*{\monofn}[1]{%
167 {\subfootnotesize\texttt{#1}}%
168 }
169
170 \usepackage{babel}
171 \usepackage{realscripts}
172 \usepackage[paper=a4paper,marginratio={2:1,3:4}]{geometry}
173 \usepackage[noshortf,makemarks]{ligtype}
174 \usepackage{spacekern}
175 \usepackage{hyperref}
176 \usepackage{bookmark}
177 \usepackage{microtype}
178
179 \hypersetup{%
180 pdflang=en,%
181 unicode=true,%
182 pdfborder={0 0 0},%
183 bookmarksopen=true,%
184 bookmarksopenlevel=0,%
185 bookmarksnumbered=true,%
186 pdftitle={The ligtype package},
187 pdfsubject={Comprehensive ligature suppression functionalities},
188 pdfauthor={Thomas Kelkel},
189 pdfkeywords={tex, latex, ligatures}
190 }
191
192 \setlength{\parindent}{0pt}
193 \setlength{\parskip}{.4\baselineskip}
194
195 \newcommand*{\q}[1]{%
196 ›%
197 #1%
198 ‹%
199 }
200 \newcommand*{\qq}[1]{%
201 »%
202 #1%
203 «%
204 }
205
206 \setlength{\footnotesep}{.8em}
207
208 \deffootnote[0em]{0em}{1em}{}
209
210 \newcommand*{\fn}[1]{%
211 \footnotemark%
212 \footnotetext{%
213 \textbf{\addfontfeature{Numbers = Lining, BoldFont = Tangent-Bold}\thefootnote}%
214 \hs%
215 #1%
216 }%
217 }
218
219 \newcommand*{\textnote}[1]{%
220 {%
221 \ttfamily%
222 \char174{}%
223 #1%
224 \char174{}%
225 }%
226 }
227
228 \usepackage{luacode}
229
230 \begin{luacode}
231
232 local FLOOR = math.floor
233
234 local function round ( num, dec )
235 return FLOOR ( num * 10^dec + 0.5 ) / 10^dec
236 end
237
238 local p_array = {false, false, false, false, false}
239 local p_counter = 0
240 local ID = node.id
241 local NEW = node.new
242 local COPY = node.copy
243 local REM = node.remove
244 local PREV = node.prev
245 local NEXT = node.next
246 local TAIL = node.tail
247 local T_ID = node.traverse_id
248 local T_GLYPH = node.traverse_glyph
249 local INS_B = node.insert_before
250 local GLYPH = ID ( "glyph" )
251 local GLUE = ID ( "glue" )
252 local KERN = ID ( "kern" )
253 local HLIST = ID ( "hlist" )
254 local SWAPPED = table.swapped
255 local SUBTYPES = node.subtypes
256 local SPACESKIP = SWAPPED ( SUBTYPES ("glue") )["spaceskip"]
257 local WIDTH = round ( tex.sp ( "1.6em" ), 0 )
258 local ipairs = ipairs
259 local page_counter = 0
260 local INS_A = node.insert_after
261 local p_counter_x = 0
262 local ATC = luatexbase.add_to_callback
263
264 local function make_marks ( head, char, id, array, counter )
265 for n in T_GLYPH ( head ) do
266 if n.char == char then
267 counter = counter + 1
268 array[counter] = {false, false, false}
269 head = INS_B ( head, n, NEW ( GLYPH ) )
270 PREV ( n ).data = id
271 local NEXT = n.next
272 local inside_counter = 0
273 while NEXT.char ~= char do
274 inside_counter = inside_counter + 1
275 array[counter][inside_counter] = COPY ( NEXT )
276 NEXT = NEXT.next
277 REM ( head, NEXT.prev )
278 end
279 head = REM ( head, NEXT )
280 head = REM ( head, n )
281 end
282 end
283 return head, array, counter
284 end
285
286 local function mark_notes ( head )
287 head, p_array, p_counter = make_marks ( head, 174, 427956, p_array, p_counter )
288 return head
289 end
290
291 local function make_margin_notes ( head, id, array, counter )
292 for n in T_ID ( HLIST, head ) do
293 local first_kern = 0
294 local first_width = 0
295 for glyph_node in T_GLYPH ( n.head ) do
296 if glyph_node.data == id then
297 counter = counter + 1
298 local tail_node = TAIL ( n.head )
299 local glue_node = NEW ( GLUE )
300 glue_node.subtype = SPACESKIP
301 glue_node.width = WIDTH
302 local NEXT
303 local switch_counter = 1 -- page_counter
304 n.head = INS_A ( n.head, TAIL ( n.head ), glue_node )
305 if ( switch_counter % 2 == 0 ) then
306 NEXT = glue_node
307 else
308 NEXT = tail_node
309 end
310 local kern_value = 0
311 for _, value in ipairs ( array[counter] ) do
312 if value ~= false then
313 local NUMBER = COPY ( value )
314 n.head = INS_A ( n.head, NEXT, NUMBER)
315 if NEXT.next then
316 NEXT = NEXT.next
317 end
318 if NUMBER.width then
319 kern_value = kern_value - NUMBER.width
320 end
321 end
322 end
323 local kern_node = NEW ( KERN )
324 kern_node.kern = kern_value - glue_node.width
325 if switch_counter % 2 ~= 0 then
326 kern_node.kern = kern_node.kern - tex.hsize + first_kern
327 n.head = INS_A ( n.head, tail_node, kern_node )
328 end
329 if ( switch_counter % 2 == 0 ) and ( first_kern < 0 ) then
330 kern_node.kern = kern_node.kern - first_kern + first_width - kern_value
331 n.head = INS_A ( n.head, tail_node, kern_node )
332 end
333 first_kern = kern_node.kern
334 first_width = kern_value
335 head = REM ( head, glyph_node )
336 end
337 end
338 end
339 return head, counter
340 end
341
342 local function make_text_notes ( head )
343 page_counter = page_counter + 1
344 head, p_counter_x = make_margin_notes ( head, 427956, p_array, p_counter_x )
345 return head
346 end
347
348 ATC ( "ligaturing", mark_notes , "mark notes" )
349 ATC ( "pre_output_filter", make_text_notes , "count pages" )
350
351 \end{luacode}
352
353 \flushbottom
354
355 \nolig{ligtype}{lig|type}
356
357 \begin{document}
358
359 \title{The ligtype package\vspace{.25\baselineskip}\\\superlarge{}Comprehensive ligature suppression functionalities}%
360 \author{\sublarge{}Thomas Kelkel\vspace{-.25\baselineskip}\\\sublarge{}[email protected]\vspace{-.25\baselineskip}}%
361 \date{\addfontfeature{LetterSpace=2}\sublarge{}2023/07/08\quad{}v0.3}%
362 \maketitle
363
364 \ligtypeoff
365
366 \vspace{-2\baselineskip}
367
368 \tableofcontents
369
370 \vspace{-\baselineskip}
371
372 \addvspace{3em}
373 \hfill\textit{\qq{I don't think you would ever do this in English}}\par
374 \addvspace{-.25\baselineskip}
375 \hfill {\small\textbf{David Carlisle}\quad}
376 \vspace{-2\baselineskip}
377
378 \section{Introduction}
379
380 The main feature of this package is the selective suppression of typographic ligatures.
381
382 There’s already the \mono{selnolig} package by Mico Loretan providing such capability. However, it has some significant shortcomings that render it barely applicable in many use cases. The \mono{ligtype} package steps in to address these deficiencies. The main improvements are:
383
384 \paragraph{Kerning}
385
386 The \mono{ligtype} package applies kerning for the glyphs of the suppressed ligatures. Both font and user kerning are applied in the usual way.
387
388 \paragraph{Short-armed f}
389
390 If available, it automatically replaces the f-glyphs of suppressed ligatures with their short-arm variant.
391
392 \paragraph{Speed}
393
394 It is between ten and twenty times faster on a typical document, thanks to its completely different architecture.\fn{This factor increases with the length of the paragraphs. On a 150-page paragraph, \monofn{ligtype} runs more than a hundred times faster.}
395
396 \addvspace{\paragraphbs}
397
398 Another, rather minor, difference is that it does not require \mono{fontspec}.
399
400 \addvspace{\paragraphbs}
401
402 \noindent The \mono{ligtype} package provides built-in suppression of inappropriate ligatures for \textbf{\addfontfeature{BoldFont = Tangent-Bold}German language documents.} (\kern.05emFor this purpose it makes use of the corresponding suppression rules provided by the \mono{selnolig} package, which cover all common f-ligatures\fn{Details can be taken from the \monofn{selnolig} documentation.}.) Using the \mono{nodefault} option and the \mono{\textbackslash{}nolig} and \mono{\textbackslash{}keeplig} macros it can also be used for other languages.
403
404 Please note that Lua{\addfontfeature{LetterSpace = 2}\LaTeX} is required to use this package.
405
406 Finally, a quick word regarding the code: It is optimized for speed throughout. It would have been much easier to provide a significantly shorter, clearer, more straightforward one. Unfortunately, with this software such code would not have been the fastest one.
407
408 \section{Basic usage}
409
410 To load the package, simply add the following line to the preamble of the document:
411
412 \begin{quote}
413 \mono{\textbackslash{}usepackage\{ligtype\}}
414 \end{quote}
415
416 If the glyphs forming the ligatures are already properly kerned and a German language document is typeset, loading the package without any options should be sufficient for most use cases.
417
418 However, most of the time it will be the case that the corresponding glyphs have to be kerned first. For this task, the \mono{kerntest} option is extremely helpful.
419
420 \section{Package options}
421
422 Options can be loaded by adding them comma separated within square brackets:
423
424 \begin{quote}
425 \mono{\textbackslash{}usepackage[\textit{<option1>,<option2>,…}]\{ligtype\}}
426 \end{quote}
427
428 \addcontentsline{toc}{subsection}{kerntest}
429
430 \textnote{kerntest}This option prints all glyph combinations that comprise the ligatures \mono{ligtype} is looking for in Regular, Italic, Bold and Italic Bold for both the Roman and the Sans font on the last page of the document. This gives you an overview of all kerning pairs that are relevant when breaking ligatures, and you can inspect the kerning values accordingly.
431
432 \addcontentsline{toc}{subsection}{liglist}
433
434 \textnote{liglist}Prints, both in the output and in an external file \mono{[filename].lig,} a sorted list of all kept and broken ligatures.
435
436 White- and blacklists can be used in conjunction with this feature. For this \mono{lig-whitelist.txt} and \mono{lig-blacklist.txt} must be provided in the document path. In the whitelist the ligatures to be broken are listed in the blacklist the ligatures to be kept. According to the formatting in the output file, the breaking points are marked with a vertical bar in the whitelist and with a centered period in the blacklist.
437
438 \addcontentsline{toc}{subsection}{makemarks}
439
440 \textnote{makemarks}Marks each point where a ligature was suppressed with a blue triangle below the baseline.
441
442 \addcontentsline{toc}{subsection}{noshortf}
443
444 \textnote{noshortf}Various use cases are conceivable with this option.
445
446 It is primarily intended to suppress the use of short-armed f if they are not desired.
447
448 In addition, it may be useful to load this option when using fonts that do not offer short-armed f, since there is a small gain in speed if \mono{ligtype} does not look for them.
449
450 Finally, this option could be used to prevent \qq{false positives}. (Even though such are not known to occur.)
451
452 \addcontentsline{toc}{subsection}{allshortf}
453
454 \textnote{allshortf}In some cases it may be desirable to use short-armed f without having different f-glyphs in the document. This option can be used for such purpose, since it replaces all long-armed f with their short-arm variant (if available).
455
456 This option has priority over the \mono{noshortf} option, i.\,e. if both are loaded, \mono{allshortf} is applied.
457
458 \addcontentsline{toc}{subsection}{nodefault}
459
460 \textnote{nodefault}Disables the built-in (German language) suppression rules. With this option and the \mono{\textbackslash{}nolig} and \mono{\textbackslash{}keeplig} macros, \mono{ligtype} can be used for other languages.
461
462 \section{Macros}
463
464 \addcontentsline{toc}{subsection}{nolig}
465
466 \addcontentsline{toc}{subsection}{keeplig}
467
468 \textnote{\textbackslash{}nolig}The first macro defines a rule for suppressing ligatures, the second one for keeping them. Both macros take two arguments.\textnote{\textbackslash{}keeplig} The first one specifies the string to search for. In the second, a marker of the breaking point is added to this string using a vertical bar.\fn{The architecture of the \monofn{ligtype} package differs quite significantly from that of the \monofn{selnolig} package. To allow current users of \monofn{selnolig} to continue using existing macros for creating suppression rules as far as possible without changes, the syntax has been largely adopted. For the \monofn{\textbackslash{}nolig} macro it is identical. However, in contrast to the \monofn{selnolig} syntax, the breakpoint must be specified as a second argument for the \monofn{\textbackslash{}keeplig} macros, since \monofn{ligtype} requires this for every rule application.} For example:
469
470 \begin{quote}
471 \mono{\textbackslash{}nolig\{flich\}\{f|lich\}}\\
472 \mono{\textbackslash{}keeplig\{flicht\}\{f|licht\}}
473 \end{quote}
474
475 A list of alternatives that can be located at the end of the string can be specified within square brackets:
476
477 \begin{quote}
478 \mono{\textbackslash{}nolig\{Auff[aeiloruyäöü]\}\{Auf|f\}}
479 \end{quote}
480
481 It is important to note that macros are processed in the order in which they are defined, which means that strings defined later have priority over strings defined earlier. Accordingly, strings defined later should not be included in strings defined earlier, otherwise the earlier ones will have no effect.
482
483 \addcontentsline{toc}{subsection}{ligtypeon}
484
485 \addcontentsline{toc}{subsection}{ligtypeoff}
486
487 \textnote{\textbackslash{}ligtypeon}With the help of these macros the features of the \mono{ligtype} package can be switched on and off within the document.\textnote{\textbackslash{}ligtypeoff}
488
489 \section{Acknowledgements}
490
491 The \mono{ligtype} package makes use of the German language ligature suppression rules of the \mono{selnolig} package by Mico Loretan. The \mono{selnolig} package can be downloaded at
492
493 \begin{quote}
494 \mono{https://www.ctan.org/pkg/selnolig}
495 \end{quote}
496
497 and may be distributed and/or modified under the conditions of the LaTeX Project Public License.
498
499 Please see the \qq{License and acknowledgments} section of the \mono{selnolig} documentation to learn about all the people who contributed to the creation of the suppression rules.
500
501 In general, the truly excellent \mono{selnolig} documentation is highly recommended for further information on the subject of this package.
502
503 \section{License}
504
505 This package is copyright © 2022\kern.1em–\kern.1em2023 Thomas Kelkel. It may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3c of this license or (at your option) any later version. This work has the LPPL maintenance status \qq{author maintained}.
506
507 \end{document}