| 1 |
#!/usr/bin/env ruby |
| 2 |
# encoding: utf-8 |
| 3 |
|
| 4 |
# this file auto-generates loaders for hyphenation patterns - to be improved # No shit, Sherlock -- AR 2018-11-27 |
| 5 |
|
| 6 |
require_relative 'lib/tex/hyphen' |
| 7 |
require_relative 'lib/tex/hyphen/texlive' |
| 8 |
include TeX::Hyphen |
| 9 |
include TeXLive |
| 10 |
|
| 11 |
#text_if_native_utf = "\input pattern-loader.tex\n\\ifNativeUtfEightPatterns" |
| 12 |
|
| 13 |
def output(file, string, indent = 0) |
| 14 |
if string.is_a? Enumerable |
| 15 |
string.each { |line| output(file, line, indent) } |
| 16 |
else |
| 17 |
file.print ' ' * indent |
| 18 |
file.puts(string) |
| 19 |
end |
| 20 |
end |
| 21 |
|
| 22 |
print '[1;36mGenerating[0m [0;34mloaders[0m for ' |
| 23 |
Language.all.each do |language| |
| 24 |
|
| 25 |
# puts language.bcp47 |
| 26 |
|
| 27 |
################ |
| 28 |
# Header texts # |
| 29 |
################ |
| 30 |
|
| 31 |
# a message about auto-generation |
| 32 |
# TODO: write a more comprehensive one |
| 33 |
text_header = <<-EOHEADER |
| 34 |
% filename: loadhyph-#{language.bcp47}.tex |
| 35 |
% language: #{language.babelname} |
| 36 |
% |
| 37 |
% Loader for hyphenation patterns, generated by |
| 38 |
% source/generic/hyph-utf8/generate-pattern-loaders.rb |
| 39 |
% See also http://tug.org/tex-hyphen |
| 40 |
% |
| 41 |
% Copyright 2008-#{Time.now.year} TeX Users Group. |
| 42 |
% You may freely use, modify and/or distribute this file. |
| 43 |
% (But consider adapting the scripts if you need modifications.) |
| 44 |
% |
| 45 |
% Once it turns out that more than a simple definition is needed, |
| 46 |
% these lines may be moved to a separate file. |
| 47 |
% |
| 48 |
EOHEADER |
| 49 |
|
| 50 |
########### |
| 51 |
# lccodes # |
| 52 |
########### |
| 53 |
|
| 54 |
lccodes_common = [] |
| 55 |
if language.has_apostrophes? then |
| 56 |
lccodes_common.push("\\lccode`\\'=`\\'") |
| 57 |
end |
| 58 |
if language.has_hyphens? then |
| 59 |
lccodes_common.push("\\lccode`\\-=`\\-") |
| 60 |
end |
| 61 |
|
| 62 |
next if language.use_old_loader |
| 63 |
print '[0;32m', language.bcp47, '[0m ' |
| 64 |
|
| 65 |
filename = File.join(PATH::LOADER, language.loadhyph) |
| 66 |
File.open(filename, "w") do |file| |
| 67 |
# puts language.bcp47 |
| 68 |
file.puts text_header |
| 69 |
file.puts('\begingroup') |
| 70 |
|
| 71 |
if lccodes_common.length > 0 then |
| 72 |
file.puts lccodes_common.join("\n") |
| 73 |
end |
| 74 |
|
| 75 |
# for ASCII encoding, we don't load any special support files, but simply load everything |
| 76 |
if language.encoding == 'ascii' && !language.italic? |
| 77 |
file.puts "% ASCII patterns - no additional support is needed" |
| 78 |
file.puts "\\message{ASCII #{language.message}}" |
| 79 |
file.puts "\\input hyph-#{language.bcp47}.tex" |
| 80 |
else |
| 81 |
file.puts '% Test for pTeX |
| 82 |
\\ifx\\kanjiskip\\undefined |
| 83 |
% Test for native UTF-8 (which gets only a single argument) |
| 84 |
% That\'s Tau (as in Taco or ΤΕΧ, Tau-Epsilon-Chi), a 2-byte UTF-8 character |
| 85 |
\\def\\testengine#1#2!{\\def\\secondarg{#2}}\\testengine Τ!\\relax |
| 86 |
\\ifx\\secondarg\\empty' |
| 87 |
# byebug if language.bcp47 == 'zh-latn-pinyin' |
| 88 |
output(file, language.format_inputs(language.utf8_chunk), 2) |
| 89 |
file.puts("\\else\n") |
| 90 |
output(file, language.format_inputs(language.nonutf8_chunk('8-bit')), 2) |
| 91 |
file.puts("\\fi\\else\n") |
| 92 |
output(file, language.format_inputs(language.nonutf8_chunk('pTeX')), 2) |
| 93 |
file.puts("\\fi\n") |
| 94 |
end |
| 95 |
|
| 96 |
######################################## |
| 97 |
# GROUP nr. 1 - ONLY USABLE WITH UTF-8 # |
| 98 |
######################################## |
| 99 |
# some special cases first |
| 100 |
# |
| 101 |
# some languages (sanskrit) are useless in 8-bit engines; we only want to load them for UTF engines |
| 102 |
# TODO - maybe consider doing something similar for ibycus |
| 103 |
|
| 104 |
####################### |
| 105 |
# GROUP nr. 2 - ASCII # |
| 106 |
####################### |
| 107 |
|
| 108 |
#################################### |
| 109 |
# GROUP nr. 3 - different patterns # |
| 110 |
#################################### |
| 111 |
# when lanugage uses old patterns for 8-bit engines, load two different patterns rather than using the converter |
| 112 |
# greek, coptic |
| 113 |
######################### |
| 114 |
# GROUP nr. 4 - regular # |
| 115 |
######################### |
| 116 |
####### |
| 117 |
# end # |
| 118 |
####### |
| 119 |
file.puts('\endgroup') |
| 120 |
end |
| 121 |
end |
| 122 |
|
| 123 |
puts |