diff options
author | Karl Berry <karl@freefriends.org> | 2022-06-11 20:43:14 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-06-11 20:43:14 +0000 |
commit | 63d22f849b86544ecd568a80ce8ca3d971026a59 (patch) | |
tree | d87b18850ebff45b0df634f7ac65a3259fe7223e /Master | |
parent | 9e82e4083572f3a686c29d965a888d101a47b735 (diff) |
spacekern (11jun22)
git-svn-id: svn://tug.org/texlive/trunk@63552 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/spacekern/DEPENDS.txt | 1 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/spacekern/README.md | 19 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/spacekern/spacekern.pdf | bin | 0 -> 64020 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/spacekern/spacekern.tex | 401 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/spacekern/spacekern.lua | 174 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/spacekern/spacekern.sty | 33 | ||||
-rw-r--r-- | Master/tlpkg/tlpsrc/spacekern.tlpsrc | 0 |
7 files changed, 628 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/lualatex/spacekern/DEPENDS.txt b/Master/texmf-dist/doc/lualatex/spacekern/DEPENDS.txt new file mode 100644 index 00000000000..6f08ff5ee74 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/spacekern/DEPENDS.txt @@ -0,0 +1 @@ +ifluatex
\ No newline at end of file diff --git a/Master/texmf-dist/doc/lualatex/spacekern/README.md b/Master/texmf-dist/doc/lualatex/spacekern/README.md new file mode 100644 index 00000000000..6aa24a47bbd --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/spacekern/README.md @@ -0,0 +1,19 @@ +The package offers two distinct main features. +First, it provides two shorthands for typesetting breaking +and non-breaking small spaces, where both hyphenation and +kerning against space are correctly applied. +Second, interword kerning can be applied. +The package requires LuaLaTeX. + +Copyright (c) 2022 Thomas Kelkel kelkel@emaileon.de + +The files of this package may be distributed and/or +modified under the conditions of the LaTeX Project +Public License, either version 1.3c of this license +or (at your option) any later version. The latest +version of this license is in + + http://www.latex-project.org/lppl.txt + +and version 1.3c or later is part of all distributions +of LaTeX version 2009/09/24 or later.
\ No newline at end of file diff --git a/Master/texmf-dist/doc/lualatex/spacekern/spacekern.pdf b/Master/texmf-dist/doc/lualatex/spacekern/spacekern.pdf Binary files differnew file mode 100644 index 00000000000..a7c707ce109 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/spacekern/spacekern.pdf diff --git a/Master/texmf-dist/doc/lualatex/spacekern/spacekern.tex b/Master/texmf-dist/doc/lualatex/spacekern/spacekern.tex new file mode 100644 index 00000000000..33a11384531 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/spacekern/spacekern.tex @@ -0,0 +1,401 @@ +\documentclass[ +ukenglish,% +twoside=false,% +fontsize=10pt,% +bibliography=totoc,% +numbers=autoenddot,% +headings=normalsize,% +overfullrule,% +headings=optiontotoc,% +] +{scrartcl} + +\makeatletter +\providecommand\@ix{9.6} +\providecommand\@xi{10.4} +\providecommand\@xiii{13.15} +\def\subfootnotesize{% + \@setfontsize% + \subfootnotesize% + {7.6}{8}% +} +\def\supernormalsize{% + \@setfontsize% + \supernormalsize% + \@xi{12}% +} +\def\subnormalsize{% + \@setfontsize% + \subnormalsize% + \@ix{11}% +} +\def\sublarge{% + \@setfontsize% + \sublarge% + {11.2}{13}% +} +\def\superlarge{% + \@setfontsize% + \superlarge% + \@xiii{16}% +} +\makeatother + +\newcommand*{\sectionas}{2.3ex plus .2ex} +\newcommand*{\sectionbs}{-3.5ex plus -1ex minus -.2ex} +\newcommand*{\sectiontbs}{3.6pt} +\newcommand*{\subsectiontbs}{1.2pt} +\newcommand*{\subsectionas}{1.5ex plus .2ex} +\newcommand*{\subsectionbs}{-3.25ex plus -1ex minus -.2ex} +\newcommand*{\subsubsectionas}{\subsectionas} +\newcommand*{\subsubsectionbs}{\subsectionbs} +\newcommand*{\paragraphas}{-1em} +\newcommand*{\paragraphbs}{.8\baselineskip} + +\newlength{\tnwsection} +\newlength{\tnwsubsection} +\newlength{\tnwsubsubsection} +\newlength{\tnwparagraph} +\newlength{\tisection} +\newlength{\tisubsection} +\newlength{\tisubsubsection} +\newlength{\tiparagraph} + +\setlength{\tnwsection}{1.2em} +\addtolength{\tnwsection}{.6em} +\setlength{\tnwsubsection}{\tnwsection} +\addtolength{\tnwsubsection}{.75em} +\setlength{\tnwsubsubsection}{\tnwsubsection} +\addtolength{\tnwsubsubsection}{.75em} +\setlength{\tnwparagraph}{\tnwsubsubsection} +\addtolength{\tnwparagraph}{.75em} + +\setlength{\tisection}{0em} +\setlength{\tisubsection}{\tisection} +\addtolength{\tisubsection}{\tnwsection} +\setlength{\tisubsubsection}{\tisubsection} +\addtolength{\tisubsubsection}{\tnwsubsection} +\setlength{\tiparagraph}{\tisubsubsection} +\addtolength{\tiparagraph}{\tnwsubsubsection} + +\RedeclareSectionCommands[% + tocraggedentrytext=true,% +]% +{section,subsection,subsubsection,paragraph} + +\RedeclareSectionCommand[% + tocindent=\tisection,% + tocnumwidth=\tnwsection,% + tocbeforeskip=\sectiontbs,% + tocentryformat=\supernormalsize\sffamily\bfseries,% + tocentrynumberformat=\supernormalsize\sffamily\bfseries,% + tocpagenumberformat=\supernormalsize\sffamily\bfseries% +]% +{section} + +\RedeclareSectionCommand[% + tocindent=\tisubsection,% + tocnumwidth=\tnwsubsection,% + tocbeforeskip=\subsectiontbs,% + tocentryformat=\subnormalsize,% + tocentrynumberformat=\subnormalsize,% + tocpagenumberformat=\subnormalsize% +]% +{subsection} + +\RedeclareSectionCommand[% + tocindent=\tisubsubsection,% + tocnumwidth=\tnwsubsubsection,% + tocbeforeskip=\sectiontbs% +]% +{subsubsection} + +\RedeclareSectionCommand[% + afterskip=\paragraphas,% + beforeskip=\paragraphbs,% + tocindent=\tiparagraph,% + tocnumwidth=\tnwparagraph,% + tocbeforeskip=\sectiontbs% +]% +{paragraph} + +\linespread{1.1} + +\newcommand*{\hs}{\hspace{.45em}} + +\usepackage{fontspec} + +\directlua{ + + fonts.handlers.otf.addfeature { + name = "onumkern", + type = "kern", + data = { + ["v"] = { ["zero.taboldstyle"] = 80 }, + ["two.taboldstyle"] = { ["zero.taboldstyle"] = 30, ["/"] = 50 }, + ["five.taboldstyle"] = { ["/"] = 20 }, + ["»"] = { ["I"] = 50 }, + }, + } + +} + +\setmainfont{Tangent}[ + BoldFont = *-Medium, + ItalicFont = *-Italic, + Ligatures = {Common, TeX}, + Numbers = OldStyle, + RawFeature = +onumkern +] + +\setsansfont{SegoeUI}[ + BoldFont = seguisb.ttf, + Ligatures = {Discretionary, TeX}, + Numbers = OldStyle +] + +\setmonofont{Consolas}[ + ItalicFont = *-Italic, + Numbers = OldStyle +] + +\newcommand*{\mono}[1]{% + {\subnormalsize\texttt{#1}}% +} + +\usepackage{babel} +\usepackage[paper=a4paper,marginratio={2:1,3:4}]{geometry} +\usepackage{spacekern} +\usepackage{hyperref} +\usepackage{bookmark} +\usepackage{microtype} + +\hypersetup{% + pdflang=en,% + unicode=true,% + pdfborder={0 0 0},% + bookmarksopen=true,% + bookmarksopenlevel=0,% + bookmarksnumbered=true,% + pdftitle={The spacekern package}, + pdfsubject={Kerning between words and against space}, + pdfauthor={Thomas Kelkel}, + pdfkeywords={tex, latex, kerning} +} + +\setlength{\parindent}{0pt} +\setlength{\parskip}{.4\baselineskip} + +\newcommand*{\q}[1]{% + ›% + #1% + ‹% +} +\newcommand*{\qq}[1]{% + »% + #1% + «% +} + +\newcommand*{\textnote}[1]{% + {% + \ttfamily% + \char174{}% + #1% + \char174{}% + }% +} + +\usepackage{luacode} + +\begin{luacode} + +local FLOOR = math.floor + +local function round ( num, dec ) + return FLOOR ( num * 10^dec + 0.5 ) / 10^dec +end + +local p_array = {false, false, false, false, false} +local p_counter = 0 +local ID = node.id +local NEW = node.new +local COPY = node.copy +local REM = node.remove +local PREV = node.prev +local NEXT = node.next +local TAIL = node.tail +local T_ID = node.traverse_id +local T_GLYPH = node.traverse_glyph +local INS_B = node.insert_before +local GLYPH = ID ( "glyph" ) +local GLUE = ID ( "glue" ) +local KERN = ID ( "kern" ) +local HLIST = ID ( "hlist" ) +local SWAPPED = table.swapped +local SUBTYPES = node.subtypes +local SPACESKIP = SWAPPED ( SUBTYPES ("glue") )["spaceskip"] +local WIDTH = round ( tex.sp ( "1.6em" ), 0 ) +local ipairs = ipairs +local page_counter = 0 +local INS_A = node.insert_after +local p_counter_x = 0 +local ATC = luatexbase.add_to_callback + +local function make_marks ( head, char, id, array, counter ) + for n in T_GLYPH ( head ) do + if n.char == char then + counter = counter + 1 + array[counter] = {false, false, false} + head = INS_B ( head, n, NEW ( GLYPH ) ) + PREV ( n ).data = id + local NEXT = n.next + local inside_counter = 0 + while NEXT.char ~= char do + inside_counter = inside_counter + 1 + array[counter][inside_counter] = COPY ( NEXT ) + NEXT = NEXT.next + REM ( head, NEXT.prev ) + end + head = REM ( head, NEXT ) + head = REM ( head, n ) + end + end + return head, array, counter +end + +local function mark_notes ( head ) + head, p_array, p_counter = make_marks ( head, 174, 427956, p_array, p_counter ) + return head +end + +local function make_margin_notes ( head, id, array, counter ) + for n in T_ID ( HLIST, head ) do + local first_kern = 0 + local first_width = 0 + for glyph_node in T_GLYPH ( n.head ) do + if glyph_node.data == id then + counter = counter + 1 + local tail_node = TAIL ( n.head ) + local glue_node = NEW ( GLUE ) + glue_node.subtype = SPACESKIP + glue_node.width = WIDTH + local NEXT + local switch_counter = 1 -- page_counter + n.head = INS_A ( n.head, TAIL ( n.head ), glue_node ) + if ( switch_counter % 2 == 0 ) then + NEXT = glue_node + else + NEXT = tail_node + end + local kern_value = 0 + for _, value in ipairs ( array[counter] ) do + if value ~= false then + local NUMBER = COPY ( value ) + n.head = INS_A ( n.head, NEXT, NUMBER) + if NEXT.next then + NEXT = NEXT.next + end + if NUMBER.width then + kern_value = kern_value - NUMBER.width + end + end + end + local kern_node = NEW ( KERN ) + kern_node.kern = kern_value - glue_node.width + if switch_counter % 2 ~= 0 then + kern_node.kern = kern_node.kern - tex.hsize + first_kern + n.head = INS_A ( n.head, tail_node, kern_node ) + end + if ( switch_counter % 2 == 0 ) and ( first_kern < 0 ) then + kern_node.kern = kern_node.kern - first_kern + first_width - kern_value + n.head = INS_A ( n.head, tail_node, kern_node ) + end + first_kern = kern_node.kern + first_width = kern_value + end + end + end + return head, counter +end + +local function make_text_notes ( head ) + page_counter = page_counter + 1 + head, p_counter_x = make_margin_notes ( head, 427956, p_array, p_counter_x ) + return head +end + + ATC ( "ligaturing", mark_notes , "mark notes" ) + ATC ( "pre_output_filter", make_text_notes , "count pages" ) + +\end{luacode} + +\flushbottom + +\RedeclareSectionCommand[% + afterskip=1.3ex plus .2ex,% + beforeskip=-2.5ex plus -1ex minus -.2ex,% + font=\superlarge% +]% +{section} + +\begin{document} + +\title{The spacekern package\vspace{.25\baselineskip}\\\superlarge{}Kerning between words and against space}% +\author{\sublarge{}Thomas Kelkel\vspace{-.25\baselineskip}\\\sublarge{}kelkel@emaileon.de\vspace{-.25\baselineskip}}% +\date{\addfontfeature{LetterSpace=2}\sublarge{}2022/06/11\quad{}v0.1a}% +\maketitle + +\section{Introduction} + +For typesetting a short space, \LaTeX{} provides the \mono{\textbackslash{},} macro. However, there are several issues with it. First, the following word is not hyphenated. Furthermore, kerning against space is not applied. And finally, the inserted space is non-breaking, which may not be desirable in many cases. + +For this reason, the \mono{spacekern} package provides shorthands for typesetting breaking and non-breaking short spaces where both hyphenation and kerning against space are correctly applied. By default, the \mono{\textbackslash{},} macro is redefined accordingly. + +The other main feature of this package is the application of interword kerning. + +Please note that this does not necessarily lead to better results in all cases. For example, if kerning against space is defined for a glyph, interword kerning might be superfluous and result in too little spacing. Also, you should be aware that interword kerning regularly deals with glyph combinations that do not occur within words and for which the font therefore does not provide kerning. + +\section{Basic usage} + +To load the package, simply add the following line to the preamble of the document: + +\begin{quote} + \mono{\textbackslash{}usepackage\{spacekern\}} +\end{quote} + +\section{Package options} + +Options can be loaded by adding them comma separated within square brackets: + +\begin{quote} + \mono{\textbackslash{}usepackage[\textit{<option1>,<option2>,…}]\{spacekern\}} +\end{quote} + +\addcontentsline{toc}{subsection}{noiwkern} + +\textnote{noiwkern}By default, interword kerning is applied. This option disables it. + +\addcontentsline{toc}{subsection}{noredef} + +\textnote{noredef}Disables the redefinition of \mono{\textbackslash{},}. + +\section{Shorthands and Macros} + +\addcontentsline{toc}{subsection}{;;} + +\textnote{\semicolon\semicolon}Typesets a small breaking space. + +\addcontentsline{toc}{subsection}{;;;} + +\textnote{\semicolon\semicolon\semicolon}Typesets a small non-breaking space. + +\addcontentsline{toc}{subsection}{semicolon} + +\textnote{\textbackslash{}semicolon}This macro allows the user to typeset consecutive semicolons. + +\section{License} + +This package is copyright © 2022 Thomas Kelkel. It may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3c of this license or (at your option) any later version. This work has the LPPL maintenance status \qq{author maintained}. + +\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/lualatex/spacekern/spacekern.lua b/Master/texmf-dist/tex/lualatex/spacekern/spacekern.lua new file mode 100644 index 00000000000..442f3845d43 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/spacekern/spacekern.lua @@ -0,0 +1,174 @@ +-- Copyright (c) 2022 Thomas Kelkel kelkel@emaileon.de + +-- This file may be distributed and/or modified under the +-- conditions of the LaTeX Project Public License, either +-- version 1.3c of this license or (at your option) any later +-- version. The latest version of this license is in + +-- http://www.latex-project.org/lppl.txt + +-- and version 1.3c or later is part of all distributions of +-- LaTeX version 2009/09/24 or later. + +-- Version: 0.1a + +local ID = node.id +local GLYPH = ID ( "glyph" ) +local GLUE = ID ( "glue" ) +local KERN = ID ( "kern" ) +local WI = ID ( "whatsit" ) +local BOUND = ID ( "boundary" ) +local PENALTY = ID ( "penalty" ) +local SWAPPED = table.swapped +local SUBTYPES = node.subtypes +local USERKERN = SWAPPED ( SUBTYPES ("kern") )["userkern"] +local LBPENALTY = SWAPPED ( SUBTYPES ("penalty") )["linebreakpenalty"] +local SPACESKIP = SWAPPED ( SUBTYPES ("glue") )["spaceskip"] +local NEW = node.new +local REM = node.remove +local PREV = node.prev +local NEXT = node.next +local INS_B = node.insert_before +local T_ID = node.traverse_id +local T_GLYPH = node.traverse_glyph +local WIS = node.whatsits() +local userdefined +local pairs = pairs +local FLOOR = math.floor +local GET_FONT = font.getfont +local ATC = luatexbase.add_to_callback + +local no_iw_kern = false + +function spacekern_no_iw_kern () + no_iw_kern = true +end + +local function round ( num, dec ) + return FLOOR ( num * 10^dec + 0.5 ) / 10^dec +end + +for key, value in pairs ( WIS ) do + if value == "user_defined" then + userdefined = key + end +end + +local function find_glyph ( n, d ) + if d ( n ) then + n = d ( n ) + while n.id ~= GLYPH do + if not d ( n ) or n.id == GLUE or n.id == BOUND or ( n.id == KERN and n.subtype == USERKERN ) then return false end + n = d ( n ) + end + else + return false + end + return n +end + +local function make_kern ( head, font, first_glyph, second_glyph, insert_point ) + local tfmdata = GET_FONT ( font ) + if tfmdata.resources then + local resources = tfmdata.resources + if resources.sequences then + local seq = resources.sequences + for _, t in pairs ( seq ) do + if t.steps then + local steps = t.steps + for _, k in pairs ( steps ) do + if k.coverage then + local first_number = true + if k.coverage[first_glyph] then + local glyph_table = k.coverage[first_glyph] + if type ( glyph_table ) == "table" then + for key, value in pairs ( glyph_table ) do + if key == second_glyph and type ( value ) == "number" and first_number and ( k.format == "move" or tfmdata.specification.features.raw[t.name] ) then + if tfmdata.specification.features.raw[t.name] then + first_number = false + end + if PREV ( insert_point ).id == PENALTY then + insert_point = PREV ( insert_point ) + end + INS_B ( head, insert_point, NEW ( KERN ) ) + PREV ( insert_point ).kern = value / tfmdata.units_per_em * tfmdata.size + end + end + end + end + end + end + end + end + end + end +end + +local function check_glyph ( n, d, has_prev_next_glyph, prev_next_glyph ) + if find_glyph ( n, d ) then + prev_next_glyph = find_glyph ( n, d ) + has_prev_next_glyph = true + end + return has_prev_next_glyph, prev_next_glyph +end + +local function make_kerns ( head, n ) + local has_prev_glyph = false + local has_next_glyph = false + local prev_glyph = n + local next_glyph = n + has_prev_glyph, prev_glyph = check_glyph ( n, PREV, has_prev_glyph, prev_glyph ) + has_next_glyph, next_glyph = check_glyph ( n, NEXT, has_next_glyph, next_glyph ) + if has_prev_glyph and prev_glyph.char and prev_glyph.font then + make_kern ( head, prev_glyph.font, prev_glyph.char, 32, n ) + end + if has_next_glyph and next_glyph.char and next_glyph.font then + make_kern ( head, next_glyph.font, 32, next_glyph.char, n ) + end + if not no_iw_kern and has_prev_glyph and has_next_glyph and prev_glyph.char and next_glyph.char and prev_glyph.font and next_glyph.font and ( prev_glyph.font == next_glyph.font ) then + make_kern ( head, prev_glyph.font, prev_glyph.char, next_glyph.char, n ) + end +end + +local function make_glues_and_kerns ( head ) + for n in T_ID ( GLUE, head ) do + make_kerns ( head, n ) + end + for n in T_GLYPH ( head ) do + if n.char and n.char == 59 and ( not find_glyph ( n, PREV ) or find_glyph ( n, PREV ).char ~= 59 ) then + if find_glyph ( n, NEXT ) then + local next_glyph = n + next_glyph = find_glyph ( n, NEXT ) + if next_glyph.char and next_glyph.char == 59 then + REM ( head, next_glyph ) + local SIZE = 0 + if n.font then + local tfmdata = GET_FONT ( n.font ) + if tfmdata.size then + SIZE = tfmdata.size + end + end + INS_B ( head, n, NEW ( GLUE ) ) + local glue_node = PREV ( n ) + glue_node.subtype = SPACESKIP + glue_node.width = round ( SIZE * .16667, 0 ) + local has_next_glyph = false + if find_glyph ( n, NEXT ) then + next_glyph = find_glyph ( n, NEXT ) + has_next_glyph = true + end + if has_next_glyph and next_glyph.char and next_glyph.char == 59 then + INS_B ( head, glue_node, NEW ( PENALTY ) ) + PREV ( glue_node ).subtype = LBPENALTY + PREV ( glue_node ).penalty = 10000 + REM ( head, next_glyph ) + end + REM ( head, n ) + make_kerns ( head, glue_node ) + end + end + end + end +end + +ATC ( "ligaturing", make_glues_and_kerns, "kern between words and against space", 1 )
\ No newline at end of file diff --git a/Master/texmf-dist/tex/lualatex/spacekern/spacekern.sty b/Master/texmf-dist/tex/lualatex/spacekern/spacekern.sty new file mode 100644 index 00000000000..8cb91537332 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/spacekern/spacekern.sty @@ -0,0 +1,33 @@ +% Copyright (c) 2022 Thomas Kelkel kelkel@emaileon.de + +% This file may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either +% version 1.3c of this license or (at your option) any later +% version. The latest version of this license is in + +% http://www.latex-project.org/lppl.txt + +% and version 1.3c or later is part of all distributions of +% LaTeX version 2009/09/24 or later. + +\ProvidesPackage{spacekern}[2022/06/11 v0.1a Kerning between words and against space] +\RequirePackage{ifluatex,luatexbase} + +\ifluatex + \directlua{require ( "spacekern.lua" )} + + \def\redef{true} + + \DeclareOption{noiwkern}{\directlua{spacekern_no_iw_kern()}} + \DeclareOption{noredef}{\def\redef{false}} + \ProcessOptions + + \def\semicolon{\nobreak\hspace{0em};} + \def\tmp{true} + \ifx\tmp\redef + \def\,{;;;} + \fi +\else + \errhelp{Compile with LuaLaTeX to be able to use the "spacekern" package.} + \errmessage{Package "spacekern" error: This package requires LuaLaTeX!} +\fi
\ No newline at end of file diff --git a/Master/tlpkg/tlpsrc/spacekern.tlpsrc b/Master/tlpkg/tlpsrc/spacekern.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/Master/tlpkg/tlpsrc/spacekern.tlpsrc |