From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/luatex/generic/cstypo/LICENSE | 21 ++++ macros/luatex/generic/cstypo/README.md | 9 ++ macros/luatex/generic/cstypo/cstypo-tex.tex | 24 ++++ macros/luatex/generic/cstypo/cstypo.lua | 176 ++++++++++++++++++++++++++++ macros/luatex/generic/cstypo/cstypo.pdf | Bin 0 -> 74001 bytes macros/luatex/generic/cstypo/cstypo.sty | 45 +++++++ macros/luatex/generic/cstypo/cstypo.tex | 138 ++++++++++++++++++++++ macros/luatex/generic/cstypo/cstypotest.pdf | Bin 0 -> 28731 bytes macros/luatex/generic/cstypo/cstypotest.tex | 158 +++++++++++++++++++++++++ 9 files changed, 571 insertions(+) create mode 100644 macros/luatex/generic/cstypo/LICENSE create mode 100644 macros/luatex/generic/cstypo/README.md create mode 100644 macros/luatex/generic/cstypo/cstypo-tex.tex create mode 100644 macros/luatex/generic/cstypo/cstypo.lua create mode 100644 macros/luatex/generic/cstypo/cstypo.pdf create mode 100644 macros/luatex/generic/cstypo/cstypo.sty create mode 100644 macros/luatex/generic/cstypo/cstypo.tex create mode 100644 macros/luatex/generic/cstypo/cstypotest.pdf create mode 100644 macros/luatex/generic/cstypo/cstypotest.tex (limited to 'macros/luatex/generic/cstypo') diff --git a/macros/luatex/generic/cstypo/LICENSE b/macros/luatex/generic/cstypo/LICENSE new file mode 100644 index 0000000000..872ab4f9e1 --- /dev/null +++ b/macros/luatex/generic/cstypo/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Václav Haisman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/macros/luatex/generic/cstypo/README.md b/macros/luatex/generic/cstypo/README.md new file mode 100644 index 0000000000..4b0ed9a8ef --- /dev/null +++ b/macros/luatex/generic/cstypo/README.md @@ -0,0 +1,9 @@ +# cstypo + +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. diff --git a/macros/luatex/generic/cstypo/cstypo-tex.tex b/macros/luatex/generic/cstypo/cstypo-tex.tex new file mode 100644 index 0000000000..28488daec1 --- /dev/null +++ b/macros/luatex/generic/cstypo/cstypo-tex.tex @@ -0,0 +1,24 @@ +\catcode`\@=11 +\directlua{cstypo_czech_language_id = \the\l@czech} +\catcode`\@=12 +\directlua{require('cstypo')} + +\long\def\cstypoSingleLetterEnable{% + \directlua{cstypo_single_letter_enable()}} +\long\def\cstypoSingleLetterDisable{% + \directlua{cstypo_single_letter_disable()}} + +\long\def\cstypoALetterEnable{% + \directlua{cstypo_a_letter_enable()}} +\long\def\cstypoALetterDisable{% + \directlua{cstypo_a_letter_disable()}} + +\long\def\cstypoPercentsEnable{% + \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/macros/luatex/generic/cstypo/cstypo.lua b/macros/luatex/generic/cstypo/cstypo.lua new file mode 100644 index 0000000000..4ad6f651fb --- /dev/null +++ b/macros/luatex/generic/cstypo/cstypo.lua @@ -0,0 +1,176 @@ +--[[-- +(c) 2016 Václav Haisman + +This program can be redistributed and/or modified under the terms of the MIT +license. See LICENSE file. +--]]-- + +local GLYPH = node.id("glyph") +--print('GLYPH value: ', 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) + 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 one letter word + if unicode.utf8.match(unicode.utf8.char(head.char), "[zZsSuUkKoOvViI]") then + -- and left of it is either a space + if ((head.prev.id == GLUE + -- or one of '{[(' + or (head.prev.id == GLYPH + and unicode.utf8.match(unicode.utf8.char(head.prev.char), + "[%[%]()%{%}]"))) + -- and right of the one letter word is also a space + and head.next.id == GLUE) then + -- then avoid line break between the single letter word and the + -- word following it + local p = node.new("penalty") + p.penalty = 10000 + node.insert_after(head, head, p) + --print('inserting penalty at ', head) + end + end + end + head = head.next + end + return true +end + +function cstypo_single_letter_enable () + print('cstypo: Enabling single letter hook.') + luatexbase.add_to_callback("pre_linebreak_filter", prevent_single_letter, + "cstyposingleletter") +end + +function cstypo_single_letter_disable () + print('cstypo: Disabling single letter hook.') + luatexbase.remove_from_callback("pre_linebreak_filter", "cstyposingleletter") +end + + +local function prevent_a_letter (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 one letter word + if unicode.utf8.match(unicode.utf8.char(head.char), "[aA]") then + -- and previous is space + if ((head.prev.id == GLUE + -- or previous is one of '{[(' + or (head.prev.id == GLYPH + and unicode.utf8.match(unicode.utf8.char(head.prev.char), + "[%[%]()%{%}]"))) + -- and right of the one letter word is also a space + and head.next.id == GLUE) then + -- then avoid line break between the single letter word and the + -- word 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_a_letter_enable () + print('cstypo: Enabling \'a\' letter hook.') + luatexbase.add_to_callback("pre_linebreak_filter", prevent_a_letter, + "cstypoaletter") +end + +function cstypo_a_letter_disable () + print('cstypo: Disabling \'a\' letter hook.') + luatexbase.remove_from_callback("pre_linebreak_filter", "cstypoaletter") +end + + +local function prevent_percents (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 percentage sign + 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. + and head.prev.prev.id == GLYPH + and unicode.utf8.match(unicode.utf8.char(head.prev.prev.char), + "[0-9]")) then + local p = node.new("penalty") + p.penalty = 10000 + node.insert_after(head.prev.prev, head.prev.prev, p) + end + end + end + head = head.next + end + return true +end + +function cstypo_percents_enable() + print('cstypo: Enabling percents hook.') + luatexbase.add_to_callback("pre_linebreak_filter", prevent_percents, + "cstypopercents") +end + +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 diff --git a/macros/luatex/generic/cstypo/cstypo.pdf b/macros/luatex/generic/cstypo/cstypo.pdf new file mode 100644 index 0000000000..a1454c3707 Binary files /dev/null and b/macros/luatex/generic/cstypo/cstypo.pdf differ diff --git a/macros/luatex/generic/cstypo/cstypo.sty b/macros/luatex/generic/cstypo/cstypo.sty new file mode 100644 index 0000000000..a556597098 --- /dev/null +++ b/macros/luatex/generic/cstypo/cstypo.sty @@ -0,0 +1,45 @@ +% LaTeX package to enforce some basic Czech language typography +% rules. Requires LuaLaTeX. +% +% (c) 2016 Václav Haisman +% +%% This program can be redistributed and/or modified under the terms of the +%% MIT license. See LICENSE file. +% +\NeedsTeXFormat{LaTeX2e}[1994/06/01] +\ProvidesPackage{cstypo} + [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}{% + This requires LuaTeX or LuaLaTeX +}{% + Compile this with LuaTeX or LuaLaTeX. +} + +\fi + +\endinput + +%% +%% End of file `cstypo.sty'. diff --git a/macros/luatex/generic/cstypo/cstypo.tex b/macros/luatex/generic/cstypo/cstypo.tex new file mode 100644 index 0000000000..1246e3d956 --- /dev/null +++ b/macros/luatex/generic/cstypo/cstypo.tex @@ -0,0 +1,138 @@ +\documentclass[paper=B5,DIV=calc,parskip=half]{scrartcl} +\usepackage{ifluatex} + +\usepackage{fontspec} +%\defaultfontfeatures{Ligatures={TeX,Common},Scale=MatchLowercase} +\setmainfont[]{Charis SIL} +\setsansfont[Ligatures={TeX,Common}, Scale=MatchLowercase]{TeX Gyre Heros} +\setmonofont[Ligatures=,Scale=MatchLowercase]{DejaVu Sans Mono} + +\usepackage{listings} +\usepackage{enumitem} +%\usepackage{enumitem-zref} +\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} +\title{\texttt{cstypo} user manual} + +\PassOptionsToPackage{unicode}{hyperref} +\usepackage{bookmark} +\usepackage{xcolor} +\hypersetup{ + colorlinks, + linkcolor={red!50!black}, + citecolor={blue!50!black}, + urlcolor={blue!80!black}, + breaklinks=true} +\urlstyle{same} % don't use monospace font for urls + +\usepackage{microtype} +\usepackage{metalogo} + +\setlength{\emergencystretch}{3em} % prevent overfull lines + +\lstdefinestyle{myLatexStyle}{ + language=[LaTeX]{Tex}, + basicstyle=\ttfamily +} + + +\begin{document} +\begin{titlepage} + \maketitle +\end{titlepage} + +\tableofcontents + +\section{Introduction} +The \href{https://www.ctan.org/pkg/cstypo}{\texttt{cstypo}}\footnote{Source + code is on GitHub in + \href{https://github.com/wilx/cstypo}{\texttt{wilx/cstypo}} repository.} +package provides macros that enforce basic Czech typography rules through Lua +hooks available in \LuaTeX{}. + +\begin{enumerate}%[name=rulesList] +\item\label{itm:singleletter} There should be no line break between single + letter preprosition and single letter conjugations and word following them. +\item\label{itm:percents} There should be no line break between number and \% + symbol. +\end{enumerate} + +There are obviously more rules than these two but only the above rules are +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}): + +\begin{lstlisting}[style=myLatexStyle] +\cstypoSingleLetterEnable +\cstypoSingleLetterDisable +\end{lstlisting} + +The following two macros allow to enable and disable hook that enforces the +same rule as above but for ‘a’ conjugation. The reason that this is separete +from the rest of the single letter prepositions and conjugations is that line +break after ‘a’ is tolerated for narrow column texts. It might be desirable +to have this rule enforced for all of the single letter words except for the +‘a’. + +\begin{lstlisting}[style=myLatexStyle] +\cstypoALetterEnable +\cstypoALetterDisable +\end{lstlisting} + +The following two macros allow to enable and disable hook that enforces +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 +\texttt{\href{http://www.ctan.org/pkg/impnattypo}{impnattypo}} French +typography package. It would not be possible without help and comments from +people of +\href{http://chat.stackexchange.com/rooms/41/tex-latex-and-friends}{\TeX{}, + \LaTeX{} and Friends} StackExchange chat room and the +\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. +\end{description} + +\end{document} diff --git a/macros/luatex/generic/cstypo/cstypotest.pdf b/macros/luatex/generic/cstypo/cstypotest.pdf new file mode 100644 index 0000000000..1d6912a134 Binary files /dev/null and b/macros/luatex/generic/cstypo/cstypotest.pdf differ diff --git a/macros/luatex/generic/cstypo/cstypotest.tex b/macros/luatex/generic/cstypo/cstypotest.tex new file mode 100644 index 0000000000..bfdc3cfab4 --- /dev/null +++ b/macros/luatex/generic/cstypo/cstypotest.tex @@ -0,0 +1,158 @@ +\documentclass{article} +\usepackage{lmodern} +\usepackage{ifluatex} +\usepackage[a6paper]{geometry} +\usepackage{parskip} +\usepackage{polyglossia} +\setmainlanguage[]{czech} +\setotherlanguage{english} +\usepackage{microtype} + +\setlength{\emergencystretch}{3em} % prevent overfull lines +\newcommand{\expl}[1]{\begin{english}\sffamily #1\end{english}} + +\usepackage{cstypo} + +\begin{document} +\section{Bad line breaks} +\expl{The follwing text has prepostions `O' and `k' at end of line which + is incorrect according to Czech language typography standards:} + +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.} + +\expl{The follwing text is the same as above but parentheses are used to test + that a preposition stay (or not stay, in this case) with following word + even if the prepostion is preceeded with a parenthesis:} + +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).} + +\expl{Next line shows bad line break between number and the \% symbol.} + +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:} + +\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.} + +\expl{The follwing text is the same as above but parentheses are used to test + that a preposition stay with following word even if the prepostion is + preceeded with a parenthesis:} + +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).} + +\expl{Here, the \% symbol should be together with the number.} + +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.} + +\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.} + +\expl{The follwing text is the same as above but parentheses are used to test + that a preposition stay (or not stay, in this case) with following word + even if the prepostion is preceeded with a parenthesis:} + +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).} + +\expl{And here, line break is inserted before the \% symbol again.} + +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} -- cgit v1.2.3