summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2008-06-22 12:52:56 +0000
committerKarl Berry <karl@freefriends.org>2008-06-22 12:52:56 +0000
commit5ed8932132aaa734b293e7a41dd1b6f885a6f2e9 (patch)
tree915e90fe24729ecc97114902b76b4004c712b024 /Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb
parenta84aa35db647cc419c465bd3e4b9db1bc86c0c0b (diff)
hyph-utf8 from CTAN
git-svn-id: svn://tug.org/texlive/trunk@8932 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb')
-rw-r--r--Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb112
1 files changed, 112 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb b/Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb
new file mode 100644
index 00000000000..f00a19d3e68
--- /dev/null
+++ b/Master/texmf-dist/source/generic/hyph-utf8/generate-pattern-loaders.rb
@@ -0,0 +1,112 @@
+#!/usr/bin/env ruby
+
+# this file auto-generates loaders for hyphenation patterns - to be improved
+
+load 'languages.rb'
+
+$package_name="hyph-utf8"
+
+
+# TODO - make this a bit less hard-coded
+$path_tex_generic="../../../tex/generic"
+$path_loadhyph="#{$path_tex_generic}/#{$package_name}/loadhyph"
+
+# TODO: should be singleton
+languages = Languages.new.list
+
+#text_if_native_utf = "\input pattern-loader.tex\n\\ifNativeUtfEightPatterns"
+
+text_if_native_utf = <<EOT
+% Test whether we received one or two arguments
+\\def\\testengine#1#2!{\\def\\secondarg{#2}}
+% That's Tau (as in Taco or ΤΕΧ, Tau-Epsilon-Chi), a 2-byte UTF-8 character
+\\testengine Τ!\\relax
+% Unicode-aware engine (such as XeTeX or LuaTeX) only sees a single (2-byte) argument
+\\ifx\\secondarg\\empty
+EOT
+
+languages.each do |language|
+ if language.use_new_loader then
+ filename = "#{$path_loadhyph}/loadhyph-#{language.code}.tex"
+ puts "generating '#{filename}'"
+ File.open(filename, "w") do |file|
+ # a message about auto-generation
+ # TODO: write a more comprehensive one
+ file.puts "% loadhyph-#{language.code}.tex"
+ file.puts "%"
+ file.puts "% Autogenerated loader for hyphenation patterns for \"#{language.name}\""
+ file.puts "% by source/generic/hyph-utf8/generate-pattern-loaders.rb"
+ file.puts "% See also http://tug.org/tex-hyphen"
+ file.puts "%"
+ file.puts "% Copyright 2008 TeX Users Group."
+ file.puts "% You may freely use, modify and/or distribute this file."
+ file.puts "% (But consider adapting the scripts if you need modifications.)"
+ file.puts "%"
+ file.puts "% Once it turns out that more than a simple definition is needed,"
+ file.puts "% these lines may be moved to a separate file."
+ file.puts "%"
+
+ # message (where it exists)
+ # if language.message != nil
+ # file.puts("\\message{#{language.message}}\n%")
+ # end
+
+ # TODO:
+ # \lefthyphenmin=2 \righthyphenmin=2
+ # but probably this needs to reside outside of \begingroup/endgroup
+
+ file.puts('\begingroup')
+ if language.code == 'it' or language.code == 'fr' or language.code == 'uk' or language.code == 'la' or language.code == 'zh-latn' then
+ file.puts("\\lccode`\\'=`\\'")
+ end
+ if language.code == 'pt' then
+ file.puts("\\lccode`\\-=`\\-")
+ end
+
+ if language.encoding == "ascii" then
+ file.puts('% ASCII patterns - no additional support is needed')
+ if language.use_old_patterns then
+ file.puts("\\input #{language.filename_old_patterns}")
+ else
+ file.puts("\\message{ASCII #{language.message}}")
+ file.puts("\\input hyph-#{language.code}.tex")
+ end
+ elsif language.use_old_patterns then
+ file.puts(text_if_native_utf)
+ file.puts(" \\message{UTF-8 #{language.message}}")
+ if language.code == 'grc' or language.code.slice(0,2) == 'el' then
+ file.puts(" \\lccode`'=`'\\lccode`’=`’\\lccode`ʼ=`ʼ\\lccode`᾽=`᾽\\lccode`᾿=`᾿")
+ end
+ file.puts(" \\input hyph-#{language.code}.tex")
+ file.puts('\else')
+ file.puts(" \\message{#{language.message}}")
+ # explain why we are still using the old patterns
+ if language.use_old_patterns_comment != nil then
+ file.puts(" % #{language.use_old_patterns_comment}")
+ else
+ puts "Missing comment for #{language.name}"
+ file.puts(' % we still load old patterns for 8-bit TeX')
+ end
+ file.puts(" \\input #{language.filename_old_patterns}")
+ file.puts('\fi')
+ else
+ file.puts(text_if_native_utf)
+ file.puts(" \\message{UTF-8 #{language.message}}")
+ file.puts('\else')
+ file.puts(" \\message{#{language.encoding.upcase} #{language.message}}")
+ file.puts(" \\input conv-utf8-#{language.encoding}.tex")
+ file.puts('\fi')
+ if language.code == 'sr-latn' then
+ file.puts("% Load Serbo-Croatian patterns")
+ file.puts("\\input hyph-hbs.tex")
+ else
+ file.puts("\\input hyph-#{language.code}.tex")
+ end
+# file.puts("\\loadhyphpatterns{#{language.code}}{#{language.encoding}}%")
+ end
+ file.puts('\endgroup')
+ end
+ end
+end
+
+