From d580dddbf84953059f75b9bcefb4086128ffcb58 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 23 Oct 2019 21:40:43 +0000 Subject: luavlna (23oct19) git-svn-id: svn://tug.org/texlive/trunk@52504 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/luatex/luavlna/README.md | 2 +- .../texmf-dist/doc/luatex/luavlna/luavlna-doc.pdf | Bin 87293 -> 89010 bytes .../texmf-dist/doc/luatex/luavlna/luavlna-doc.tex | 34 ++++++++++++++++-- Master/texmf-dist/doc/luatex/luavlna/luavlna.tex | 19 ++++++++++ Master/texmf-dist/tex/luatex/luavlna/luavlna.lua | 40 +++++++++++++++++++++ Master/texmf-dist/tex/luatex/luavlna/luavlna.sty | 1 + 6 files changed, 93 insertions(+), 3 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/luatex/luavlna/README.md b/Master/texmf-dist/doc/luatex/luavlna/README.md index 366cd21700c..b027486b216 100644 --- a/Master/texmf-dist/doc/luatex/luavlna/README.md +++ b/Master/texmf-dist/doc/luatex/luavlna/README.md @@ -1,4 +1,4 @@ -# Luavlna, version v0.1c, 2019-04-16 +# Luavlna, version v0.1d, 2019-10-22 # Introduction diff --git a/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.pdf b/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.pdf index c9295780139..cb80186aee2 100644 Binary files a/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.pdf and b/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.pdf differ diff --git a/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.tex b/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.tex index 1519d7fe9f7..f8c95a291cb 100644 --- a/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.tex +++ b/Master/texmf-dist/doc/luatex/luavlna/luavlna-doc.tex @@ -44,7 +44,7 @@ for enc\TeX, \verb!xevlna! for Xe\TeX, \verb!impnattypo! for Lua\LaTeX). %This package is for plain %lua\TeX and for lua\LaTeX. -Other feature of this package is including of non-breakable space after +Another feature is inclusion of a non-breakable space after initials, like in personal names, after or before academic degrees and between numbers and units (SI and others). @@ -52,10 +52,11 @@ The code is modified version of Patrick Gundlach's answer on TeX.sx\footnote{\url{http://tex.stackexchange.com/a/28128/2891}}. The difference is that it is possible to specify which single letters should be taken into account for different languages. -The support for degrees and units was added as well. +% The support for degrees and units was added as well. % The code works also for single letters at the beginning of the brackets. + \section{Usage} The usage is simple: @@ -169,6 +170,35 @@ Default values: \end{verbatim} \end{mycode} + +\subsection{Split hyphens} + +The hyphenated words like ``je-li'' should be be hyphenated as ``je-/-li`` +according to the Czech typesetting rules. This behaviour can be enabled or disabled for a particular +language using the following commands: + +\begin{mycode} + \cmd{\enablesplithyphens}\marg{language name}\\ + \cmd{\disablesplithyphens}\marg{language name} +\end{mycode} + +By default, it is enabled for the Czech language. + +Example in action: + +\begin{minipage}{3in} + \selectlanguage{czech} + Sedlec-Prčice, modro-zelený, překladatel-tlumočník, kuchař-číšník, propan-butan, + Otýlie Sklenářová-Malá, František Jílek-Oberpfalcer. + \selectlanguage{english} +\end{minipage} + +The similar behaviour can be achieved using the \verb|\splithyphens| command +provided by Czech langauge definitions for the Babel package, but it's use is +discouraged. It prevents use ot the hyphen character in many situations. The +solution provided by Luavlna should be safe. + + \subsection{Turning off language switching} By default, language of the nodes is taken into account. If you want to use diff --git a/Master/texmf-dist/doc/luatex/luavlna/luavlna.tex b/Master/texmf-dist/doc/luatex/luavlna/luavlna.tex index f3c44f1b695..a0fb9e515e9 100644 --- a/Master/texmf-dist/doc/luatex/luavlna/luavlna.tex +++ b/Master/texmf-dist/doc/luatex/luavlna/luavlna.tex @@ -5,6 +5,7 @@ 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) @@ -54,6 +55,18 @@ set_main_language = function(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 = languages:get_number(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 = languages:get_number(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 @@ -89,6 +102,11 @@ end \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}} @@ -99,5 +117,6 @@ end \singlechars{czech}{AIiVvOoUuSsZzKk} \singlechars{slovak}{AIiVvOoUuSsZzKk} \compoundinitials{czech}{Ch,CH} + \enablesplithyphens{czech} \fi diff --git a/Master/texmf-dist/tex/luatex/luavlna/luavlna.lua b/Master/texmf-dist/tex/luatex/luavlna/luavlna.lua index 84d4c3f82cd..73a10fe9ba8 100644 --- a/Master/texmf-dist/tex/luatex/luavlna/luavlna.lua +++ b/Master/texmf-dist/tex/luatex/luavlna/luavlna.lua @@ -305,10 +305,50 @@ local function prevent_single_letter (head) return true end +-- Enable hyphenation of words that contain hyphens +-- and repeating of the explicit hyphen on a new line when +-- the hyphen is hyphenated +-- It should be used in the `hyphenate` callback +-- based on ShreewatsaR's code from: +-- https://tex.stackexchange.com/a/417883/2891 +local hyphenate_langs = {} +local break_hyphens = function(head, tail) + local hyphenchar = string.byte("-") + local glyph_id = node.id("glyph") + local n = head + while n do + if n.id == glyph_id and hyphenate_langs[n.lang] and n.char == hyphenchar then + -- Insert an infinite penalty before, and a zero-width glue node after, the hyphen. + -- Like writing "\nobreak-\hspace{0pt}" or equivalently "\penalty10000-\hskip0pt" + local p = node.new(node.id('penalty')) + p.penalty = 10000 + head, p = node.insert_before(head, n, p) + local g = node.new(node.id('glue')) + head, g = node.insert_after(head, n, g) + -- insert the discretionary + local disc = node.new("disc") + disc.penalty = tex.hyphenpenalty + disc.subtype = 2 + disc.pre = node.copy(n) + disc.post = node.copy(n) + disc.replace = node.copy(n) + node.insert_before(head, g, disc) + -- insert another penalty + node.insert_before(head, g, node.copy(p)) + node.remove(head,n) + n = g + end + n = n.next + end + lang.hyphenate(head, tail) +end + M.preventsingle = prevent_single_letter M.singlechars = set_singlechars M.initials = set_initials M.set_tex4ht = set_tex4ht M.debug = set_debug M.set_main_language = set_main_language +M.split_hyphen_langs = hyphenate_langs +M.split_hyphens = break_hyphens return M diff --git a/Master/texmf-dist/tex/luatex/luavlna/luavlna.sty b/Master/texmf-dist/tex/luatex/luavlna/luavlna.sty index 059c260ea11..44efffb6bd6 100644 --- a/Master/texmf-dist/tex/luatex/luavlna/luavlna.sty +++ b/Master/texmf-dist/tex/luatex/luavlna/luavlna.sty @@ -20,5 +20,6 @@ \singlechars{czech}{AIiVvOoUuSsZzKk} \singlechars{slovak}{AIiVvOoUuSsZzKk} \compoundinitials{czech}{Ch,CH} + \enablesplithyphens{czech} } \endinput -- cgit v1.2.3