diff options
author | Karl Berry <karl@freefriends.org> | 2023-03-07 22:22:01 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-03-07 22:22:01 +0000 |
commit | 5ec21fd1c60e0aa6fcd566e687fd5199695f855d (patch) | |
tree | be58398e35989bdef5f453f8d4877063c8d31436 /Master/texmf-dist | |
parent | 1f1bfd29f1134e183376ffe9a2c09532eaecfde2 (diff) |
linebreaker (7mar23)
git-svn-id: svn://tug.org/texlive/trunk@66440 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/linebreaker/README.md | 4 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf | bin | 51966 -> 49887 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex | 11 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua | 72 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty | 9 |
5 files changed, 88 insertions, 8 deletions
diff --git a/Master/texmf-dist/doc/lualatex/linebreaker/README.md b/Master/texmf-dist/doc/lualatex/linebreaker/README.md index 26b4cd59e55..a418e231b06 100644 --- a/Master/texmf-dist/doc/lualatex/linebreaker/README.md +++ b/Master/texmf-dist/doc/lualatex/linebreaker/README.md @@ -1,4 +1,4 @@ -#The Linebreaker package, version v0.1a (2022-03-12) +#The Linebreaker package, version v0.1b (2023-03-06) This package tries to prevent overflow lines in paragraphs or boxes. It changes the LuaTeX's `linebreak` callback, and it re-typesets the paragraph @@ -15,6 +15,8 @@ with the lowest badness. ## License +Author: Michal Hoftich <michal.h21@gmail.com> + Permission is granted to copy, distribute and/or modify this software under the terms of the LaTeX Project Public License, version 1.3. diff --git a/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf b/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf Binary files differindex ac6659002fb..b47fc0e3e3c 100644 --- a/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf +++ b/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf diff --git a/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex b/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex index 8da047ceea4..f94aa33ef02 100644 --- a/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex +++ b/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex @@ -140,6 +140,11 @@ Maximal allowed value of \verb|\emergencystretch|. Maximal allowed value of \verb|tolerance|. \end{function} +\begin{function}{cubic} +Use cubic method for the \verb|tolerance| calculation. By default, \verb|tolerance| is calculated +using a linear method, with constant steps. With the cubic method, each step is larger than the previous. +\end{function} + \begin{function}{debug} Print debugging info to the terminal output. \end{function} @@ -186,6 +191,12 @@ under the terms of the LaTeX Project Public License, version 1.3. \section{Changes} \begin{description} + \item[v0.1b, 2023-03-06]\hfill + \begin{itemize} + \item Set maximal value of tolerance to 8189, bigger value doesn't have any effect. + \item Added \verb|cubic| method for calculating tolerance. + \item Explicitly set the \verb|tex.linebreak| parameters, to support paragraph direction and other paragraph variables. + \end{itemize} \item[v0.1a, 2022-03-12]\hfill \begin{itemize} diff --git a/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua b/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua index 6a2d20e074b..99966ad302f 100644 --- a/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua +++ b/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua @@ -1,3 +1,11 @@ +-- linebreaker.lua +-- +-- (c) Michal Hoftich <michal.h21@gmail.com> +-- +-- This program can be redistributed and/or modified under the terms +-- of the LaTeX Project Public License Distributed from CTAN archives +-- in directory macros/latex/base/lppl.txt. + local linebreaker = {} local hlist_id = node.id "hlist" @@ -22,7 +30,7 @@ end linebreaker.debug = false -- max allowed value of tolerance -linebreaker.max_tolerance = 9999 +linebreaker.max_tolerance = 8189 -- maximal possible value of tolerance (thanks to Jan Šustek for pointing that out) -- maximal allowed emergencystretch linebreaker.max_emergencystretch = tex.sp("3em") -- line breaking function is customizable @@ -43,9 +51,38 @@ linebreaker.previous_points = linebreaker.vertical_point / linebreaker.boxsize linebreaker.width_factor = 1.5 -- will be linebreaker active? linebreaker.active = true + +-- use cubic method for tolerance calculation +linebreaker.use_cubic = false -- return array with default parameters function linebreaker.parameters() - return {} + return { + pardir = tex.pardir + ,pretolerance = tex.pretolerance + ,tracingparagraphs=tex.tracingparagraphs + ,tolerance=tex.tolerance + ,looseness=tex.looseness + ,hyphenpenalty=tex.hyphenpenalty + ,exhyphenpenalty=tex.exhyphenpenalty + ,pdfadjustspacing=tex.pdfadjustspacing + ,adjdemerits=tex.adjdemerits + ,pdfprotrudechars=tex.pdfprotrudechars + ,linepenalty=tex.linepenalty + ,lastlinefit=tex.lastlinefit + ,doublehyphendemerits=tex.doublehyphendemerits + ,finalhyphendemerits=tex.finalhyphendemerits + ,hangafter=tex.hangafter + ,interlinepenalty=tex.interlinepenalty + ,clubpenalty=tex.clubpenalty + ,widowpenalty=tex.widowpenalty + ,brokenpenalty=tex.brokenpenalty + ,emergencystretch=tex.emergencystretch + ,hangindent=tex.hangindent + ,hsize=tex.hsize + ,leftskip=tex.leftskip + ,rightskip=tex.rightskip + ,parshape=tex.parshape + } end -- diagnostic function for traversing nodes returned by linebreaking @@ -144,9 +181,23 @@ local function glue_calc(n, sign,set) end --- calculate new tolerance +local function cube_root(num) + return num ^(1/3) +end + + +-- calculate new tolerance using method suggested by Jan Šustek +local function calc_tolerance_cubic(previous, step) + local previous = previous or tex.tolerance + local max_cycles = linebreaker.max_cycles + local max_tolerance = linebreaker.max_tolerance + local new = 100 * (cube_root(previous / 100) + (cube_root(max_tolerance/100) - cube_root(previous/100)) * (step/max_cycles))^3 + -- local new = previous + (max_tolerance / max_cycles)-- + math.sqrt(previous * 4) + return (new < max_tolerance) and new or max_tolerance +end + -- max_tolerance / max_cycles is added to the current tolerance value -local function calc_tolerance(previous) +local function calc_tolerance(previous, step) local previous = previous or tex.tolerance local max_cycles = linebreaker.max_cycles local max_tolerance = linebreaker.max_tolerance @@ -340,7 +391,9 @@ end -- try to linebreak current paragraph with increasing tolerance and -- emergencystretch -function linebreaker.best_solution(par, parameters) +function linebreaker.best_solution(par, parameters, step) + -- step is used in the tolerance calculation + local step = (step or 0) + 1 -- save current node list, because call to the linebreaker modifies it -- and we wouldn't be able to run it multiple times local head = node.copy_list(par) @@ -373,9 +426,14 @@ function linebreaker.best_solution(par, parameters) params.badness = badness if badness > 0 then -- calc new value of tolerance - local tolerance = calc_tolerance(params.tolerance) -- or 10000 + local tolerance + if linebreaker.use_cubic then + tolerance = calc_tolerance_cubic(params.tolerance, step) -- or 10000 + else + tolerance = calc_tolerance(params.tolerance, step) -- or 10000 + end -- save tolerance to newparams so this value will be used in next run - newparams.tolerance = tolerance + newparams.tolerance = math.floor(tolerance) newparams.emergencystretch = (params.emergencystretch or 0) + linebreaker.max_emergencystretch / linebreaker.max_cycles table.insert(parameters, newparams) -- run linebreaker again diff --git a/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty b/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty index 2804f4bbe69..3442adad8c2 100644 --- a/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty +++ b/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty @@ -1,3 +1,11 @@ +% linebreaker.sty +% +% (c) Michal Hoftich <michal.h21@gmail.com> +% +%% This program can be redistributed and/or modified under the terms +%% of the LaTeX Project Public License Distributed from CTAN archives +%% in directory macros/latex/base/lppl.txt. + \ProvidesPackage{linebreaker} \RequirePackage{luatexbase} @@ -16,6 +24,7 @@ luatexbase.add_to_callback("hpack_quality", linebreaker.hpack_quality, "Our over maxtolerance .code:n = \directlua{linebreaker.max_tolerance = tonumber("#1")}, maxemergencystretch .code:n = \directlua{linebreaker.max_emergencystretch = tex.sp("#1")}, maxcycles .code:n = \directlua{linebreaker.max_cycles = tonumber("#1")}, + cubic .code:n = \directlua{linebreaker.use_cubic = true} } \NewDocumentCommand{\linebreakersetup}{m}{ \keys_set:nn {linebreaker} {#1} |