Debian Codegraph @

texmf-dist/tex/lualatex/lua-typo/lua-typo-2021-04-18.sty

raw
1 %%
2 %% This is file `lua-typo.sty' v0.40,
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% lua-typo.dtx (with options: `sty')
8 %%
9 %% IMPORTANT NOTICE:
10 %% For the copyright see the source file `lua-typo.dtx'.
11 %%
12 \NeedsTeXFormat{LaTeX2e}[2020/01/01]
13 \ProvidesPackage{lua-typo}
14 [2021/04/18 v.0.40 Daniel Flipo]
15 \ifdefined\directlua
16 \RequirePackage{luatexbase,luacode,luacolor}
17 \RequirePackage{kvoptions,atveryend}
18 \else
19 \PackageError{This package is meant for LuaTeX only! Aborting}
20 {No more information available, sorry!}
21 \fi
22 \newdimen\luatypoLLminWD
23 \newdimen\luatypoBackPI
24 \newdimen\luatypoBackFuzz
25 \newcount\luatypoStretchMax
26 \newcount\luatypoHyphMax
27 \newcount\luatypoPageMin
28 \newcount\luatypoMinFull
29 \newcount\luatypoMinPart
30 \newcount\luatypo@LANGno
31 \newcount\luatypo@options
32 \newtoks\luatypo@single
33 \newtoks\luatypo@double
34
35 \begin{luacode}
36 luatypo = { }
37 \end{luacode}
38 \SetupKeyvalOptions{
39 family=luatypo,
40 prefix=LT@,
41 }
42 \DeclareBoolOption[false]{ShowOptions}
43 \DeclareBoolOption[false]{None}
44 \DeclareBoolOption[false]{All}
45 \DeclareBoolOption[false]{BackParindent}
46 \DeclareBoolOption[false]{ShortLines}
47 \DeclareBoolOption[false]{ShortPages}
48 \DeclareBoolOption[false]{OverfullLines}
49 \DeclareBoolOption[false]{UnderfullLines}
50 \DeclareBoolOption[false]{Widows}
51 \DeclareBoolOption[false]{Orphans}
52 \DeclareBoolOption[false]{EOPHyphens}
53 \DeclareBoolOption[false]{RepeatedHyphens}
54 \DeclareBoolOption[false]{ParLastHyphen}
55 \DeclareBoolOption[false]{EOLShortWords}
56 \DeclareBoolOption[false]{FirstWordMatch}
57 \DeclareBoolOption[false]{LastWordMatch}
58 \AddToKeyvalOption{luatypo}{All}{%
59 \LT@ShortLinestrue \LT@ShortPagestrue
60 \LT@OverfullLinestrue \LT@UnderfullLinestrue
61 \LT@Widowstrue \LT@Orphanstrue
62 \LT@EOPHyphenstrue \LT@RepeatedHyphenstrue
63 \LT@ParLastHyphentrue \LT@EOLShortWordstrue
64 \LT@FirstWordMatchtrue \LT@LastWordMatchtrue
65 \LT@BackParindenttrue
66 }
67 \ProcessKeyvalOptions{luatypo}
68 \AtEndOfPackage{%
69 \ifLT@None
70 \directlua{ luatypo.None = true }%
71 \else
72 \directlua{ luatypo.None = false }%
73 \fi
74 \ifLT@BackParindent
75 \advance\luatypo@options by 1
76 \directlua{ luatypo.BackParindent = true }%
77 \else
78 \directlua{ luatypo.BackParindent = false }%
79 \fi
80 \ifLT@ShortLines
81 \advance\luatypo@options by 1
82 \directlua{ luatypo.ShortLines = true }%
83 \else
84 \directlua{ luatypo.ShortLines = false }%
85 \fi
86 \ifLT@ShortPages
87 \advance\luatypo@options by 1
88 \directlua{ luatypo.ShortPages = true }%
89 \else
90 \directlua{ luatypo.ShortPages = false }%
91 \fi
92 \ifLT@OverfullLines
93 \advance\luatypo@options by 1
94 \directlua{ luatypo.OverfullLines = true }%
95 \else
96 \directlua{ luatypo.OverfullLines = false }%
97 \fi
98 \ifLT@UnderfullLines
99 \advance\luatypo@options by 1
100 \directlua{ luatypo.UnderfullLines = true }%
101 \else
102 \directlua{ luatypo.UnderfullLines = false }%
103 \fi
104 \ifLT@Widows
105 \advance\luatypo@options by 1
106 \directlua{ luatypo.Widows = true }%
107 \else
108 \directlua{ luatypo.Widows = false }%
109 \fi
110 \ifLT@Orphans
111 \advance\luatypo@options by 1
112 \directlua{ luatypo.Orphans = true }%
113 \else
114 \directlua{ luatypo.Orphans = false }%
115 \fi
116 \ifLT@EOPHyphens
117 \advance\luatypo@options by 1
118 \directlua{ luatypo.EOPHyphens = true }%
119 \else
120 \directlua{ luatypo.EOPHyphens = false }%
121 \fi
122 \ifLT@RepeatedHyphens
123 \advance\luatypo@options by 1
124 \directlua{ luatypo.RepeatedHyphens = true }%
125 \else
126 \directlua{ luatypo.RepeatedHyphens = false }%
127 \fi
128 \ifLT@ParLastHyphen
129 \advance\luatypo@options by 1
130 \directlua{ luatypo.ParLastHyphen = true }%
131 \else
132 \directlua{ luatypo.ParLastHyphen = false }%
133 \fi
134 \ifLT@EOLShortWords
135 \advance\luatypo@options by 1
136 \directlua{ luatypo.EOLShortWords = true }%
137 \else
138 \directlua{ luatypo.EOLShortWords = false }%
139 \fi
140 \ifLT@FirstWordMatch
141 \advance\luatypo@options by 1
142 \directlua{ luatypo.FirstWordMatch = true }%
143 \else
144 \directlua{ luatypo.FirstWordMatch = false }%
145 \fi
146 \ifLT@LastWordMatch
147 \advance\luatypo@options by 1
148 \directlua{ luatypo.LastWordMatch = true }%
149 \else
150 \directlua{ luatypo.LastWordMatch = false }%
151 \fi
152 }
153 \ifLT@ShowOptions
154 \GenericWarning{* }{%
155 *** List of possible options for lua-typo ***\MessageBreak
156 [Default values between brackets]%
157 \MessageBreak
158 ShowOptions [false]\MessageBreak
159 None [false]\MessageBreak
160 BackParindent [false]\MessageBreak
161 ShortLines [false]\MessageBreak
162 ShortPages [false]\MessageBreak
163 OverfullLines [false]\MessageBreak
164 UnderfullLines [false]\MessageBreak
165 Widows [false]\MessageBreak
166 Orphans [false]\MessageBreak
167 EOPHyphens [false]\MessageBreak
168 RepeatedHyphens [false]\MessageBreak
169 ParLastHyphen [false]\MessageBreak
170 EOLShortWords [false]\MessageBreak
171 FirstWordMatch [false]\MessageBreak
172 LastWordMatch [false]\MessageBreak
173 \MessageBreak
174 *********************************************%
175 \MessageBreak Lua-typo [ShowOptions]
176 }%
177 \fi
178 \AtBeginDocument{%
179 \directlua{
180 luatypo.HYPHmax = tex.count.luatypoHyphMax
181 luatypo.PAGEmin = tex.count.luatypoPageMin
182 luatypo.Stretch = tex.count.luatypoStretchMax
183 luatypo.MinFull = tex.count.luatypoMinFull
184 luatypo.MinPart = tex.count.luatypoMinPart
185 luatypo.LLminWD = tex.dimen.luatypoLLminWD
186 luatypo.BackPI = tex.dimen.luatypoBackPI
187 luatypo.BackFuzz = tex.dimen.luatypoBackFuzz
188 }%
189 }
190 \AtVeryEndDocument{%
191 \ifnum\luatypo@options = 0 \LT@Nonetrue \fi
192 \ifLT@None
193 \directlua{
194 texio.write_nl(' ')
195 texio.write_nl('***********************************')
196 texio.write_nl('*** lua-typo loaded with NO option:')
197 texio.write_nl('*** NO CHECK PERFORMED! ***')
198 texio.write_nl('***********************************')
199 texio.write_nl(' ')
200 }%
201 \else
202 \directlua{
203 texio.write_nl(' ')
204 texio.write_nl('*************************************')
205 if luatypo.pagelist == "" then
206 texio.write_nl('*** lua-typo: No Typo Flaws found.')
207 else
208 texio.write_nl('*** lua-typo: WARNING *************')
209 texio.write_nl('The following pages need attention: ')
210 texio.write(luatypo.pagelist)
211 end
212 texio.write_nl('***********************************')
213 texio.write_nl(' ')
214 }%
215 \fi}
216 \newcommand*{\luatypoOneChar}[2]{%
217 \def\luatypo@LANG{#1}\luatypo@single={#2}%
218 \ifcsname l@\luatypo@LANG\endcsname
219 \luatypo@LANGno=\the\csname l@\luatypo@LANG\endcsname \relax
220 \directlua{
221 local langno = \the\luatypo@LANGno
222 local string = \the\luatypo@single
223 luatypo.single[langno] = " "
224 for p, c in utf8.codes(string) do
225 local s = string.char(c)
226 luatypo.single[langno] = luatypo.single[langno] .. s
227 end
228 }%
229 \else
230 \PackageWarning{luatypo}{Unknown language "\luatypo@LANG",
231 \MessageBreak \protect\luatypoOneChar\space command ignored}%
232 \fi}
233 \newcommand*{\luatypoTwoChars}[2]{%
234 \def\luatypo@LANG{#1}\luatypo@double={#2}%
235 \ifcsname l@\luatypo@LANG\endcsname
236 \luatypo@LANGno=\the\csname l@\luatypo@LANG\endcsname \relax
237 \directlua{
238 local langno = \the\luatypo@LANGno
239 local string = \the\luatypo@double
240 luatypo.double[langno] = " "
241 for p, c in utf8.codes(string) do
242 local s = string.char(c)
243 luatypo.double[langno] = luatypo.double[langno] .. s
244 end
245 }%
246 \else
247 \PackageWarning{luatypo}{Unknown language "\luatypo@LANG",
248 \MessageBreak \protect\luatypoTwoChars\space command ignored}%
249 \fi}
250 \newcommand*{\luatypoSetColor}[2]{%
251 \begingroup
252 \color{#2}%
253 \directlua{luatypo.colortbl[#1]=\the\LuaCol@Attribute}%
254 \endgroup
255 }
256 \begin{luacode}
257 luatypo.single = { }
258 luatypo.double = { }
259 luatypo.colortbl = { }
260 luatypo.pagelist = ""
261
262 local char_to_discard = { }
263 char_to_discard[string.byte(",")] = true
264 char_to_discard[string.byte(".")] = true
265 char_to_discard[string.byte("!")] = true
266 char_to_discard[string.byte("?")] = true
267 char_to_discard[string.byte(":")] = true
268 char_to_discard[string.byte(";")] = true
269 char_to_discard[string.byte("-")] = true
270
271 local split_lig = { }
272 split_lig[0xFB00] = "ff"
273 split_lig[0xFB01] = "fi"
274 split_lig[0xFB02] = "fl"
275 split_lig[0xFB03] = "ffi"
276 split_lig[0xFB04] = "ffl"
277 split_lig[0xFB05] = "st"
278 split_lig[0xFB06] = "st"
279
280 local DISC = node.id("disc")
281 local GLYPH = node.id("glyph")
282 local GLUE = node.id("glue")
283 local KERN = node.id("kern")
284 local HLIST = node.id("hlist")
285 local LPAR = node.id("local_par")
286 local MKERN = node.id("margin_kern")
287 local PENALTY = node.id("penalty")
288 local USRSKIP = 0
289 local PARSKIP = 3
290 local LFTSKIP = 8
291 local RGTSKIP = 9
292 local TOPSKIP = 10
293 local PARFILL = 15
294 local LINE = 1
295 local BOX = 2
296 local EQN = 6
297 local USER = 0
298 local HYPH = 0x2D
299 local LIGA = 0x102
300 local parline = 0
301
302 local effective_glue = node.effective_glue
303 local set_attribute = node.set_attribute
304 local slide = node.slide
305 local traverse = node.traverse
306 local traverse_id = node.traverse_id
307 local has_field = node.has_field
308 local uses_font = node.uses_font
309 local is_glyph = node.is_glyph
310
311 local color_node = function (node, color)
312 local attr = oberdiek.luacolor.getattribute()
313 if node and node.id == DISC then
314 local pre = node.pre
315 local post = node.post
316 local repl = node.replace
317 if pre then
318 set_attribute(pre,attr,color)
319 end
320 if post then
321 set_attribute(post,attr,color)
322 end
323 if repl then
324 set_attribute(repl,attr,color)
325 end
326 elseif node then
327 set_attribute(node,attr,color)
328 end
329 end
330 local color_hlist = function (head, color)
331 local first = head.head
332 for n in traverse(first) do
333 color_node(n, color)
334 end
335 end
336 local color_line = function (head, color)
337 local first = head.head
338 for n in traverse(first) do
339 if n and n.id == HLIST then
340 color_hlist(n, color)
341 else
342 color_node(n, color)
343 end
344 end
345 end
346 local signature = function (node, string, swap)
347 local n = node
348 local str = string
349 if n and n.id == GLYPH then
350 local b, id = is_glyph(n)
351 if b and not char_to_discard[b] then
352 if b == 0x2019 then b = 0x27 end
353 if b < 0x100 then
354 str = str .. string.char(b)
355 elseif split_lig[b] then
356 local c = split_lig[b]
357 if swap then
358 c = string.reverse(c)
359 end
360 str = str .. c
361 elseif n.subtype == LIGA and b > 0xE000 then
362 local c = string.sub(b,-2)
363 if swap then
364 c = string.reverse(c)
365 end
366 str = str .. c
367 end
368 end
369 elseif n and n.id == DISC then
370 local pre = n.pre
371 local post = n.post
372 local c1 = ""
373 local c2 = ""
374 if pre and pre.char and pre.char ~= HYPH and pre.char < 0x100 then
375 c1 = string.char(pre.char)
376 end
377 if post and post.char then
378 if post.char < 0x100 then
379 c2 = string.char(post.char)
380 elseif split_lig[post.char] then
381 c2 = split_lig[post.char]
382 if swap then
383 c2 = string.reverse(c2)
384 end
385 end
386 end
387 if swap then
388 str = str .. c2 .. c1
389 else
390 str = str .. c1 .. c2
391 end
392 end
393 local len = string.len(str)
394 if string.find(str, "_") then
395 len = len - 1
396 end
397 return len, str
398 end
399 local check_last_word = function (old, node, flag)
400 local COLOR = luatypo.colortbl[11]
401 local match = false
402 local new = ""
403 local maxlen = 0
404 if flag and node then
405 local swap = true
406 local lastn = node
407 while lastn and lastn.id ~= GLYPH and lastn.id ~= DISC do
408 lastn = lastn.prev
409 end
410 local n = lastn
411 while n and n.id ~= GLUE do
412 maxlen, new = signature (n, new, swap)
413 n = n.prev
414 end
415 if n and n.id == GLUE then
416 new = new .. "_"
417 repeat
418 n = n.prev
419 maxlen, new = signature (n, new, swap)
420 until not n or n.id == GLUE
421 end
422 new = string.reverse(new)
423 local MinFull = luatypo.MinFull
424 local MinPart = luatypo.MinPart
425 MinFull = math.min(MinPart,MinFull)
426 local k = MinPart
427 local oldlast = string.gsub (old, '.*_', '')
428 local newlast = string.gsub (new, '.*_', '')
429 local i = string.find(new, "_")
430 if i and i > maxlen - MinPart + 1 then
431 k = MinPart + 1
432 end
433 local oldsub = string.sub(old,-k)
434 local newsub = string.sub(new,-k)
435 local l = string.len(new)
436 if oldsub == newsub and l >= k then
437 match = true
438 elseif oldlast == newlast and string.len(newlast) >= MinFull then
439 match = true
440 oldsub = oldlast
441 newsub = newlast
442 k = string.len(newlast)
443 end
444 if match then
445 local osub = oldsub
446 local nsub = newsub
447 while osub == nsub and k <= maxlen do
448 k = k +1
449 osub = string.sub(old,-k)
450 nsub = string.sub(new,-k)
451 if osub == nsub then
452 newsub = nsub
453 end
454 end
455 pageflag = true
456 newsub = string.gsub(newsub, '^_', '')
457 oldsub = string.reverse(newsub)
458 local newsub = ""
459 local n = lastn
460 repeat
461 if n and n.id ~= GLUE then
462 color_node(n, COLOR)
463 l, newsub = signature(n, newsub, swap)
464 elseif n then
465 newsub = newsub .. "_"
466 end
467 n = n.prev
468 until not n or newsub == oldsub or l >= k
469 end
470 end
471 return new
472 end
473 local check_first_word = function (old, node, flag)
474 local COLOR = luatypo.colortbl[10]
475 local match = false
476 local swap = false
477 local new = ""
478 local maxlen = 0
479 local start = node
480 local n = start
481 while n and n.id ~= GLYPH and n.id ~= DISC do
482 n = n.next
483 end
484 while n and n.id ~= GLUE do
485 maxlen, new = signature (n, new, swap)
486 n = n.next
487 end
488 if n and n.id == GLUE then
489 new = new .. "_"
490 repeat
491 n = n.next
492 maxlen, new = signature (n, new, swap)
493 until not n or n.id == GLUE
494 end
495 if flag then
496 local MinFull = luatypo.MinFull
497 local MinPart = luatypo.MinPart
498 MinFull = math.min(MinPart,MinFull)
499 local k = MinPart
500 local oldsub = ""
501 local newsub = ""
502 local oldfirst = string.gsub (old, '_.*', '')
503 local newfirst = string.gsub (new, '_.*', '')
504 local i = string.find(new, "_")
505 if i and i <= MinPart then
506 k = MinPart + 1
507 end
508 local oldsub = string.sub(old,1,k)
509 local newsub = string.sub(new,1,k)
510 local l = string.len(newsub)
511 if oldsub == newsub and l >= k then
512 match = true
513 elseif oldfirst == newfirst and string.len(newfirst) >= MinFull then
514 match = true
515 oldsub = oldfirst
516 newsub = newfirst
517 k = string.len(newfirst)
518 end
519 if match then
520 local osub = oldsub
521 local nsub = newsub
522 while osub == nsub and k <= maxlen do
523 k = k + 1
524 osub = string.sub(old,1,k)
525 nsub = string.sub(new,1,k)
526 if osub == nsub then
527 newsub = nsub
528 end
529 end
530 pageflag = true
531 newsub = string.gsub(newsub, '_$', '') --$
532 oldsub = newsub
533 local newsub = ""
534 local k = string.len(oldsub)
535 local n = start
536 repeat
537 if n and n.id ~= GLUE then
538 color_node(n, COLOR)
539 l, newsub = signature(n, newsub, swap)
540 elseif n then
541 newsub = newsub .. "_"
542 end
543 n = n.next
544 until not n or newsub == oldsub or l >= k
545 end
546 end
547 return new
548 end
549 local check_regexpr = function (glyph)
550 local COLOR = luatypo.colortbl[3]
551 local lang = glyph.lang
552 local match = false
553 local lchar, id = is_glyph(glyph)
554 local previous = glyph.prev
555 if lang and luatypo.single[lang] then
556 if lchar and lchar < 0x100 and previous and previous.id == GLUE then
557 match = string.find(luatypo.single[lang], string.char(lchar))
558 if match then
559 pageflag = true
560 color_node(glyph,COLOR)
561 end
562 end
563 end
564 if lang and luatypo.double[lang] then
565 if lchar and previous and previous.id == GLYPH then
566 local pchar, id = is_glyph(previous)
567 local pprev = previous.prev
568 if pchar and pchar < 0x100 and pprev and pprev.id == GLUE then
569 local pattern = string.char(pchar) .. string.char(lchar)
570 match = string.find(luatypo.double[lang], pattern)
571 if match then
572 pageflag = true
573 color_node(previous,COLOR)
574 color_node(glyph,COLOR)
575 end
576 end
577 elseif lchar and previous and previous.id == KERN then
578 local pprev = previous.prev
579 if pprev and pprev.id == GLYPH then
580 local pchar, id = is_glyph(pprev)
581 local ppprev = pprev.prev
582 if pchar and pchar < 0x100 and
583 ppprev and ppprev.id == GLUE then
584 local pattern = string.char(pchar) .. string.char(lchar)
585 match = string.find(luatypo.double[lang], pattern)
586 if match then
587 pageflag = true
588 color_node(pprev,COLOR)
589 color_node(glyph,COLOR)
590 end
591 end
592 end
593 end
594 end
595 end
596 local show_pre_disc = function (disc, color)
597 local n = disc
598 while n and n.id ~= GLUE do
599 color_node(n, color)
600 n = n.prev
601 end
602 return n
603 end
604 luatypo.check_page = function (head)
605 local PAGEmin = luatypo.PAGEmin
606 local HYPHmax = luatypo.HYPHmax
607 local LLminWD = luatypo.LLminWD
608 local BackPI = luatypo.BackPI
609 local BackFuzz = luatypo.BackFuzz
610 local BackParindent = luatypo.BackParindent
611 local ShortLines = luatypo.ShortLines
612 local ShortPages = luatypo.ShortPages
613 local OverfullLines = luatypo.OverfullLines
614 local UnderfullLines = luatypo.UnderfullLines
615 local Widows = luatypo.Widows
616 local Orphans = luatypo.Orphans
617 local EOPHyphens = luatypo.EOPHyphens
618 local RepeatedHyphens = luatypo.RepeatedHyphens
619 local FirstWordMatch = luatypo.FirstWordMatch
620 local ParLastHyphen = luatypo.ParLastHyphen
621 local EOLShortWords = luatypo.EOLShortWords
622 local LastWordMatch = luatypo.LastWordMatch
623 local pageno = tex.getcount("c@page")
624 local Stretch = math.max(luatypo.Stretch/100,1)
625 local blskip = tex.getglue("baselineskip")
626 local textht = tex.getdimen("textheight")
627 local vpos_min = (PAGEmin+1) * blskip
628 local vpos = 0
629
630 local pageflag = false
631 local orphanflag = false
632 local widowflag = false
633 local lwhyphflag = false
634 local pageshort = false
635 local firstwd = ""
636 local lastwd = ""
637 local hyphcount = 0
638 local pageline = 0
639
640 while head do
641 local nextnode = head.next
642 local prevnode = head.prev
643 local pprevnode = nil
644 if prevnode then
645 pprevnode = prevnode.prev
646 end
647 if head.id == HLIST and head.subtype == LINE then
648 vpos = vpos + head.height + head.depth
649 local first = head.head
650 while first.id == MKERN or
651 (first.id == GLUE and first.subtype == LFTSKIP) do
652 first = first.next
653 end
654 local ListItem = false
655 pageline = pageline + 1
656 if head.glue_set == 1 and head.glue_sign == 2 and
657 head.glue_order == 0 and OverfullLines then
658 pageflag = true
659 local COLOR = luatypo.colortbl[7]
660 color_line (head, COLOR)
661 elseif head.glue_set >= Stretch and head.glue_sign == 1 and
662 head.glue_order == 0 and UnderfullLines then
663 local COLOR = luatypo.colortbl[8]
664 pageflag = true
665 color_line (head, COLOR)
666 end
667 if first.id == LPAR then
668 hyphcount = 0
669 parline = 1
670 if not nextnode then
671 orphanflag = true
672 end
673 local nn = first.next
674 if nn and nn.id == HLIST and nn.subtype == BOX then
675 ListItem = true
676 end
677 else
678 parline = parline + 1
679 end
680 if FirstWordMatch then
681 local flag = not ListItem
682 firstwd = check_first_word(firstwd, first, flag)
683 end
684 local ln = slide(first)
685 local pn = ln.prev
686 if pn and pn.id == GLUE and pn.subtype == PARFILL then
687 hyphcount = 0
688 orphanflag = false
689 if pageline == 1 and parline > 1 then
690 widowflag = true
691 end
692 local PFskip = effective_glue(pn,head)
693 if ShortLines then
694 local llwd = tex.hsize - PFskip
695 if llwd < LLminWD then
696 pageflag = true
697 local COLOR = luatypo.colortbl[6]
698 local attr = oberdiek.luacolor.getattribute()
699 color_line (head, COLOR)
700 end
701 end
702 if BackParindent and PFskip < BackPI and PFskip > BackFuzz then
703 pageflag = true
704 local COLOR = luatypo.colortbl[12]
705 local attr = oberdiek.luacolor.getattribute()
706 color_line (head, COLOR)
707 end
708 if LastWordMatch then
709 local flag = textline
710 if PFskip > BackPI then
711 flag = false
712 end
713 lastwd = check_last_word(lastwd, pn, flag)
714 end
715 elseif pn and pn.id == DISC then
716 hyphcount = hyphcount + 1
717 if LastWordMatch then
718 lastwd = check_last_word(lastwd, ln, true)
719 end
720 if hyphcount > HYPHmax and RepeatedHyphens then
721 local COLOR = luatypo.colortbl[2]
722 local pg = show_pre_disc (pn,COLOR)
723 pageflag = true
724 end
725 if not nextnode and EOPHyphens then
726 lwhyphflag = true
727 end
728 if nextnode and ParLastHyphen then
729 local nnnode = nextnode.next
730 local nnnnode = nil
731 if nnnode and nnnode.next then
732 nnnnode = nnnode.next
733 if nnnnode and nnnnode.id == HLIST and
734 nnnnode.subtype == 1 and nnnnode.glue_order == 2 then
735 local COLOR = luatypo.colortbl[0]
736 local pg = show_pre_disc (pn,COLOR)
737 pageflag = true
738 end
739 end
740 end
741 else
742 hyphcount = 0
743 if LastWordMatch and pn then
744 lastwd = check_last_word(lastwd, pn, true)
745 end
746 if EOLShortWords then
747 while pn and pn.id ~= GLYPH and pn.id ~= HLIST do
748 pn = pn.prev
749 end
750 if pn and pn.id == GLYPH then
751 check_regexpr(pn,line)
752 end
753 end
754 end
755 if widowflag and Widows then
756 pageflag = true
757 widowflag = false
758 local COLOR = luatypo.colortbl[4]
759 color_line (head, COLOR)
760 end
761 if orphanflag and Orphans then
762 pageflag = true
763 local COLOR = luatypo.colortbl[5]
764 color_line (head, COLOR)
765 end
766 if lwhyphflag and EOPHyphens then
767 pageflag = true
768 local COLOR = luatypo.colortbl[1]
769 local pg = show_pre_disc (pn,COLOR)
770 end
771 elseif head.id == GLUE and head.subtype == USRSKIP then
772 vpos = vpos + head.width
773 if not nextnode and ShortPages and
774 pageline > 1 and pageline < PAGEmin then
775 pageshort = true
776 end
777 if pageshort and vpos < vpos_min then
778 pageflag = true
779 local COLOR = luatypo.colortbl[9]
780 local n = head
781 repeat
782 n = n.prev
783 until n.id == HLIST and (n.subtype == LINE or n.subtype == EQN)
784 if n then
785 color_line(n, COLOR)
786 end
787 end
788 elseif head.id == GLUE then
789 vpos = vpos + head.width
790 end
791 head = nextnode
792 end
793 if pageflag then
794 local pl = luatypo.pagelist
795 local p = tonumber(string.match(pl, "%s(%d+),%s$"))
796 if not p or pageno > p then
797 luatypo.pagelist = luatypo.pagelist .. tostring(pageno) .. ", "
798 end
799 end
800 return true
801 end
802 return luatypo.check_page
803 \end{luacode}
804 \AtEndOfPackage{%
805 \directlua{
806 if not luatypo.None then
807 luatexbase.add_to_callback
808 ("pre_output_filter",luatypo.check_page,"check_page")
809 end
810 }
811 }
812
813 \InputIfFileExists{lua-typo.cfg}%
814 {\PackageInfo{lua-typo.sty}{'lua-typo.cfg' file loaded}}%
815 {\PackageInfo{lua-typo.sty}{'lua-typo.cfg' file not found.
816 \MessageBreak Providing default values.}%
817 \definecolor{mygrey}{gray}{0.6}%
818 \definecolor{myred}{rgb}{1,0.55,0}
819 \luatypoSetColor0{red}% Paragraph last full line hyphenated
820 \luatypoSetColor1{red}% Page last word hyphenated
821 \luatypoSetColor2{red}% Hyphens ending two many consecutive lines
822 \luatypoSetColor3{red}% Short word at end of line
823 \luatypoSetColor4{cyan}% Widow
824 \luatypoSetColor5{cyan}% Orphan
825 \luatypoSetColor6{cyan}% Paragraph ending on a short line
826 \luatypoSetColor7{blue}% Overfull lines
827 \luatypoSetColor8{blue}% Underfull lines
828 \luatypoSetColor9{red}% Nearly empty page
829 \luatypoSetColor{10}{myred}% First word matches
830 \luatypoSetColor{11}{myred}% Last word matches
831 \luatypoSetColor{12}{mygrey}% Paragraph ending on a nearly full line
832 \luatypoBackPI=1em\relax
833 \luatypoBackFuzz=2pt\relax
834 \luatypoLLminWD=2\parindent\relax
835 \luatypoStretchMax=200\relax
836 \luatypoHyphMax=2\relax
837 \luatypoPageMin=5\relax
838 \luatypoMinFull=4\relax
839 \luatypoMinPART=4\relax
840 }%
841 %%
842 %%
843 %% End of file `lua-typo.sty'.