summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-10-23 03:00:42 +0000
committerNorbert Preining <norbert@preining.info>2019-10-23 03:00:42 +0000
commit43e60b98142683b95336b9086ee52f4daefff93e (patch)
treec435859ab7275b2cb9f3c2f5ca83dafe20968ad6 /macros/luatex
parent7bf461efa5036b361e9500c4ed5c675cc819652c (diff)
CTAN sync 201910230300
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/generic/luavlna/README.md2
-rw-r--r--macros/luatex/generic/luavlna/luavlna-doc.pdfbin87293 -> 89010 bytes
-rw-r--r--macros/luatex/generic/luavlna/luavlna-doc.tex34
-rw-r--r--macros/luatex/generic/luavlna/luavlna.lua40
-rw-r--r--macros/luatex/generic/luavlna/luavlna.sty1
-rw-r--r--macros/luatex/generic/luavlna/luavlna.tex19
6 files changed, 93 insertions, 3 deletions
diff --git a/macros/luatex/generic/luavlna/README.md b/macros/luatex/generic/luavlna/README.md
index 366cd21700..b027486b21 100644
--- a/macros/luatex/generic/luavlna/README.md
+++ b/macros/luatex/generic/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/macros/luatex/generic/luavlna/luavlna-doc.pdf b/macros/luatex/generic/luavlna/luavlna-doc.pdf
index c929578013..cb80186aee 100644
--- a/macros/luatex/generic/luavlna/luavlna-doc.pdf
+++ b/macros/luatex/generic/luavlna/luavlna-doc.pdf
Binary files differ
diff --git a/macros/luatex/generic/luavlna/luavlna-doc.tex b/macros/luatex/generic/luavlna/luavlna-doc.tex
index 1519d7fe9f..f8c95a291c 100644
--- a/macros/luatex/generic/luavlna/luavlna-doc.tex
+++ b/macros/luatex/generic/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/macros/luatex/generic/luavlna/luavlna.lua b/macros/luatex/generic/luavlna/luavlna.lua
index 84d4c3f82c..73a10fe9ba 100644
--- a/macros/luatex/generic/luavlna/luavlna.lua
+++ b/macros/luatex/generic/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/macros/luatex/generic/luavlna/luavlna.sty b/macros/luatex/generic/luavlna/luavlna.sty
index 059c260ea1..44efffb6bd 100644
--- a/macros/luatex/generic/luavlna/luavlna.sty
+++ b/macros/luatex/generic/luavlna/luavlna.sty
@@ -20,5 +20,6 @@
\singlechars{czech}{AIiVvOoUuSsZzKk}
\singlechars{slovak}{AIiVvOoUuSsZzKk}
\compoundinitials{czech}{Ch,CH}
+ \enablesplithyphens{czech}
}
\endinput
diff --git a/macros/luatex/generic/luavlna/luavlna.tex b/macros/luatex/generic/luavlna/luavlna.tex
index f3c44f1b69..a0fb9e515e 100644
--- a/macros/luatex/generic/luavlna/luavlna.tex
+++ b/macros/luatex/generic/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