texlive[66443] branches/branch2022.final/Master/texmf-dist:

commits+karl at tug.org commits+karl at tug.org
Tue Mar 7 23:23:07 CET 2023


Revision: 66443
          http://tug.org/svn/texlive?view=revision&revision=66443
Author:   karl
Date:     2023-03-07 23:23:07 +0100 (Tue, 07 Mar 2023)
Log Message:
-----------
linebreaker (7mar23) (branch)

Modified Paths:
--------------
    branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/README.md
    branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf
    branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex
    branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua
    branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty

Modified: branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/README.md
===================================================================
--- branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/README.md	2023-03-07 22:22:41 UTC (rev 66442)
+++ branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/README.md	2023-03-07 22:23:07 UTC (rev 66443)
@@ -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 @@
 
 ## License
 
+Author: Michal Hoftich <michal.h21 at 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.
 

Modified: branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.pdf
===================================================================
(Binary files differ)

Modified: branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex
===================================================================
--- branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex	2023-03-07 22:22:41 UTC (rev 66442)
+++ branches/branch2022.final/Master/texmf-dist/doc/lualatex/linebreaker/linebreaker-doc.tex	2023-03-07 22:23:07 UTC (rev 66443)
@@ -140,6 +140,11 @@
 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 @@
 \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}

Modified: branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua
===================================================================
--- branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua	2023-03-07 22:22:41 UTC (rev 66442)
+++ branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.lua	2023-03-07 22:23:07 UTC (rev 66443)
@@ -1,3 +1,11 @@
+--  linebreaker.lua
+-- 
+--  (c) Michal Hoftich <michal.h21 at 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 @@
 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.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 @@
 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 @@
 
 -- 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 @@
   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

Modified: branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty
===================================================================
--- branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty	2023-03-07 22:22:41 UTC (rev 66442)
+++ branches/branch2022.final/Master/texmf-dist/tex/lualatex/linebreaker/linebreaker.sty	2023-03-07 22:23:07 UTC (rev 66443)
@@ -1,3 +1,11 @@
+% linebreaker.sty
+%
+% (c) Michal Hoftich <michal.h21 at 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 @@
   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}



More information about the tex-live-commits mailing list.