| 1 |
#!/usr/bin/env ruby |
| 2 |
|
| 3 |
require_relative 'hyph-utf8' |
| 4 |
require_relative 'lib/tex/hyphen' |
| 5 |
require_relative 'lib/tex/hyphen/texlive' |
| 6 |
include TeX::Hyphen |
| 7 |
include TeXLive |
| 8 |
|
| 9 |
# this file generates patterns for pTeX out of the plain ones |
| 10 |
|
| 11 |
# load encodings |
| 12 |
encodings_list = |
| 13 |
Dir.glob(File.expand_path(File.join(__dir__, 'data/encodings/*.dat'))).map do |encdat| |
| 14 |
encdat.gsub /^.*\/(.*)\.dat$/, '\1' |
| 15 |
end |
| 16 |
encodings = Hash.new |
| 17 |
encodings_list.each do |encoding_name| |
| 18 |
encodings[encoding_name] = HyphEncoding.new(encoding_name) |
| 19 |
end |
| 20 |
|
| 21 |
header = <<-HEADER |
| 22 |
%% pTeX-friendly hyphenation patterns |
| 23 |
%% |
| 24 |
%% language: %s (%s) |
| 25 |
%% encoding: %s |
| 26 |
%% |
| 27 |
%% This file has been auto-generated from hyph-%s.tex |
| 28 |
%% with a script [texmf]/scripts/generic/hyph-utf8/generate-ptex-patterns.rb |
| 29 |
%% See the original file for details about author, licence etc. |
| 30 |
%% |
| 31 |
HEADER |
| 32 |
|
| 33 |
print '[1;36mGenerating [0;34mpTeX patterns[0m for (skipped # reason): ' |
| 34 |
Language.all.sort.each do |language| |
| 35 |
if language.use_old_patterns_comment || !language.encoding || language.encoding == 'ascii' |
| 36 |
if language.use_old_patterns_comment # FIXME This skips [de-1996] and [de-1901]!! |
| 37 |
reason = 'legacy patterns' |
| 38 |
else |
| 39 |
reason = sprintf 'encoding: %s', language.encoding.inspect |
| 40 |
end |
| 41 |
print '([0;31m', language.bcp47, '[0m [0;35m# ', reason, '[0m) ' |
| 42 |
|
| 43 |
next |
| 44 |
else |
| 45 |
encoding = encodings[language.encoding] |
| 46 |
end |
| 47 |
|
| 48 |
bcp47 = language.bcp47 |
| 49 |
|
| 50 |
print '[0;32m', bcp47, '[0m ' |
| 51 |
File.open(File.join(PATH::PTEX, sprintf('hyph-%s.%s.tex', bcp47, language.encoding)), 'w') do |file_ptex| |
| 52 |
patterns = language.patterns |
| 53 |
exceptions = language.exceptions |
| 54 |
|
| 55 |
characters = patterns.join('').gsub(/[.0-9]/,'').unpack('U*').sort.uniq |
| 56 |
|
| 57 |
if language.encoding != 'ascii' then |
| 58 |
patterns = encoding.convert_to_escaped_characters(patterns) |
| 59 |
exceptions = encoding.convert_to_escaped_characters(exceptions) |
| 60 |
end |
| 61 |
|
| 62 |
file_ptex.printf(header, language.babelname, language.bcp47, language.encoding, language.bcp47) |
| 63 |
|
| 64 |
file_ptex.puts("\\bgroup") |
| 65 |
# setting lccodes for letters |
| 66 |
characters.each do |c| |
| 67 |
if (c == 0x01FD or c == 0x0301) and language.bcp47 == 'la-x-liturgic' |
| 68 |
# skip |
| 69 |
elsif c >= 128 then |
| 70 |
code = encoding.unicode_characters[c].code_enc |
| 71 |
file_ptex.printf("\\lccode\"%02X=\"%02X\n", code, code) |
| 72 |
end |
| 73 |
end |
| 74 |
# patterns |
| 75 |
if patterns.length > 0 then |
| 76 |
file_ptex.puts("\\patterns{\n#{patterns.join("\n")}\n}") |
| 77 |
end |
| 78 |
# exceptions |
| 79 |
if exceptions.length > 0 then |
| 80 |
file_ptex.puts("\\hyphenation{\n#{exceptions.join("\n")}\n}") |
| 81 |
end |
| 82 |
file_ptex.puts("\\egroup") |
| 83 |
end |
| 84 |
end |
| 85 |
puts |