summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luavlna/luavlna.tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-10-29 21:22:13 +0000
committerKarl Berry <karl@freefriends.org>2019-10-29 21:22:13 +0000
commit25f69aadc674dbb748d19b87ad5723f8381df52b (patch)
tree8922262309859419e0c6fd8a01ff33d503dad238 /Master/texmf-dist/tex/luatex/luavlna/luavlna.tex
parent3c1bc4c2ad1fbb0fe57314a61719abfdd3bdf96a (diff)
luavlna.tex in runtime
git-svn-id: svn://tug.org/texlive/trunk@52569 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luavlna/luavlna.tex')
-rw-r--r--Master/texmf-dist/tex/luatex/luavlna/luavlna.tex123
1 files changed, 123 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/luatex/luavlna/luavlna.tex b/Master/texmf-dist/tex/luatex/luavlna/luavlna.tex
new file mode 100644
index 00000000000..5159fbe5b54
--- /dev/null
+++ b/Master/texmf-dist/tex/luatex/luavlna/luavlna.tex
@@ -0,0 +1,123 @@
+% Modify pre_linebreak_filter callback so the spaces can be inserted
+\directlua{%
+luavlna = require "luavlna"
+langno = require "luavlna-langno"
+
+require "ltluatex"
+luatexbase.add_to_callback("pre_linebreak_filter", luavlna.preventsingle,"LuaVlna")
+luatexbase.add_to_callback("hyphenate", luavlna.split_hyphens, "allow hyphen breaks")
+% -- define the attribute number
+luavlna.preventsingleid = math.random(2^16)
+
+local languages = langno.load_languages()
+local get_lang_id = function(lang)
+ local langid = tonumber(lang)
+ if not tonumber(lang) then
+ langid = languages:get_number(lang)
+ end
+ return langid
+end
+
+% Process string and make table of enabled single letters
+% By default, spaces for all single letters are inserted
+% This can be modified with \singlechars macro
+set_singlechars = function(lang,chars)
+ local utf_gmatch = unicode.utf8.gmatch
+ % local langnumbers = languages.names
+ local langid = get_lang_id(lang)
+ if not langid then return nil, "Cannot find language number for: "..lang end
+ local chars = chars or ""
+ local singlechars = {}
+ local percent = string.char(37)
+ local alpha = percent .. "a"
+ for char in utf_gmatch(chars,"("..alpha..")") do
+ singlechars[char] = true
+ end
+ luavlna.singlechars(langid,singlechars)
+end
+
+% set compound characters for initials handling
+% useful for Czech "Ch" etc.
+% comma separated list of compounds
+set_compounds = function(lang, compounds)
+ local langid = get_lang_id(lang)
+ if not langid then return nil, "Cannot find language number for: "..lang end
+ local c = compounds:explode(",+") % match multiple colons as one
+ local compoundstable = {}
+ for _, compound in pairs(c) do
+ compoundstable[compound] = true
+ end
+ luavlna.initials(langid, compoundstable)
+end
+
+set_main_language = function(lang)
+ local langid = languages:get_number(lang)
+ if not langid then return nil, "Cannot find language number for: "..lang end
+ luavlna.set_main_language(langid)
+end
+
+enable_split_hyphens = function(lang)
+ local langid = get_lang_id(lang)
+ if not langid then return nil, "Cannot find language number for: "..lang end
+ luavlna.split_hyphen_langs[langid] = true
+end
+
+disable_split_hyphens = function(lang)
+ local langid = get_lang_id(lang)
+ if not langid then return nil, "Cannot find language number for: "..lang end
+ luavlna.split_hyphen_langs[langid] = nil
+end
+}
+
+% Set letters which are prevented from breaking
+\def\singlechars#1#2{%
+\directlua{set_singlechars("#1","#2")}
+}
+
+% Define compound initials
+\def\compoundinitials#1#2{%
+\directlua{set_compounds("#1","#2")}
+}
+% Enable inserting of visual marks for debugging
+\def\preventsingledebugon{%
+\directlua{luavlna.debug(true)}
+}
+
+\def\preventsinglelang#1{%
+ \directlua{set_main_language("#1")}
+}
+
+%\newluatexattribute\preventsinglestatus
+\attributedef\preventsinglestatus=\directlua{tex.print(luavlna.preventsingleid)} % just a random number
+
+\def\preventsingleon{%
+ \preventsinglestatus=2
+}
+
+\def\preventsingleoff{
+ \preventsinglestatus=1
+}
+% Disable inserting of visual marks for dewbugging
+\def\preventsingledebugoff{%
+\directlua{luavlna.debug(false)}
+}
+
+% enable/disable split hyphens for a language
+
+\def\enablesplithyphens#1{\directlua{enable_split_hyphens("#1")}}
+\def\disablesplithyphens#1{\directlua{disable_split_hyphens("#1")}}
+
+% disable processing of units or degrees
+
+\def\nopredegrees{\directlua{luavlna.no_predegrees = true}}
+\def\nosufdegrees{\directlua{luavlna.no_sufdegrees = true}}
+\def\nounits{\directlua{luavlna.no_unit = true}}
+
+\ifdefined\nosingledefaults\else
+ \singlechars{czech}{AIiVvOoUuSsZzKk}
+ \singlechars{slovak}{AIiVvOoUuSsZzKk}
+ \compoundinitials{czech}{Ch,CH}
+ \enablesplithyphens{czech}
+ \enablesplithyphens{slovak}
+\fi
+