From d6d8155a5f7b9a3a7a103ca7d2e061ac8dc947eb Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 29 Jul 2012 17:01:44 +0000 Subject: new lualatex package lua-check-hyphen (20jun12) git-svn-id: svn://tug.org/texlive/trunk@27227 c570f23f-e606-0410-a88d-b1316a301751 --- .../doc/lualatex/lua-check-hyphen/doc/README.md | 26 ++++ .../lua-check-hyphen/doc/luacheckhyphenmanual.pdf | Bin 0 -> 76927 bytes .../lua-check-hyphen/doc/luacheckhyphenmanual.tex | 93 ++++++++++++ .../doc/lualatex/lua-check-hyphen/doc/sample.pdf | Bin 0 -> 5316 bytes .../doc/lualatex/lua-check-hyphen/doc/sample.tex | 10 ++ .../lualatex/lua-check-hyphen/lua-check-hyphen.lua | 163 +++++++++++++++++++++ .../lualatex/lua-check-hyphen/lua-check-hyphen.sty | 38 +++++ Master/tlpkg/libexec/ctan2tds | 1 + Master/tlpkg/tlpsrc/collection-luatex.tlpsrc | 1 + Master/tlpkg/tlpsrc/lua-check-hyphen.tlpsrc | 0 10 files changed, 332 insertions(+) create mode 100644 Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/README.md create mode 100644 Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.pdf create mode 100644 Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.tex create mode 100644 Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.pdf create mode 100644 Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.tex create mode 100644 Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua create mode 100644 Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty create mode 100644 Master/tlpkg/tlpsrc/lua-check-hyphen.tlpsrc (limited to 'Master') 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 new file mode 100644 index 00000000000..20d8244dc83 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/README.md @@ -0,0 +1,26 @@ +# lua-check-hyphen + +## Usage + + \usepackage{lua-check-hyphen} + ... + \LuaCheckHyphen{mark,whitelist={filea.txt,fileb.txt}} + +## What it does + +It lists all hyphenated words in the log file as well as in the file with the extension `.uhy` + +## How to use + +A typical workflow is: + +* run final document +* put the correctly hyphenated words into a text file (format: each word separated with space or on a single line, only whitespace matters as a separator) +* add that file to the whitelist (as given above) +* 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. 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 new file mode 100644 index 00000000000..aa837960627 Binary files /dev/null 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 new file mode 100644 index 00000000000..deab3895410 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/luacheckhyphenmanual.tex @@ -0,0 +1,93 @@ +\documentclass{ltxdockit} +\usepackage{dtklogos} +\newcommand\pkgversion{0.1} + +\titlepage{% + title={The lua-check-hyphen package}, + subtitle={Checking your hyphenated words}, + url={https://github.com/pgundlach/lua-check-hyphen}, + author={Patrick Gundlach}, + email={patrick@gundla.ch}, + revision={\pkgversion}, + date={\today}} + +\hypersetup{% + pdftitle={The lua-check-hyphen package}, + pdfsubject={Checking your hyphenated words}, + pdfauthor={Patrick Gundlach}, + pdfkeywords={tex, latex, hyphenation}} + + + + +\begin{document} +\printtitlepage +\tableofcontents + +\section{Introduction} + +\TeX\ is pretty good at hyphenating words. But a computer algorithm is not perfect, sometimes we wish to manually check all used hyphenations in a document. This package helps you on this task. + +\section{Usage} + +This package only works with \LuaTeX. To activate it a + +\begin{verbatim} + \usepackage{lua-check-hyphen} +\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. + +\section{Advanced usage} +\label{sec:advanced_usage} + +With longer documents it becomes tedious checking for the same hyphenated words over and over. Therefore this package allows you to create a whitelist of \emph{accepted hyphenation}. This whitelist is a simple textfile where the words are separated by whitespace and the allowed hyphenation is marked with a dash (-). You can use the output file \texttt{.uhy} as an input for the whitelist file. You load the file in your document with + +\begin{verbatim} + \LuaCheckHyphen{whitelist=myfile.txt} +\end{verbatim} + +and a sample file looks like this: + +\begin{verbatim} +seren-ity +morn-ings +posses-sion +\end{verbatim} + +or + +\begin{verbatim} +seren-ity morn-ings posses-sion +\end{verbatim} + +The format is not important, the entries must be separated by whitespace. + +Words in this whitelist won't be reported. \sty{lua-check-hyphen} assumes that these are valid break points. + +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}} +\end{verbatim} + +\section{Visual marker} + +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} +% or: +\LuaCheckHyphen{mark} +\end{verbatim} + +This marks all non-whitelisted used hyphenation points in the document with a black square (not to be confused with overfull boxes): + +\includegraphics{sample-crop} + +\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. + +\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 new file mode 100644 index 00000000000..406be84ddca Binary files /dev/null and b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.pdf differ diff --git a/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.tex b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.tex new file mode 100644 index 00000000000..618fbf7f174 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/lua-check-hyphen/doc/sample.tex @@ -0,0 +1,10 @@ +\documentclass{article} +\usepackage{fontspec,nopageno} +\usepackage[mark]{lua-check-hyphen} +\begin{document} +\parindent0.9em +\hsize 1.3in +A wonderful serenity has taken possession of my entire soul, like these sweet +mornings of spring which I enjoy with my whole heart. + +\end{document} \ No newline at end of file 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 new file mode 100644 index 00000000000..9730b4d5eac --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.lua @@ -0,0 +1,163 @@ +-- Copyright 2012 Patrick Gundlach, patrick@gundla.ch +-- Public repository: https://github.com/pgundlach/lua-check-hyphen (issues/pull requests,...) +-- Version: 0.1 + + +-- for debugging purpuse: +-- function w( ... ) +-- 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 +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 +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 +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 +end + +luachekchyphen.listhyphenatedwords = function() + if luachekchyphen.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") +end + +luachekchyphen.enable = function() + if luachekchyphen.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") +end + +return luachekchyphen + +-- 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 new file mode 100644 index 00000000000..a4253fb0579 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/lua-check-hyphen/lua-check-hyphen.sty @@ -0,0 +1,38 @@ +% see lua file for copyright information (MIT License) + +\def\luachekchyphenpkgdate{2012/06/20} +\def\luachekchyphenversion{0.1} + + +\RequirePackage{ifluatex} +\RequirePackage{luatexbase-attr} +\RequirePackage{luatextra} +\RequirePackage{keyval} + +\DeclareOption{final}{\setkeys{luacheckhyphen}{final}} +\DeclareOption*{\setkeys{luacheckhyphen}{\CurrentOption}} + +\ProvidesPackage{lua-check-hyphen}[\luachekchyphenpkgdate\space v\luachekchyphenversion\space Hyphenation checking for LuaTeX (PGU)] + + + +\def\luachekchyphendothings{\directlua{luachekchyphen.enable() }} + +\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}"}} + + +\ifluatex + \AtBeginDocument{\luachekchyphendothings} + \directlua{luachekchyphen = require('lua-check-hyphen')} + \def\LuaCheckHyphen#1{\setkeys{luacheckhyphen}{#1}} + \AtEndDocument{\directlua{luachekchyphen.listhyphenatedwords()}} +\else + \def\LuaCheckHyphen#1{} + \message{Warning: lua-check-hyphen only works with LuaTeX (LaTeX format for now)} +\fi + +\ProcessOptions + + diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds index 332d545c0fe..3a16b19e559 100755 --- a/Master/tlpkg/libexec/ctan2tds +++ b/Master/tlpkg/libexec/ctan2tds @@ -1294,6 +1294,7 @@ $standardtex='\.(.bx|cfg|sty|clo|ldf|cls|def|fd|cmap|4ht)$'; 'listings-ext','\.sty', # not .cfg 'logic', 'milstd\.tex|' . $standardtex, 'ltxkeys', '\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$', # not cfg + 'lua-check-hyphen', '\.lua|' . $standardtex, 'lua-visual-debug', '\.lua|' . $standardtex, 'lua2dox', 'NULL', # .def is lua code 'lualatex-math', '\.sty', # not phst-doc.cls diff --git a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc index ddaf405f81d..5713f8fd6bf 100644 --- a/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-luatex.tlpsrc @@ -8,6 +8,7 @@ depend collection-basic depend checkcites depend chickenize depend interpreter +depend lua-check-hyphen depend lua-visual-debug depend lua2dox depend luabibentry diff --git a/Master/tlpkg/tlpsrc/lua-check-hyphen.tlpsrc b/Master/tlpkg/tlpsrc/lua-check-hyphen.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d -- cgit v1.2.3