Debian Codegraph @

texmf-dist/source/generic/hyphenex/hyphenex.pl

raw
1 #! /usr/bin/env perl
2 #
3 # hyphenex.pl
4 #
5 # This small filter converts a hyphenation exception log article for
6 # TUGBoat to a real \hyphenation block.
7 #
8 # Written by Werner Lemberg <[email protected]>.
9 #
10 # Version 1.3 (2008/05/20)
11 #
12 # Public domain.
13 #
14 #
15 # Usage:
16 # perl hyphenex.pl < tugboat-article > hyphenation-exceptions
17
18 # print header
19 print "% Hyphenation exceptions for US English,\n";
20 print "% based on hyphenation exception log articles in TUGboat.\n";
21 print "%\n";
22 print "% Copyright 2021 TeX Users Group.\n";
23 print "% You may freely use, modify and/or distribute this file.\n";
24 print "%\n";
25 print "% This is an automatically generated file. Do not edit!\n";
26 print "%\n";
27 print "% Please contact the TUGboat editorial staff <tugboat\@tug.org>\n";
28 print "% for corrections and omissions.\n";
29 print "\n";
30 print "\\hyphenation{\n";
31
32 while (<>) {
33 # retain only lines starting with \1 ... \6 or \tabalign
34 next if not (m/^\\[123456]/ || m/^\\tabalign/);
35 # remove final newline
36 chop;
37 # remove all TeX commands except \1 ... \6
38 s/\\[^123456\s{]+//g;
39 # remove all paired { ... }
40 1 while s/{(.*?)}/\1/g;
41 # skip lines which now have only whitespace before `&'
42 next if m/^\s*&/;
43 # remove comments
44 s/%.*//;
45 # remove trailing whitespace
46 s/\s*$//;
47 # remove trailing `*' (used as a marker in the document)
48 s/\*$//;
49 # split at whitespace
50 @field = split(' ');
51 if ($field[0] eq "\\1" || $field[0] eq "\\4") {
52 print " $field[2]\n";
53 }
54 elsif ($field[0] eq "\\2" || $field[0] eq "\\5") {
55 print " $field[2]\n";
56 # handle multiple suffixes separated by commata
57 @suffix_list = split(/,/, "$field[3]");
58 foreach $suffix (@suffix_list) {
59 print " $field[2]$suffix\n";
60 }
61 }
62 elsif ($field[0] eq "\\3" || $field[0] eq "\\6") {
63 # handle multiple suffixes separated by commata
64 @suffix_list = split(/,/, "$field[3],$field[4]");
65 foreach $suffix (@suffix_list) {
66 print " $field[2]$suffix\n";
67 }
68 }
69 else {
70 # for `&', split at `&' with trailing whitespace
71 @field = split(/&\s*/);
72 print " $field[1]\n";
73 }
74 }
75
76 # print trailer
77 print "}\n";
78 print "\n";
79 print "% EOF\n";