summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-04-02 21:42:33 +0000
committerKarl Berry <karl@freefriends.org>2016-04-02 21:42:33 +0000
commit2d629dc1657a546dbe79d71fbfe89d81f15a5aec (patch)
tree1c2620ba6eb871b111de7a3d6ee58be034ce5c3b /Master/texmf-dist/tex/lualatex
parent4b5466704256a0bd84c31cb760a435a3c26fb713 (diff)
lua-check-hyphen (2apr16)
git-svn-id: svn://tug.org/texlive/trunk@40211 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua91
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty9
2 files changed, 87 insertions, 13 deletions
diff --git a/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua b/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua
index e0eee9b88cf..148699382d3 100644
--- a/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua
+++ b/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua
@@ -1,13 +1,13 @@
--- Copyright 2012 Patrick Gundlach (patrick@gundla.ch)
+-- Copyright 2012-2016 Patrick Gundlach (patrick@gundla.ch)
-- Public repository: https://github.com/pgundlach/lua-check-hyphen
-- Licensed under the MIT license. See the file 'mit-license.txt' for exact terms.
--- Version: 0.3
+-- Version: 0.4
-- for debugging purpuse:
-- function w( ... )
--- texio.write_nl(string.format(...))
+-- texio.write_nl("--->" .. string.format(...))
-- end
local explode = function(s,p)
@@ -38,8 +38,9 @@ local a_whatsit_node = node.id("whatsit")
local subtype_rightskip = 9
+local sln = unicode.utf8
+
luacheckhyphen.deligature = function ( glyph_node )
- local sln = unicode.utf8
local head = glyph_node.components
local str = ""
while head do
@@ -56,6 +57,12 @@ luacheckhyphen.deligature = function ( glyph_node )
end
+-- This functions analyzes the list beginning at head. If it encounters a box,
+-- it recurses into the box. If it finds a disc node, it goes back until it finds the word
+-- start. Then it analyzes the word und finds all hyphenation points. For example the German
+-- word "Salpetersäure" has these disc nodes: , "Sal-petersäure", "Salpe-tersäure",
+-- "Salpeter-säure", and "Salpetersäu-re". Each of these "word with hyphen" gets stored in
+-- the hash hyphenwords
luacheckhyphen.collect_discs = function(head)
local word_start
local word
@@ -95,6 +102,7 @@ luacheckhyphen.collect_discs = function(head)
end
if thisbreakpoint then
word_with_hyphen = sln.sub(word,1,thisbreakpoint) .. "-" .. sln.sub(word,thisbreakpoint+1,-1)
+ -- word with hyphen has all possible hyphenation points
luacheckhyphen.hyphenwords[hyphencounter] = word_with_hyphen
hyphencounter = #luacheckhyphen.hyphenwords + 1
end
@@ -104,6 +112,12 @@ luacheckhyphen.collect_discs = function(head)
return true
end
+-- Remove '-' from word
+local function removedash( word )
+ local ret = sln.gsub(word,"-","")
+ return ret
+end
+
luacheckhyphen.check_discs = function (head,parent)
local c
local word
@@ -119,7 +133,14 @@ luacheckhyphen.check_discs = function (head,parent)
if luacheckhyphen.word_whitelist[word] then
-- word found, but OK (whitelisted)
else
- luacheckhyphen.all_hyphenatedwords[word] = true
+ if luachekchyphen.compact == nil or luachekchyphen.compact == "true" then
+ local word_without_hyphen = sln.lower(removedash(word))
+ local tmp = luacheckhyphen.all_hyphenatedwords[word_without_hyphen] or {}
+ tmp[word] = true
+ luacheckhyphen.all_hyphenatedwords[word_without_hyphen] = tmp
+ else
+ luacheckhyphen.all_hyphenatedwords[word] = true
+ end
if luacheckhyphen.drawmarks then
tmp = node.copy(luacheckhyphen.rectangle)
node.insert_after(parent,head,tmp)
@@ -131,6 +152,21 @@ luacheckhyphen.check_discs = function (head,parent)
return true
end
+-- http://www.lua.org/pil/19.3.html
+local function pairsByKeys (t)
+ local a = {}
+ for n in pairs(t) do table.insert(a, n) end
+ table.sort(a)
+ local i = 0 -- iterator variable
+ local iter = function () -- iterator function
+ i = i + 1
+ if a[i] == nil then return nil
+ else return a[i], t[a[i]]
+ end
+ end
+ return iter
+end
+
luacheckhyphen.listhyphenatedwords = function()
if luacheckhyphen.final == "true" then
return
@@ -139,9 +175,31 @@ luacheckhyphen.listhyphenatedwords = function()
if not luacheckhyphen.nofile then
local unknown_hyphenation_filename = tex.jobname .. ".uhy"
local unknown_hyphenation_file = io.open(unknown_hyphenation_filename,"w")
-
- for k,v in pairs(luacheckhyphen.all_hyphenatedwords) do
- unknown_hyphenation_file:write(k .. "\n")
+ for k,v in pairsByKeys(luacheckhyphen.all_hyphenatedwords) do
+ if luachekchyphen.compact == "true" or luachekchyphen.compact == nil then
+ local hyphenationlist = {}
+ local hyphenpos = {}
+ for l,_ in pairs(v) do
+ local tmp = string.find(l,"-")
+ if tmp then
+ hyphenpos[#hyphenpos + 1] = tmp
+ end
+ hyphenationlist[#hyphenationlist + 1] = l
+ end
+ table.sort(hyphenpos)
+ local word_with_all_hyphenationpoints = {}
+ local cur = 1
+ for i=1,string.len(k) do
+ if hyphenpos[cur] == i then
+ word_with_all_hyphenationpoints[#word_with_all_hyphenationpoints + 1] = "-"
+ cur = cur + 1
+ end
+ word_with_all_hyphenationpoints[#word_with_all_hyphenationpoints + 1] = string.sub(k,i, i)
+ end
+ unknown_hyphenation_file:write(table.concat(word_with_all_hyphenationpoints,"") .. "\n")
+ else
+ unknown_hyphenation_file:write(k .. "\n")
+ end
end
unknown_hyphenation_file:close()
end
@@ -166,7 +224,22 @@ luacheckhyphen.enable = function()
else
filecontents = whitelistfile:read("*a")
for _,entry in ipairs(explode(filecontents,"[^%s]+")) do
- luacheckhyphen.word_whitelist[entry] = true
+ parts = string.explode(entry,"-")
+ if #parts > 2 then
+ local c = 1
+ for c=1,#parts - 1 do
+ local word = {}
+ for i=1,#parts do
+ word[#word + 1] = parts[i]
+ if i == c then
+ word[#word + 1] = "-"
+ end
+ end
+ luacheckhyphen.word_whitelist[table.concat(word,"")] = true
+ end
+ else
+ luacheckhyphen.word_whitelist[entry] = true
+ end
end
end
end
diff --git a/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty b/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty
index b919bd3b654..d38ebeab8cb 100644
--- a/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty
+++ b/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty
@@ -1,9 +1,9 @@
-% Copyright 2012 Patrick Gundlach (patrick@gundla.ch)
-% Public repository: https://github.com/pgundlach/lua-check-hyphen
+% Copyright 2012 Patrick Gundlach (patrick@gundla.ch)
+% Public repository: https://github.com/pgundlach/lua-check-hyphen
% Licensed under the MIT license. See the file 'mit-license.txt' for exact terms.
-\def\luachekchyphenpkgdate{2014/07/30}
-\def\luachekchyphenversion{0.3}
+\def\luachekchyphenpkgdate{2016/04/02}
+\def\luachekchyphenversion{0.4}
\RequirePackage{ifluatex}
@@ -23,6 +23,7 @@
\def\luachekchyphendothings{\directlua{luachekchyphen.enable() }}
\define@key{luacheckhyphen}{nofile}[true]{\directlua{luachekchyphen.nofile = "\luatexluaescapestring{#1}"}}
+\define@key{luacheckhyphen}{compact}[true]{\directlua{luachekchyphen.compact = "\luatexluaescapestring{#1}"}}
\define@key{luacheckhyphen}{final}[true]{\directlua{luachekchyphen.final = "\luatexluaescapestring{#1}"}}
\define@key{luacheckhyphen}{mark}[true]{\directlua{luachekchyphen.mark = "\luatexluaescapestring{#1}"}}
\define@key{luacheckhyphen}{whitelist}{\directlua{luachekchyphen.whitelist = "\luatexluaescapestring{#1}"}}