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/doc/lualatex/cstypo/README.md | 6 +- Master/texmf-dist/doc/lualatex/cstypo/cstypo.pdf | Bin 67456 -> 74001 bytes Master/texmf-dist/doc/lualatex/cstypo/cstypo.tex | 26 ++++++- .../texmf-dist/doc/lualatex/cstypo/cstypotest.pdf | Bin 21174 -> 28731 bytes .../texmf-dist/doc/lualatex/cstypo/cstypotest.tex | 78 +++++++++++++++++++++ Master/texmf-dist/tex/lualatex/cstypo/cstypo.sty | 17 ++++- Master/texmf-dist/tex/luatex/cstypo/cstypo-tex.tex | 8 +++ Master/texmf-dist/tex/luatex/cstypo/cstypo.lua | 60 ++++++++++++++-- 8 files changed, 183 insertions(+), 12 deletions(-) diff --git a/Master/texmf-dist/doc/lualatex/cstypo/README.md b/Master/texmf-dist/doc/lualatex/cstypo/README.md index db71a70026b..4b0ed9a8ef0 100644 --- a/Master/texmf-dist/doc/lualatex/cstypo/README.md +++ b/Master/texmf-dist/doc/lualatex/cstypo/README.md @@ -1,11 +1,9 @@ # cstypo -This package provides macros for Czech language typography rules using -Lua(La)TeX. +This package provides macros for Czech language typography rules using Lua(La)TeX. - License is MIT license. See `LICENSE` file. - Author is [Václav Haisman](mailto:vhaisman+cstypo@gmail.com?subject=[cstypo]) -- Source code on GitHub in [`wilx/cstypo`](https://github.com/wilx/cstypo) - repository. +- Source code on GitHub in [`wilx/cstypo`](https://github.com/wilx/cstypo) repository. diff --git a/Master/texmf-dist/doc/lualatex/cstypo/cstypo.pdf b/Master/texmf-dist/doc/lualatex/cstypo/cstypo.pdf index 98610d9d79e..a1454c37073 100644 Binary files a/Master/texmf-dist/doc/lualatex/cstypo/cstypo.pdf and b/Master/texmf-dist/doc/lualatex/cstypo/cstypo.pdf differ diff --git a/Master/texmf-dist/doc/lualatex/cstypo/cstypo.tex b/Master/texmf-dist/doc/lualatex/cstypo/cstypo.tex index 9e87d617b90..1246e3d9566 100644 --- a/Master/texmf-dist/doc/lualatex/cstypo/cstypo.tex +++ b/Master/texmf-dist/doc/lualatex/cstypo/cstypo.tex @@ -13,6 +13,12 @@ \usepackage{polyglossia} \setmainlanguage[]{english} +\usepackage{newunicodechar} +\newunicodechar{℃}{{°C}} +\newunicodechar{℉}{{°F}} + +\usepackage[autostyle]{csquotes} + \author{Václav Haisman\texorpdfstring{% \\{\small\href{mailto:vhaisman+cstypo@gmail.com?subject=[cstypo]}{vhaisman@gmail.com}}}{}} \date{\today} @@ -66,6 +72,9 @@ enforcable through this package. \section{User interface} +Czech typography rules, when enabled by the following macros, are only +enforced on text marked as Czech by \texttt{polyglossia} or \texttt{babel}. + The following two macros allow to enable and disable hook that enforces penalization of line breaks after single letter words: %(\refitem{rulesList{itm:singleletter}): @@ -88,13 +97,24 @@ to have this rule enforced for all of the single letter words except for the \end{lstlisting} The following two macros allow to enable and disable hook that enforces -penalization of line breaks between number and \% symbol. +penalization of line breaks between number and \enquote*{\%} symbol and also +few more symbols: per thousand~\enquote*{‰}, degree~\enquote*{°}, degree +Celsius~\enquote*{℃} and degree Fahrenheit~\enquote*{℉}. \begin{lstlisting}[style=myLatexStyle] \cstypoPercentsEnable \cstypoPercentsDisable \end{lstlisting} +The following two macros allow to enable and disable hook that enforces +penalization of line breaks between~\enquote*{§} symbol and following number. + +\begin{lstlisting}[style=myLatexStyle] +\cstypoParagraphEnable +\cstypoParagraphDisable +\end{lstlisting} + + \section{History} This package was inspired by @@ -106,6 +126,10 @@ people of \href{http://tex.stackexchange.com/}{\TeX.SE} site itself. \begin{description}[style=nextline, labelwidth=4.5em, leftmargin=!, labelindent=0em] +\item[\texttt{v0.03}] Limit Czech typography rules enforcement only to text + marked as Czech language. Handle per thousand~\enquote*{‰}, + degree~\enquote*{°}, degree Celsius~\enquote*{℃}, degree + Fahrenheit~\enquote*{℉} and paragraph~\enquote*{§} symbols. \item[\texttt{v0.02}] Fixed some packaging and documentation issues found by CTAN submission review. \item[\texttt{v0.01}] First published version of this package. diff --git a/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.pdf b/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.pdf index 9752e42b352..1d6912a1341 100644 Binary files a/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.pdf and b/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.pdf differ diff --git a/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.tex b/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.tex index bd94218c940..bfdc3cfab4d 100644 --- a/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.tex +++ b/Master/texmf-dist/doc/lualatex/cstypo/cstypotest.tex @@ -32,6 +32,23 @@ Mezi oblíbené dětské pohádky patří pohádky \emph{[O Palečkovi], Alenka Se správným nastavením fontů znak \% v `na 100 \%' skončí na další řádce. +\expl{Next line is similar as the one above but tests behaviour for the ‰ + character.} + +Zde, v České republice, stále není povoleno ani 1 ‰ alkoholu v krvi při +řízení automobilu. + +\expl{Next line shows bad line break between degree sign `°' and number.} + +Součet všech tří úhlů v trojůhelníku je vždy 180 °. + +Voda taje při teplotě 0 ℃ a vypařuje se při 100 ℃. + +\expl{Next line show use of ``paragraf'' symbol. It should be kept with the + following number.} + +Jak může státní zástupce věc odložit zmiňuje § 159a. + \section{Better line breaks} \expl{And here we add Lua code to penalize single letter words. It results in following line layout:} @@ -39,6 +56,7 @@ following line layout:} \cstypoSingleLetterEnable{} \cstypoPercentsEnable{} \cstypoALetterEnable{} +\cstypoParagraphEnable{} Mezi oblíbené dětské pohádky patří pohádky \emph{O Palečkovi, Alenka v říši divů} a \emph{Socialismem k lepším zítřkům.} @@ -53,6 +71,50 @@ Mezi oblíbené dětské pohádky patří pohádky \emph{[O Palečkovi], Alenka Se správným nastavením fontů znak \% v `na 100 \%' skončí na další řádce. +\expl{Next line is similar as the one above but tests behaviour for the ‰ + character.} + +Zde, v České republice, stále není povoleno ani 1 ‰ alkoholu v krvi při +řízení automobilu. + +\expl{Next line shows line break between degree sign `°' and number. The + degree sign should stay with the number.} + +Součet všech tří úhlů v trojůhelníku je vždy 180 °. + +Voda taje při teplotě 0 ℃ a vypařuje se při 100 ℃. + +\expl{Next line show use of ``paragraf'' symbol. It should be kept with the + following number.} + +Jak může státní zástupce věc odložit zmiňuje § 159a. + + +\section{Bad line breaks because of English} +\expl{This section shows that while the hooks are still active, the actual + Czech language text is marked as English which results in bad line breaks.} + +\begin{english} +Mezi oblíbené dětské pohádky patří pohádky \emph{O Palečkovi, Alenka v říši + divů} a \emph{Socialismem k lepším zítřkům.} + +Mezi oblíbené dětské pohádky patří pohádky \emph{[O Palečkovi], Alenka v říši + divů} a \emph{Socialismem (k lepším zítřkům).} + +Se správným nastavením fontů znak \% v `na 100 \%' skončí na další řádce. + +Zde, v České republice, stále není povoleno ani 1 ‰ alkoholu v krvi při +řízení automobilu. + +Součet všech tří úhlů v trojůhelníku je vždy 180 °. + +Voda taje při teplotě 0 ℃ a vypařuje se při 100 ℃. + +Jak může státní zástupce věc odložit zmiňuje § 159a. + +\end{english} + + \section{Bad line breaks again} \expl{This section shows that disabling of the hook works and that the prepositions are again left at the end of their line.} @@ -60,6 +122,7 @@ Se správným nastavením fontů znak \% v `na 100 \%' skončí na další řád \cstypoSingleLetterDisable{} \cstypoPercentsDisable{} \cstypoALetterDisable{} +\cstypoParagraphDisable{} Mezi oblíbené dětské pohádky patří pohádky \emph{O Palečkovi, Alenka v říši divů} a \emph{Socialismem k lepším zítřkům.} @@ -75,6 +138,21 @@ Mezi oblíbené dětské pohádky patří pohádky \emph{[O Palečkovi], Alenka Se správným nastavením fontů znak \% v `na 100 \%' skončí na další řádce. +\expl{Next line is similar as the one above but tests behaviour for the ‰ + character.} + +Zde, v České republice, stále není povoleno ani 1 ‰ alkoholu v krvi při +řízení automobilu. + +\expl{Next line shows bad line break between degree sign `°' and number.} + +Součet všech tří úhlů v trojůhelníku je vždy 180 °. + +Voda taje při teplotě 0 ℃ a vypařuje se při 100 ℃. + +\expl{Next line show use of ``paragraf'' symbol. It should be kept with the + following number.} +Jak může státní zástupce věc odložit zmiňuje § 159a. \end{document} diff --git a/Master/texmf-dist/tex/lualatex/cstypo/cstypo.sty b/Master/texmf-dist/tex/lualatex/cstypo/cstypo.sty index 5fe04b38d35..a5565970982 100644 --- a/Master/texmf-dist/tex/lualatex/cstypo/cstypo.sty +++ b/Master/texmf-dist/tex/lualatex/cstypo/cstypo.sty @@ -8,12 +8,27 @@ % \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{cstypo} - [2016/08/30 v0.02 LaTeX package to enforce some basic Czech language + [2016/08/31 v0.03 LaTeX package to enforce some basic Czech language typography rules. Requires Lua(La)TeX.] \RequirePackage{ifluatex} \ifluatex + +\makeatletter +\ifcsname l@czech\endcsname +\PackageInfo{cstypo}{% + Czech language ID is \the\l@czech +} +\else +\PackageError{cstypo}{% + \protect\l@czech\space is not defined +}{% + Include cstypo package after polyglossia or babel. +} +\fi +\makeatother + \input{cstypo-tex} \else \PackageError{cstypo}{% 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