Debian Codegraph @

texmf-dist/doc/lualatex/showkerning/showkerning.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 \usepackage{babel}
167 \usepackage[paper=a4paper,marginratio={2:1,3:4}]{geometry}
168 \usepackage{spacekern}
169 \usepackage{hyperref}
170 \usepackage{bookmark}
171 \usepackage{microtype}
172
173 \hypersetup{%
174 pdflang=en,%
175 unicode=true,%
176 pdfborder={0 0 0},%
177 bookmarksopen=true,%
178 bookmarksopenlevel=0,%
179 bookmarksnumbered=true,%
180 pdftitle={The showkerning package},
181 pdfsubject={Showing kerns in a document},
182 pdfauthor={Thomas Kelkel},
183 pdfkeywords={tex, latex, kerning}
184 }
185
186 \setlength{\parindent}{0pt}
187 \setlength{\parskip}{.4\baselineskip}
188
189 \newcommand*{\q}[1]{%
190 ›%
191 #1%
192 ‹%
193 }
194 \newcommand*{\qq}[1]{%
195 »%
196 #1%
197 «%
198 }
199
200 \newcommand*{\textnote}[1]{%
201 {%
202 \ttfamily%
203 \char174{}%
204 #1%
205 \char174{}%
206 }%
207 }
208
209 \usepackage{luacode}
210
211 \begin{luacode}
212
213 local FLOOR = math.floor
214
215 local function round ( num, dec )
216 return FLOOR ( num * 10^dec + 0.5 ) / 10^dec
217 end
218
219 local p_array = {false, false, false, false, false}
220 local p_counter = 0
221 local ID = node.id
222 local NEW = node.new
223 local COPY = node.copy
224 local REM = node.remove
225 local PREV = node.prev
226 local NEXT = node.next
227 local TAIL = node.tail
228 local T_ID = node.traverse_id
229 local T_GLYPH = node.traverse_glyph
230 local INS_B = node.insert_before
231 local GLYPH = ID ( "glyph" )
232 local GLUE = ID ( "glue" )
233 local KERN = ID ( "kern" )
234 local HLIST = ID ( "hlist" )
235 local SWAPPED = table.swapped
236 local SUBTYPES = node.subtypes
237 local SPACESKIP = SWAPPED ( SUBTYPES ("glue") )["spaceskip"]
238 local WIDTH = round ( tex.sp ( "1.6em" ), 0 )
239 local ipairs = ipairs
240 local page_counter = 0
241 local INS_A = node.insert_after
242 local p_counter_x = 0
243 local ATC = luatexbase.add_to_callback
244
245 local function make_marks ( head, char, id, array, counter )
246 for n in T_GLYPH ( head ) do
247 if n.char == char then
248 counter = counter + 1
249 array[counter] = {false, false, false}
250 head = INS_B ( head, n, NEW ( GLYPH ) )
251 PREV ( n ).data = id
252 local NEXT = n.next
253 local inside_counter = 0
254 while NEXT.char ~= char do
255 inside_counter = inside_counter + 1
256 array[counter][inside_counter] = COPY ( NEXT )
257 NEXT = NEXT.next
258 REM ( head, NEXT.prev )
259 end
260 head = REM ( head, NEXT )
261 head = REM ( head, n )
262 end
263 end
264 return head, array, counter
265 end
266
267 local function mark_notes ( head )
268 head, p_array, p_counter = make_marks ( head, 174, 427956, p_array, p_counter )
269 return head
270 end
271
272 local function make_margin_notes ( head, id, array, counter )
273 for n in T_ID ( HLIST, head ) do
274 local first_kern = 0
275 local first_width = 0
276 for glyph_node in T_GLYPH ( n.head ) do
277 if glyph_node.data == id then
278 counter = counter + 1
279 local tail_node = TAIL ( n.head )
280 local glue_node = NEW ( GLUE )
281 glue_node.subtype = SPACESKIP
282 glue_node.width = WIDTH
283 local NEXT
284 local switch_counter = 1 -- page_counter
285 n.head = INS_A ( n.head, TAIL ( n.head ), glue_node )
286 if ( switch_counter % 2 == 0 ) then
287 NEXT = glue_node
288 else
289 NEXT = tail_node
290 end
291 local kern_value = 0
292 for _, value in ipairs ( array[counter] ) do
293 if value ~= false then
294 local NUMBER = COPY ( value )
295 n.head = INS_A ( n.head, NEXT, NUMBER)
296 if NEXT.next then
297 NEXT = NEXT.next
298 end
299 if NUMBER.width then
300 kern_value = kern_value - NUMBER.width
301 end
302 end
303 end
304 local kern_node = NEW ( KERN )
305 kern_node.kern = kern_value - glue_node.width
306 if switch_counter % 2 ~= 0 then
307 kern_node.kern = kern_node.kern - tex.hsize + first_kern
308 n.head = INS_A ( n.head, tail_node, kern_node )
309 end
310 if ( switch_counter % 2 == 0 ) and ( first_kern < 0 ) then
311 kern_node.kern = kern_node.kern - first_kern + first_width - kern_value
312 n.head = INS_A ( n.head, tail_node, kern_node )
313 end
314 first_kern = kern_node.kern
315 first_width = kern_value
316 end
317 end
318 end
319 return head, counter
320 end
321
322 local function make_text_notes ( head )
323 page_counter = page_counter + 1
324 head, p_counter_x = make_margin_notes ( head, 427956, p_array, p_counter_x )
325 return head
326 end
327
328 ATC ( "ligaturing", mark_notes , "mark notes" )
329 ATC ( "pre_output_filter", make_text_notes , "count pages" )
330
331 \end{luacode}
332
333 \flushbottom
334
335 \pagestyle{empty}
336
337 \usepackage{showkerning}
338
339 \RedeclareSectionCommand[%
340 afterskip=1.3ex plus .2ex,%
341 beforeskip=-2.5ex plus -1ex minus -.2ex,%
342 font=\superlarge%
343 ]%
344 {section}
345
346 \begin{document}
347
348 \directlua{
349 local function rem_kern ( head )
350 for n in node.traverse ( head ) do
351 if n.id == node.id ( "hlist" ) or n.id == node.id ( "vlist" ) then
352 n.head = rem_kern ( n.head )
353 elseif n.id == node.id ( "glyph" ) then
354 if n.char == 112 then
355 n.prev.data = ""
356 end
357 end
358 end
359 return head
360 end
361
362 luatexbase.add_to_callback ( "post_linebreak_filter", rem_kern, "remove kern", 1 )
363 }
364
365 \title{The showk\kern-.1eme\kern.2emrn\kern-.05emin\kern.1emg package\vspace{.25\baselineskip}\\\superlarge{}\directlua{luatexbase.remove_from_callback ( "post_linebreak_filter", "show kerns in postline" ) luatexbase.remove_from_callback ( "hpack_filter", "show kerns in hpack" ) luatexbase.remove_from_callback ( "post_linebreak_filter", "remove kern" )}Showing kerns in a document}%
366 \author{\sublarge{}Thomas Kelkel\vspace{-.25\baselineskip}\\\sublarge{}[email protected]\vspace{-.25\baselineskip}}%
367 \date{\addfontfeature{LetterSpace=2}\sublarge{}2023/07/08\quad{}v0.3}%
368 \maketitle
369
370 \thispagestyle{empty}
371
372 \section{Introduction}
373
374 This package displays all kerning values in the form of colored bars directly at the respective position in the document. Positive values are displayed in green, negative values in red. The width of the bars corresponds exactly to the respective kerning value. The left edge of the bar is always at the position where the kerning node is placed. (This corresponds to the common representation method).
375
376 Please note that Lua{\addfontfeature{LetterSpace = 2}\LaTeX} is required to use this package.
377
378 \section{Basic usage}
379
380 To load the package, simply add the following line to the preamble of the document:
381
382 \begin{quote}
383 \mono{\textbackslash{}usepackage\{showkerning\}}
384 \end{quote}
385
386 \section{Package options}
387
388 \addcontentsline{toc}{subsection}{ontop}
389
390 \textnote{ontop}By default, the bars are placed behind the glyphs. With this option they are in front of them. It can be loaded in the following way:
391
392 \begin{quote}
393 \mono{\textbackslash{}usepackage[ontop]\{showkerning\}}
394 \end{quote}
395
396 \section{License}
397
398 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}.
399
400 \end{document}