From c22ab9576265f84ca4d5a4a331998e171aa3872d Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 3 Sep 2016 21:36:23 +0000 Subject: cstypo (3sep16) git-svn-id: svn://tug.org/texlive/trunk@41986 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/luatex/cstypo/cstypo-tex.tex | 8 +++ Master/texmf-dist/tex/luatex/cstypo/cstypo.lua | 60 +++++++++++++++++++--- 2 files changed, 62 insertions(+), 6 deletions(-) (limited to 'Master/texmf-dist/tex/luatex') diff --git a/Master/texmf-dist/tex/luatex/cstypo/cstypo-tex.tex b/Master/texmf-dist/tex/luatex/cstypo/cstypo-tex.tex index 2b768f783dd..28488daec1d 100644 --- a/Master/texmf-dist/tex/luatex/cstypo/cstypo-tex.tex +++ b/Master/texmf-dist/tex/luatex/cstypo/cstypo-tex.tex @@ -1,3 +1,6 @@ +\catcode`\@=11 +\directlua{cstypo_czech_language_id = \the\l@czech} +\catcode`\@=12 \directlua{require('cstypo')} \long\def\cstypoSingleLetterEnable{% @@ -14,3 +17,8 @@ \directlua{cstypo_percents_enable()}} \long\def\cstypoPercentsDisable{% \directlua{cstypo_percents_disable()}} + +\long\def\cstypoParagraphEnable{% + \directlua{cstypo_paragraph_enable()}} +\long\def\cstypoParagraphDisable{% + \directlua{cstypo_paragraph_disable()}} diff --git a/Master/texmf-dist/tex/luatex/cstypo/cstypo.lua b/Master/texmf-dist/tex/luatex/cstypo/cstypo.lua index 9012ce385ce..4ad6f651fb7 100644 --- a/Master/texmf-dist/tex/luatex/cstypo/cstypo.lua +++ b/Master/texmf-dist/tex/luatex/cstypo/cstypo.lua @@ -11,13 +11,16 @@ local GLYPH = node.id("glyph") local GLUE = node.id("glue") --print('GLUE value: ', GLUE) +local CZECH_ID = cstypo_czech_language_id +--print('CZECH_ID value: ', CZECH_ID) local function prevent_single_letter (head) - --print('prevent_single_letter hook is executing', head) while head do -- glyph - --print('inside prevent_single_letter loop, head.id: ', head.id) - if head.id == GLYPH then + if (head.id == GLYPH + -- and in Czech or unspecified (???) + and (head.lang == nil + or head.lang == CZECH_ID)) then -- only if we are at one letter word if unicode.utf8.match(unicode.utf8.char(head.char), "[zZsSuUkKoOvViI]") then -- and left of it is either a space @@ -57,7 +60,10 @@ end local function prevent_a_letter (head) while head do -- glyph - if head.id == GLYPH then + if (head.id == GLYPH + -- and in Czech or unspecified (???) + and (head.lang == nil + or head.lang == CZECH_ID)) then -- only if we are at one letter word if unicode.utf8.match(unicode.utf8.char(head.char), "[aA]") then -- and previous is space @@ -96,9 +102,12 @@ end local function prevent_percents (head) while head do -- glyph - if head.id == GLYPH then + if (head.id == GLYPH + -- and in Czech or unspecified (???) + and (head.lang == nil + or head.lang == CZECH_ID)) then -- only if we are at percentage sign - if unicode.utf8.match(unicode.utf8.char(head.char), "%%") then + if unicode.utf8.match(unicode.utf8.char(head.char), "[%%‰°℃℉]") then -- and left of it is a space if (head.prev.id == GLUE -- and left of the space is a digit. @@ -126,3 +135,42 @@ function cstypo_percents_disable() print('cstypo: Disabling percents hook.') luatexbase.remove_from_callback("pre_linebreak_filter", "cstypopercents") end + + +local function prevent_paragraph (head) + while head do + -- glyph + if (head.id == GLYPH + -- and in Czech or unspecified (???) + and (head.lang == nil + or head.lang == CZECH_ID)) then + -- only if we are at paragraph symbol + if unicode.utf8.match(unicode.utf8.char(head.char), "[§]") then + -- and right of it is a space + if (head.next.id == GLUE + and (head.next.next.id == GLYPH + and unicode.utf8.match(unicode.utf8.char(head.next.next.char), + "[0-9]"))) then + -- then avoid line break between the paragraph and the number + -- following it + local p = node.new("penalty") + p.penalty = 10000 + node.insert_after(head, head, p) + end + end + end + head = head.next + end + return true +end + +function cstypo_paragraph_enable() + print('cstypo: Enabling paragraph hook.') + luatexbase.add_to_callback("pre_linebreak_filter", prevent_paragraph, + "cstypoparagraph") +end + +function cstypo_paragraph_disable() + print('cstypo: Disabling paragraph hook.') + luatexbase.remove_from_callback("pre_linebreak_filter", "cstypoparagraph") +end -- cgit v1.2.3