| 1 |
module TeX |
| 2 |
module Hyphen |
| 3 |
module TeXLive |
| 4 |
module Source |
| 5 |
def path(type, file) |
| 6 |
File.join(PATH::HYPHU8, 'patterns', type, file) |
| 7 |
end |
| 8 |
|
| 9 |
def list_synonyms |
| 10 |
if synonyms && synonyms.length > 0 |
| 11 |
sprintf " synonyms=%s", synonyms.join(',') |
| 12 |
else |
| 13 |
'' |
| 14 |
end |
| 15 |
end |
| 16 |
|
| 17 |
def list_hyphenmins |
| 18 |
lmin = lefthyphenmin |
| 19 |
rmin = righthyphenmin |
| 20 |
sprintf "lefthyphenmin=%s \\\n\trighthyphenmin=%s", lmin, rmin |
| 21 |
end |
| 22 |
|
| 23 |
# ext: 'pat' or 'hyp' |
| 24 |
# filetype: 'patterns' or 'exceptions' |
| 25 |
def plain_text_line(ext, filetype) # TODO Figure out if we will sr-cyrl to be generated again |
| 26 |
return "" if use_old_loader || luaspecial |
| 27 |
|
| 28 |
if @bcp47 =~ /^sh-/ |
| 29 |
# TODO Warning AR 2018-09-12 |
| 30 |
filename = sprintf 'hyph-sh-latn.%s.txt,hyph-sh-cyrl.%s.txt', ext, ext |
| 31 |
else |
| 32 |
filename = sprintf 'hyph-%s.%s.txt', @bcp47, ext |
| 33 |
filepath = File.join(PATH::TXT, filename) |
| 34 |
# check for existence of file and that it’s not empty |
| 35 |
unless File.file?(filepath) && File.read(filepath).length > 0 |
| 36 |
# if the file we were looking for was a pattern file, something’s wrong |
| 37 |
if ext == 'pat' |
| 38 |
raise sprintf("There is some problem with plain patterns for language [%s]!!!", @bcp47) |
| 39 |
else # the file is simply an exception file and we’re happy |
| 40 |
filename = '' # And we return and empty file name after all |
| 41 |
end |
| 42 |
end |
| 43 |
end |
| 44 |
|
| 45 |
sprintf "file_%s=%s", filetype, filename |
| 46 |
end |
| 47 |
|
| 48 |
def exceptions_line |
| 49 |
plain_text_line('hyp', 'exceptions') |
| 50 |
end |
| 51 |
|
| 52 |
def patterns_line |
| 53 |
plain_text_line('pat', 'patterns') |
| 54 |
end |
| 55 |
|
| 56 |
def pTeX_patterns |
| 57 |
if italic? |
| 58 |
sprintf 'hyph-%s.tex', @bcp47 |
| 59 |
elsif encoding |
| 60 |
sprintf 'hyph-%s.%s.tex', @bcp47, encoding |
| 61 |
else |
| 62 |
legacy_patterns |
| 63 |
end |
| 64 |
end |
| 65 |
|
| 66 |
def list_loader |
| 67 |
# which loader to use |
| 68 |
if luaspecial |
| 69 |
return "file=#{loadhyph} \\\n\tluaspecial=\"#{luaspecial}\"" |
| 70 |
else |
| 71 |
sprintf "file=%s", loadhyph |
| 72 |
end |
| 73 |
end |
| 74 |
|
| 75 |
def list_run_files |
| 76 |
# byebug if @bcp47 == "grc-x-ibycus" |
| 77 |
if use_old_loader |
| 78 |
unless @bcp47 == "grc-x-ibycus" # FIXME AR 2025-03-31 |
| 79 |
return [path('tex', "hyph-#{@bcp47}.tex")] |
| 80 |
else |
| 81 |
return [] |
| 82 |
end |
| 83 |
end |
| 84 |
|
| 85 |
files = [File.join(PATH::HYPHU8, 'loadhyph', loadhyph)] |
| 86 |
|
| 87 |
if has_apostrophes? |
| 88 |
files << path('quote', sprintf("hyph-quote-%s.tex", bcp47)) |
| 89 |
end |
| 90 |
|
| 91 |
# byebug if @bcp47 =~ /^grc/ |
| 92 |
files << path('tex', sprintf('hyph-%s.tex', bcp47)) # unless @bcp47 == "grc-x-ibycus" # FIXME AR 2025-03-31 |
| 93 |
Dir.glob(File.join('hyph-utf8', path('ptex', "hyph-#{bcp47}.*.tex"))) do |file| |
| 94 |
files << file.gsub(/^hyph-utf8\//, '') |
| 95 |
end |
| 96 |
if legacy_patterns |
| 97 |
Dir.glob(File.join('hyph-utf8', path('tex-8bit', legacy_patterns.to_s))) do |file| |
| 98 |
files << file.gsub(/^hyph-utf8\//, '') |
| 99 |
end |
| 100 |
end |
| 101 |
|
| 102 |
['pat', 'hyp'].each do |t| |
| 103 |
file = path('txt', sprintf('hyph-%s.%s.txt', bcp47, t)) |
| 104 |
files << file if File.exist? File.join('hyph-utf8', file) |
| 105 |
end |
| 106 |
|
| 107 |
# TODO AR 2026-02-20 Remove after TeX Live freeze? |
| 108 |
if bcp47 =~ /^sh-/ |
| 109 |
# duplicate entries (will be removed later) |
| 110 |
files << path('tex', 'hyph-sr-cyrl.tex') |
| 111 |
['pat', 'hyp'].each do |t| |
| 112 |
# duplicate entries (will be removed later) |
| 113 |
files << path('txt', sprintf('hyph-sr-cyrl.%s.txt', t)) |
| 114 |
end |
| 115 |
end |
| 116 |
|
| 117 |
files |
| 118 |
end |
| 119 |
|
| 120 |
def package |
| 121 |
extract_metadata unless @package |
| 122 |
@package |
| 123 |
end |
| 124 |
end |
| 125 |
end |
| 126 |
end |
| 127 |
end |