summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb
blob: c0781932a384c4721af5ea1607398dacdcdf8ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env ruby
# encoding: utf-8

# this file auto-generates loaders for hyphenation patterns - to be improved # No shit, Sherlock -- AR 2018-11-27

require_relative 'lib/tex/hyphen'
require_relative 'lib/tex/hyphen/texlive'
include TeX::Hyphen
include TeXLive

#text_if_native_utf = "\input pattern-loader.tex\n\\ifNativeUtfEightPatterns"

def output(file, string, indent = 0)
  if string.is_a? Enumerable
    string.each { |line| output(file, line, indent) }
  else
    file.print '  ' * indent
    file.puts(string)
  end
end

print 'Generating loaders for '
Language.all.each do |language|

# puts language.bcp47

################
# Header texts #
################

# a message about auto-generation
# TODO: write a more comprehensive one
  text_header = <<-EOHEADER
% filename: loadhyph-#{language.bcp47}.tex
% language: #{language.babelname}
%
% Loader for hyphenation patterns, generated by
%     source/generic/hyph-utf8/generate-pattern-loaders.rb
% See also http://tug.org/tex-hyphen
%
% Copyright 2008-#{Time.now.year} TeX Users Group.
% You may freely use, modify and/or distribute this file.
% (But consider adapting the scripts if you need modifications.)
%
% Once it turns out that more than a simple definition is needed,
% these lines may be moved to a separate file.
%
  EOHEADER

###########
# lccodes #
###########

  lccodes_common = []
  if language.has_apostrophes? then
    lccodes_common.push("\\lccode`\\'=`\\'")
  end
  if language.has_hyphens? then
    lccodes_common.push("\\lccode`\\-=`\\-")
  end

  next if language.use_old_loader
    print language.bcp47, ' '

    filename = File.join(PATH::LOADER, language.loadhyph)
    File.open(filename, "w") do |file|
      # puts language.bcp47
      file.puts text_header
      file.puts('\begingroup')

      if lccodes_common.length > 0 then
        file.puts lccodes_common.join("\n")
      end

      # for ASCII encoding, we don't load any special support files, but simply load everything
      if language.encoding == 'ascii' && !language.italic?
        file.puts "% ASCII patterns - no additional support is needed"
        file.puts "\\message{ASCII #{language.message}}"
        file.puts "\\input hyph-#{language.bcp47}.tex"
      else
        file.puts '% Test for pTeX
\\ifx\\kanjiskip\\undefined
% Test for native UTF-8 (which gets only a single argument)
% That\'s Tau (as in Taco or ΤΕΧ, Tau-Epsilon-Chi), a 2-byte UTF-8 character
\\def\\testengine#1#2!{\\def\\secondarg{#2}}\\testengine Τ!\\relax
\\ifx\\secondarg\\empty'
        output(file, language.format_inputs(language.utf8_chunk), 2)
        file.puts("\\else\n")
        output(file, language.format_inputs(language.nonutf8_chunk('8-bit')), 2)
        file.puts("\\fi\\else\n")
        output(file, language.format_inputs(language.nonutf8_chunk('pTeX')), 2)
        file.puts("\\fi\n")
      end

########################################
# GROUP nr. 1 - ONLY USABLE WITH UTF-8 #
########################################
      # some special cases first
      #
      # some languages (sanskrit) are useless in 8-bit engines; we only want to load them for UTF engines
      # TODO - maybe consider doing something similar for ibycus

#######################
# GROUP nr. 2 - ASCII #
#######################

####################################
# GROUP nr. 3 - different patterns #
####################################
      # when lanugage uses old patterns for 8-bit engines, load two different patterns rather than using the converter
        # greek, coptic
#########################
# GROUP nr. 4 - regular #
#########################
#######
# end #
#######
      file.puts('\endgroup')
    end
end

puts