From 6493ff809c01bf214a27f16adf993ca101b7b8c3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 3 Aug 2014 16:53:27 +0000 Subject: lua-check-hyphen git-svn-id: svn://tug.org/texlive/trunk@34810 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/lualatex/lua-check-hyphen/doc/README.md | 9 +- .../lua-check-hyphen/doc/luacheckhyphenmanual.pdf | Bin 76927 -> 110703 bytes .../lua-check-hyphen/doc/luacheckhyphenmanual.tex | 73 ++++- .../doc/lualatex/lua-check-hyphen/doc/sample.pdf | Bin 5316 -> 5327 bytes .../lualatex/lua-check-hyphen/lua-check-hyphen.lua | 294 +++++++++++---------- .../lualatex/lua-check-hyphen/lua-check-hyphen.sty | 11 +- 6 files changed, 238 insertions(+), 149 deletions(-) diff --git a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/README.md b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/README.md index 20d8244dc83..f6fe0bee1d8 100644 --- a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/README.md +++ b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/README.md @@ -20,7 +20,8 @@ A typical workflow is: * optionally use the option `mark` to make the unknown hyphenated words visible in the PDF file -Copyright 2012 Patrick Gundlach (patrick@gundla.ch) -Package version: 0.1 -Public repository: https://github.com/pgundlach/lua-check-hyphen -Licensed under the MIT license. +Copyright 2012–2014 Patrick Gundlach (patrick@gundla.ch)
+Package version: 0.3 +Public repository: https://github.com/pgundlach/lua-check-hyphen
+Licensed under the MIT license. See the file 'mit-license.txt' for exact terms.
+Status: works fine, slightly unmaintained.
diff --git a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.pdf b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.pdf index aa837960627..97d054ffb7d 100644 Binary files a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.pdf and b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.pdf differ diff --git a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.tex b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.tex index deab3895410..aafa334d210 100644 --- a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.tex +++ b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.tex @@ -1,6 +1,6 @@ \documentclass{ltxdockit} -\usepackage{dtklogos} -\newcommand\pkgversion{0.1} +\usepackage{dtklogos,csquotes} +\newcommand\pkgversion{0.3} \titlepage{% title={The lua-check-hyphen package}, @@ -37,7 +37,7 @@ This package only works with \LuaTeX. To activate it a \end{verbatim} is enough. -When you process your document with \LuaLaTeX, a file with the suffix \verb|.uhy| is created with that contains every hyphenated word. You can check that file for hyphenation errors. +When you process your document with \LuaLaTeX, a file with the suffix \verb|.uhy| is created with that contains every hyphenated word. You can check that file for hyphenation errors. With the package option \texttt{nofile}, you can tell the package not to write the external file. In any case the list is written to the log file. \section{Advanced usage} \label{sec:advanced_usage} @@ -69,7 +69,7 @@ Words in this whitelist won't be reported. \sty{lua-check-hyphen} assumes that t You can have more than one whitelist file by giving the filenames separated by comma: \begin{verbatim} - \LuaCheckHyphen{whitelist={file1.txt,file2.txt,file3.txt}} +\LuaCheckHyphen{whitelist={file1.txt,file2.txt,file3.txt}} \end{verbatim} \section{Visual marker} @@ -77,7 +77,7 @@ You can have more than one whitelist file by giving the filenames separated by c You might want to use the PDF viewer to check for incorrectly hyphenated words. To enable visual feedback, just pass the \texttt{mark} option to the \cmd{usepackage} or to the \cmd{LuaCheckHyphen} command: \begin{verbatim} -\usepackage{lua-check-hyphen} +\usepackage[mark]{lua-check-hyphen} % or: \LuaCheckHyphen{mark} \end{verbatim} @@ -86,8 +86,71 @@ This marks all non-whitelisted used hyphenation points in the document with a bl \includegraphics{sample-crop} +\section{Options to \cmd{LuaCheckHyphen}} + +For the true/false options you don't need to write the \texttt{=true} part. All options except for the \texttt{whitelist} can be passed directly to the package: + +\begin{verbatim} +\usepackage[mark,nofile]{lua-check-hyphen} +\end{verbatim} + +\noindent All options can be set in \cmd{LuaCheckHyphen}. + +\begin{verbatim} +\LuaCheckHyphen{mark,nofile,whitelist=myfile.txt} +\end{verbatim} + + +\begin{optionlist} + \boolitem[false]{mark}{Create visual markers when an unknown hyphenation encountered.} + \boolitem[false]{nofile}{Don't write to an external file (\texttt{.uhy}).} + \boolitem[false]{file}{Don't do anything. This is for the last document run, no marks will be generated.} + \valitem{whitelist}{files}{List of files, separated by \enquote{\texttt{,}}. You need to wrap the filenames in braces \texttt{\textbraceleft...\textbraceright} so that the comma won't be seen as a option separator.} +\end{optionlist} + \section{Final document} When you pass the Option \opt{final} to the \cmd{documentclass}, the \cmd{usepackage} or the \cmd{LuaCheckHyphen} command, all processing is disabled. +\section{Changes} +\begin{changelog} + \begin{release}{0.2}{2012-06-22} + \item Fix ligature counting error (github issue \#1) + \item Add nofile option + \item No hyphenation list in the terminal output (log only) + \item License details added + \end{release} +\end{changelog} + +\section{Bugs} + +\begin{itemize} + \item Paragraphs that end with \verb+\end{document}+ are ignored. Inserting an empty line or + \cmd{par} helps. +\end{itemize} + +\section{License} + +This file (documentation and the package) is released under the terms of the MIT License. See the file \texttt{mit-license.txt} in the distribution. + +% Copyright (c) 2012 Patrick Gundlach + +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the \enquote{Software}), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: + +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. + +% THE SOFTWARE IS PROVIDED \enquote{AS IS}, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + \end{document} \ No newline at end of file diff --git a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.pdf b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.pdf index 406be84ddca..3c9409bf05a 100644 Binary files a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.pdf and b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.pdf differ 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 9730b4d5eac..e0eee9b88cf 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,163 +1,183 @@ --- Copyright 2012 Patrick Gundlach, patrick@gundla.ch --- Public repository: https://github.com/pgundlach/lua-check-hyphen (issues/pull requests,...) --- Version: 0.1 +-- 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. + +-- Version: 0.3 -- for debugging purpuse: -- function w( ... ) --- texio.write_nl(string.format(...)) +-- texio.write_nl(string.format(...)) -- end local explode = function(s,p) - local t = { } - for s in unicode.utf8.gmatch(s,p) do - if s ~= "" then - t[#t+1] = s - end - end - return t + local t = { } + for s in unicode.utf8.gmatch(s,p) do + if s ~= "" then + t[#t+1] = s + end + end + return t end -luachekchyphen = {} - - -luachekchyphen.hyphenattr = luatexbase.new_attribute("hyphenattr") -luachekchyphen.hyphenwords = {} -luachekchyphen.all_hyphenatedwords = {} -luachekchyphen.word_whitelist = {} -luachekchyphen.rectangle = node.new("whatsit","pdf_literal") -luachekchyphen.rectangle.data = string.format("q 0 0 10 10 re f S Q") - -luachekchyphen.deligature = function ( glyph_node ) - local sln = unicode.utf8 - local head = glyph_node.components - local str = "" - while head do - if head.id == 37 then - if head.components then - str = str .. luachekchyphen.deligature(head) - else - str = str .. sln.char(head.char) - end - end - head = head.next - end - return str +luacheckhyphen = {} + + +local hyphenattr = luatexbase.new_attribute("hyphenattr") + +luacheckhyphen.hyphenwords = {} +luacheckhyphen.all_hyphenatedwords = {} +luacheckhyphen.word_whitelist = {} +luacheckhyphen.rectangle = node.new("whatsit","pdf_literal") +luacheckhyphen.rectangle.data = string.format("q 0 0 10 10 re f S Q") + +local a_glyph_node = node.id("glyph") +local a_disc_node = node.id("disc") +local a_glue_node = node.id("glue") +local a_whatsit_node = node.id("whatsit") +local subtype_rightskip = 9 + + +luacheckhyphen.deligature = function ( glyph_node ) + local sln = unicode.utf8 + local head = glyph_node.components + local str = "" + while head do + if head.id == a_glyph_node then + if head.components then + str = str .. luacheckhyphen.deligature(head) + else + str = str .. sln.char(head.char) + end + end + head = head.next + end + return str end -luachekchyphen.collect_discs = function(head) - local word_start - local word - -- this is where we store all the breakpoints - local thisbreakpoint - local word_with_hyphen - local c - local hyphencounter = #luachekchyphen.hyphenwords + 1 - local sln = unicode.utf8 - while head do - if head.id == 0 then - elseif head.id == 7 then --disc - word_start = head - word_end = head - while word_start.prev and word_start.prev.id ~= 10 do - word_start = word_start.prev - end - word = "" - c = 0 - while word_start and word_start.id ~= 10 do - if word_start == head then -- disc - -- there is a breakpoint after letter c - node.set_attribute(head,luachekchyphen.hyphenattr,hyphencounter) - thisbreakpoint = c - elseif word_start.id == 37 then - c = c + 1 - if word_start.components then - word = word .. luachekchyphen.deligature(word_start) - elseif sln.match(sln.char(word_start.char),"%a") then - word = word .. sln.char(word_start.char) - end - end - word_start = word_start.next - end - if thisbreakpoint then - word_with_hyphen = sln.sub(word,1,thisbreakpoint) .. "-" .. sln.sub(word,thisbreakpoint+1,-1) - luachekchyphen.hyphenwords[hyphencounter] = word_with_hyphen - hyphencounter = #luachekchyphen.hyphenwords + 1 - end - end - head = head.next - end - return true +luacheckhyphen.collect_discs = function(head) + local word_start + local word + -- this is where we store all the breakpoints + local thisbreakpoint + local word_with_hyphen + local c + local hyphencounter = #luacheckhyphen.hyphenwords + 1 + local sln = unicode.utf8 + local ligature_chars + while head do + if head.id == 0 then + elseif head.id == a_disc_node then + word_start = head + word_end = head + while word_start.prev and word_start.prev.id ~= a_glue_node do + word_start = word_start.prev + end + word = "" + c = 0 + while word_start and word_start.id ~= a_glue_node do + if word_start == head then -- disc + -- there is a breakpoint after letter c + node.set_attribute(head,hyphenattr,hyphencounter) + thisbreakpoint = c + elseif word_start.id == a_glyph_node then + if word_start.components then + ligature_chars = luacheckhyphen.deligature(word_start) + word = word .. ligature_chars + c = c + string.len(ligature_chars) + elseif sln.match(sln.char(word_start.char),"%a") then + c = c + 1 + word = word .. sln.char(word_start.char) + end + end + word_start = word_start.next + end + if thisbreakpoint then + word_with_hyphen = sln.sub(word,1,thisbreakpoint) .. "-" .. sln.sub(word,thisbreakpoint+1,-1) + luacheckhyphen.hyphenwords[hyphencounter] = word_with_hyphen + hyphencounter = #luacheckhyphen.hyphenwords + 1 + end + end + head = head.next + end + return true end -luachekchyphen.check_discs = function (head,parent) - local c - local word - local tmp - while head do - if head.id < 2 then - luachekchyphen.check_discs(head.list,head) - elseif head.id == 7 and head.next and head.next.id == 10 then -- disc - c = node.has_attribute(head,luachekchyphen.hyphenattr) - word = luachekchyphen.hyphenwords[c] - if luachekchyphen.word_whitelist[word] then - -- word found, but OK (whitelisted) - else - luachekchyphen.all_hyphenatedwords[word] = true - if luachekchyphen.drawmarks then - tmp = node.copy(luachekchyphen.rectangle) - node.insert_after(parent,head,tmp) - end - end - end - head = head.next - end - return true +luacheckhyphen.check_discs = function (head,parent) + local c + local word + local tmp + while head do + if head.id < 2 then -- a box, recurse + luacheckhyphen.check_discs(head.list,head) + -- package luashowhyphens has disc-whatsit-rightskip, without luashowhyphens it is disc-rightskip + elseif head.id == a_disc_node and head.next and head.next.id == a_glue_node and head.next.subtype == subtype_rightskip or + head.id == a_disc_node and head.next and head.next.next and head.next.id == a_whatsit_node and head.next.next.id == a_glue_node and head.next.next.subtype == subtype_rightskip then + c = node.has_attribute(head,hyphenattr) + word = luacheckhyphen.hyphenwords[c] + if luacheckhyphen.word_whitelist[word] then + -- word found, but OK (whitelisted) + else + luacheckhyphen.all_hyphenatedwords[word] = true + if luacheckhyphen.drawmarks then + tmp = node.copy(luacheckhyphen.rectangle) + node.insert_after(parent,head,tmp) + end + end + end + head = head.next + end + return true end -luachekchyphen.listhyphenatedwords = function() - if luachekchyphen.final == "true" then +luacheckhyphen.listhyphenatedwords = function() + if luacheckhyphen.final == "true" then return end - local unknown_hyphenation_filename = tex.jobname .. ".uhy" - local unknown_hyphenation_file = io.open(unknown_hyphenation_filename,"w") - - texio.write_nl("All words with unknown hyphenation below") - for k,v in pairs(luachekchyphen.all_hyphenatedwords) do - texio.write_nl(k) - unknown_hyphenation_file:write(k .. "\n") - end - unknown_hyphenation_file:close() - texio.write_nl("All words with unknown hyphenation above\n") + -- don't write if the use has turned that off! + 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") + end + unknown_hyphenation_file:close() + end + + texio.write_nl("log","All words with unknown hyphenation below") + for k,v in pairs(luacheckhyphen.all_hyphenatedwords) do + texio.write_nl("log",k) + end end -luachekchyphen.enable = function() - if luachekchyphen.final == "true" then +luacheckhyphen.enable = function() + if luacheckhyphen.final == "true" then return end - local whitelistfile,err - local filecontents - if luachekchyphen.whitelist then - for i,v in ipairs(string.explode(luachekchyphen.whitelist,",")) do - whitelistfile,err = io.open(v) - if not whitelistfile then - texio.write_nl(err) - else - filecontents = whitelistfile:read("*a") - for _,entry in ipairs(explode(filecontents,"[^%s]+")) do - luachekchyphen.word_whitelist[entry] = true - end - end - end - end - if luachekchyphen.mark == "true" then - luachekchyphen.drawmarks = true - end - luatexbase.add_to_callback("pre_linebreak_filter", luachekchyphen.collect_discs,"collect_discs") - luatexbase.add_to_callback("post_linebreak_filter",luachekchyphen.check_discs,"check_discs") + local whitelistfile,err + local filecontents + if luacheckhyphen.whitelist then + for i,v in ipairs(string.explode(luacheckhyphen.whitelist,",")) do + whitelistfile,err = io.open(v) + if not whitelistfile then + texio.write_nl(err) + else + filecontents = whitelistfile:read("*a") + for _,entry in ipairs(explode(filecontents,"[^%s]+")) do + luacheckhyphen.word_whitelist[entry] = true + end + end + end + end + if luacheckhyphen.mark == "true" then + luacheckhyphen.drawmarks = true + end + luatexbase.add_to_callback("pre_linebreak_filter", luacheckhyphen.collect_discs,"collect_discs") + luatexbase.add_to_callback("post_linebreak_filter",luacheckhyphen.check_discs,"check_discs") end -return luachekchyphen +return luacheckhyphen -- end of file 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 a4253fb0579..b919bd3b654 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,7 +1,9 @@ -% see lua file for copyright information (MIT License) +% 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{2012/06/20} -\def\luachekchyphenversion{0.1} +\def\luachekchyphenpkgdate{2014/07/30} +\def\luachekchyphenversion{0.3} \RequirePackage{ifluatex} @@ -10,6 +12,8 @@ \RequirePackage{keyval} \DeclareOption{final}{\setkeys{luacheckhyphen}{final}} +\DeclareOption{nofile}{\setkeys{luacheckhyphen}{nofile}} + \DeclareOption*{\setkeys{luacheckhyphen}{\CurrentOption}} \ProvidesPackage{lua-check-hyphen}[\luachekchyphenpkgdate\space v\luachekchyphenversion\space Hyphenation checking for LuaTeX (PGU)] @@ -18,6 +22,7 @@ \def\luachekchyphendothings{\directlua{luachekchyphen.enable() }} +\define@key{luacheckhyphen}{nofile}[true]{\directlua{luachekchyphen.nofile = "\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}"}} -- cgit v1.2.3