summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb')
-rwxr-xr-xMaster/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb88
1 files changed, 30 insertions, 58 deletions
diff --git a/Master/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb b/Master/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb
index 1399280a5a8..e537fe43ba7 100755
--- a/Master/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb
+++ b/Master/texmf-dist/source/generic/hyph-utf8/generate-ptex-patterns.rb
@@ -1,19 +1,10 @@
#!/usr/bin/env ruby
-require File.expand_path(File.join(File.dirname(__FILE__), 'hyph-utf8'))
+require_relative 'hyph-utf8'
+require_relative 'languages'
# this file generates patterns for pTeX out of the plain ones
-# use 'gem install unicode' if unicode is missing on your computer
-# require 'jcode'
-# require 'rubygems'
-# require 'unicode'
-
-require_relative 'languages.rb'
-
-$path_root=File.expand_path("../../../..", __FILE__)
-$path_ptex="#{$path_root}/tex/generic/hyph-utf8/patterns/ptex"
-
# load encodings
encodings_list = ["ascii", "ec", "qx", "t2a", "lmc", "il2", "il3", "l7x", "t8m", "lth"]
encodings = Hash.new
@@ -21,46 +12,37 @@ encodings_list.each do |encoding_name|
encodings[encoding_name] = HyphEncoding.new(encoding_name)
end
-$l = Languages.new
-
-# TODO: should be singleton
-languages = $l.list.sort{|a,b| a.name <=> b.name}
-
-language_codes = Hash.new
-languages.each do |language|
- language_codes[language.code] = language.code
-end
-
-languages.sort{|x,y| x.code <=> y.code }.each do |language|
- encoding = nil
- if language.use_new_loader then
- if language.encoding == nil or language_codes[language.code] == nil
- include_language = false
- puts "(skipping #{language.code} # encoding)"
- elsif language.encoding == 'ascii'
- include_language = false
- puts "(skipping #{language.code} # ascii)"
- else
- include_language = true
- encoding = encodings[language.encoding]
- end
- else
- include_language = false
+header = <<-HEADER
+%% pTeX-friendly hyphenation patterns
+%%
+%% language: %s (%s)
+%% encoding: %s
+%%
+%% This file has been auto-generated from hyph-%s.tex
+%% with a script [texmf]/scripts/generic/hyph-utf8/generate-ptex-patterns.rb
+%% See the original file for details about author, licence etc.
+%%
+HEADER
+
+Language.all.sort.each do |language|
+ if language.use_old_loader
puts "(skipping #{language.code} # loader)"
+ next
end
- code = language_codes[language.code]
-
- if include_language
- puts ">> generating #{code} (#{language.name})"
- file_ptex = File.open("#{$path_ptex}/hyph-#{code}.#{language.encoding}.tex", "w")
+ if language.encoding == nil || language.encoding == 'ascii'
+ puts "(skipping #{language.code} # #{if language.encoding then 'ascii' else 'encoding' end})"
+ next
+ else
+ encoding = encodings[language.encoding]
+ end
- patterns = language.get_patterns
- exceptions = language.get_exceptions
+ code = language.code
- if code == 'nn' or code == 'nb'
- patterns = $l['no'].get_patterns
- end
+ puts ">> generating #{code} (#{language.name.safe})"
+ File.open(File.join(PATH::PTEX, sprintf('hyph-%s.%s.tex', code, language.encoding)), 'w') do |file_ptex|
+ patterns = language.patterns
+ exceptions = language.exceptions
characters = patterns.join('').gsub(/[.0-9]/,'').unpack('U*').sort.uniq
@@ -69,15 +51,7 @@ languages.sort{|x,y| x.code <=> y.code }.each do |language|
exceptions = encoding.convert_to_escaped_characters(exceptions)
end
- file_ptex.puts("% pTeX-friendly hyphenation patterns")
- file_ptex.puts("%")
- file_ptex.puts("% language: #{language.name} (#{language.code})")
- file_ptex.puts("% encoding: #{language.encoding}")
- file_ptex.puts("%")
- file_ptex.puts("% This file has been auto-generated from hyph-#{language.code}.tex")
- file_ptex.puts("% with a script [texmf]/scripts/generic/hyph-utf8/generate-ptex-patterns.rb")
- file_ptex.puts("% See the original file for details about author, licence etc.")
- file_ptex.puts("%")
+ file_ptex.printf(header, language.name.safe, language.code, language.encoding, language.code)
file_ptex.puts("\\bgroup")
# setting lccodes for letters
@@ -86,7 +60,7 @@ languages.sort{|x,y| x.code <=> y.code }.each do |language|
# skip
elsif c >= 128 then
code = encoding.unicode_characters[c].code_enc
- file_ptex.puts sprintf("\\lccode\"%02X=\"%02X", code, code)
+ file_ptex.printf("\\lccode\"%02X=\"%02X\n", code, code)
end
end
# patterns
@@ -98,7 +72,5 @@ languages.sort{|x,y| x.code <=> y.code }.each do |language|
file_ptex.puts("\\hyphenation{\n#{exceptions.join("\n")}\n}")
end
file_ptex.puts("\\egroup")
-
- file_ptex.close
end
end