summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/lua-typo
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-09-13 20:38:02 +0000
committerKarl Berry <karl@freefriends.org>2023-09-13 20:38:02 +0000
commit24d9e92a6caf1b7640791230b17f4b08899cdd67 (patch)
treec26b97a46d5389f0e6d37bdde0cb52811ee03f1b /Master/texmf-dist/tex/lualatex/lua-typo
parentddba248d30b6607705e28844891122a07d94e698 (diff)
lua-typo (13sep23)
git-svn-id: svn://tug.org/texlive/trunk@68267 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/lua-typo')
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.cfg9
-rw-r--r--Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.sty226
2 files changed, 181 insertions, 54 deletions
diff --git a/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.cfg b/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.cfg
index fe9b2438312..32f6ade6cf8 100644
--- a/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.cfg
+++ b/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.cfg
@@ -24,8 +24,12 @@
\luatypoMinPart=4\relax
%% Minimum number of characters for the first word on a page if it ends
-%% a sentence.
-\luatypoMinLen=4\relax
+%% a sentence (version >= 0.65).
+\ifdefined\luatypoMinLen \luatypoMinLen=4\relax\fi
+
+%% Acceptable marginpars must end at |\luatypoMarginparTol| under
+%% the page’s last line or above (version >= 0.85).
+\ifdefined\luatypoMarginparTol \luatypoMarginparTol=\baselineskip \fi
%% Default colours = red, cyan, blue, LTgrey, LTred, LTline.
\definecolor{LTgrey}{gray}{0.6}
@@ -47,6 +51,7 @@
\luatypoSetColor{14}{cyan}% Footnote split
\luatypoSetColor{15}{red}% Too short first (final) word on the page
\luatypoSetColor{16}{LTline}% Line color for multiple flaws
+\luatypoSetColor{17}{red}% Margin note ending too low
%% Language specific settings (example for French):
%% short words (two letters max) to be avoided at end of lines.
diff --git a/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.sty b/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.sty
index ef9040c4013..92f1c05ba18 100644
--- a/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.sty
+++ b/Master/texmf-dist/tex/lualatex/lua-typo/lua-typo.sty
@@ -11,10 +11,10 @@
%%
\NeedsTeXFormat{LaTeX2e}[2021/06/01]
\ProvidesPackage{lua-typo}
- [2023-04-28 v.0.80 Daniel Flipo]
+ [2023-09-13 v.0.85 Daniel Flipo]
\DeclareRelease{v0.4}{2021-01-01}{lua-typo-2021-04-18.sty}
\DeclareRelease{v0.65}{2023-03-08}{lua-typo-2023-03-08.sty}
-\DeclareCurrentRelease{}{2023-04-12}
+\DeclareCurrentRelease{}{2023-09-13}
\ifdefined\directlua
\RequirePackage{luatexbase,luacode,luacolor,atveryend}
\else
@@ -24,6 +24,7 @@
\newdimen\luatypoLLminWD
\newdimen\luatypoBackPI
\newdimen\luatypoBackFuzz
+\newdimen\luatypoMarginparTol
\newcount\luatypoStretchMax
\newcount\luatypoHyphMax
\newcount\luatypoPageMin
@@ -56,6 +57,7 @@ luatypo = { }
LastWordMatch.if = LT@LastWordMatch ,
FootnoteSplit.if = LT@FootnoteSplit ,
ShortFinalWord.if = LT@ShortFinalWord ,
+ MarginparPos.if = LT@MarginparPos ,
All.if = LT@All ,
All.code = \LT@ShortLinestrue \LT@ShortPagestrue
\LT@OverfullLinestrue \LT@UnderfullLinestrue
@@ -64,7 +66,7 @@ luatypo = { }
\LT@ParLastHyphentrue \LT@EOLShortWordstrue
\LT@FirstWordMatchtrue \LT@LastWordMatchtrue
\LT@BackParindenttrue \LT@FootnoteSplittrue
- \LT@ShortFinalWordtrue
+ \LT@ShortFinalWordtrue \LT@MarginparPostrue
}
\ProcessKeyOptions[luatypo]
\AtEndOfPackage{%
@@ -163,6 +165,12 @@ luatypo = { }
\else
\directlua{ luatypo.ShortFinalWord = false }%
\fi
+ \ifLT@MarginparPos
+ \advance\luatypo@options by 1
+ \directlua{ luatypo.MarginparPos = true }%
+ \else
+ \directlua{ luatypo.MarginparPos = false }%
+ \fi
}
\ifLT@ShowOptions
\GenericWarning{* }{%
@@ -187,6 +195,7 @@ luatypo = { }
LastWordMatch [false]\MessageBreak
FootnoteSplit [false]\MessageBreak
ShortFinalWord [false]\MessageBreak
+ MarginparPos [false]\MessageBreak
\MessageBreak
*********************************************%
\MessageBreak Lua-typo [ShowOptions]
@@ -199,11 +208,12 @@ luatypo = { }
luatypo.Stretch = tex.count.luatypoStretchMax
luatypo.MinFull = tex.count.luatypoMinFull
luatypo.MinPart = tex.count.luatypoMinPart
- luatypo.MinFull = math.min(luatypo.MinPart,luatypo.MinFull)
- luatypo.MinLen = tex.count.luatypoMinLen
- luatypo.LLminWD = tex.dimen.luatypoLLminWD
- luatypo.BackPI = tex.dimen.luatypoBackPI
- luatypo.BackFuzz = tex.dimen.luatypoBackFuzz
+ luatypo.MinFull = math.min(luatypo.MinPart,luatypo.MinFull)
+ luatypo.MinLen = tex.count.luatypoMinLen
+ luatypo.LLminWD = tex.dimen.luatypoLLminWD
+ luatypo.BackPI = tex.dimen.luatypoBackPI
+ luatypo.BackFuzz = tex.dimen.luatypoBackFuzz
+ luatypo.MParTol = tex.dimen.luatypoMarginparTol
local tbl = luatypo.colortbl
local map = { }
for i,v in ipairs (luatypo.colortbl) do
@@ -230,14 +240,27 @@ luatypo = { }
texio.write_nl(' ')
texio.write_nl('*************************************')
if luatypo.pagelist == " " then
- texio.write_nl('*** lua-typo: No Typo Flaws found.')
+ if luatypo.failedlist == " " then
+ texio.write_nl('*** lua-typo: No Typo Flaws found.')
+ else
+ texio.write_nl('*** WARNING: ')
+ texio.write('lua-typo failed to scan these pages:')
+ texio.write_nl('***' .. luatypo.failedlist)
+ texio.write_nl('*** Please report to the maintainer.')
+ end
else
texio.write_nl('*** lua-typo: WARNING *************')
texio.write_nl('The following pages need attention:')
texio.write(luatypo.pagelist)
end
- texio.write_nl('***********************************')
+ texio.write_nl('*************************************')
texio.write_nl(' ')
+ if luatypo.failedlist == " " then
+ else
+ local prt = "WARNING: lua-typo failed to scan pages " ..
+ luatypo.failedlist .. "\string\n\string\n"
+ luatypo.buffer = prt .. luatypo.buffer
+ end
local fileout= tex.jobname .. ".typo"
local out=io.open(fileout,"w+")
out:write(luatypo.buffer)
@@ -285,13 +308,14 @@ luatypo = { }
\endgroup
}
\begin{luacode}
-luatypo.colortbl = { }
-luatypo.map = { }
-luatypo.single = { }
-luatypo.double = { }
-luatypo.pagelist = " "
-luatypo.buffer = "List of typographic flaws found for "
- .. tex.jobname .. ".pdf:\string\n\string\n"
+luatypo.colortbl = { }
+luatypo.map = { }
+luatypo.single = { }
+luatypo.double = { }
+luatypo.pagelist = " "
+luatypo.failedlist = " "
+luatypo.buffer = "List of typographic flaws found for "
+ .. tex.jobname .. ".pdf:\string\n\string\n"
local char_to_discard = { }
char_to_discard[string.byte(",")] = true
@@ -894,6 +918,75 @@ local check_EOP = function (node)
end
return page_bot, body_bot
end
+local check_marginnote = function (head, line, colno, vpos, bpmn)
+ local OverfullLines = luatypo.OverfullLines
+ local UnderfullLines = luatypo.UnderfullLines
+ local MarginparPos = luatypo.MarginparPos
+ local margintol = luatypo.MParTol
+ local marginpp = tex.getdimen("marginparpush")
+ local pflag = false
+ local ofirst = true
+ local ufirst = true
+ local n = head.head
+ local bottom = vpos
+ if vpos <= bpmn then
+ bottom = bpmn + marginpp
+ end
+ repeat
+ if n and (n.id == GLUE or n.id == PENALTY) then
+ n = n.next
+ elseif n and n.id == VLIST then
+ n = n.head
+ end
+ until not n or (n.id == HLIST and n.subtype == LINE)
+ local head = n
+ if head then
+ else
+ end
+ local last = head
+ while head do
+ local next = head.next
+ if head.id == HLIST and head.subtype == LINE then
+ bottom = bottom + head.height + head.depth
+ local first = head.head
+ local linewd = head.width
+ local hmax = linewd + tex.hfuzz
+ local w,h,d = dimensions(1,2,0, first)
+ local Stretch = math.max(luatypo.Stretch/100,1)
+ if w > hmax and OverfullLines then
+ pflag = true
+ local COLOR = luatypo.colortbl[8]
+ color_line (head, COLOR)
+ if ofirst then
+ local msg = "OVERFULL line(s) in margin note"
+ log_flaw(msg, line, colno, false)
+ ofirst = false
+ end
+ elseif head.glue_set > Stretch and head.glue_sign == 1 and
+ head.glue_order == 0 and UnderfullLines then
+ pflag = true
+ local COLOR = luatypo.colortbl[9]
+ color_line (head, COLOR)
+ if ufirst then
+ local msg = "UNDERFULL line(s) in margin note"
+ log_flaw(msg, line, colno, false)
+ ufirst = false
+ end
+ end
+ end
+ last = head
+ head = next
+ end
+ local textht = tex.getdimen("textheight")
+ if bottom > textht + margintol and MarginparPos then
+ pflag = true
+ local COLOR = luatypo.colortbl[17]
+ color_line (last, COLOR)
+ local msg = "Margin note too low"
+ log_flaw(msg, line, colno, false)
+ end
+ return bottom, pflag
+end
local get_pagebody = function (head)
local textht = tex.getdimen("textheight")
local fn = head.list
@@ -917,7 +1010,7 @@ local get_pagebody = function (head)
end
end
if not body then
- texio.write_nl("***lua-typo ERROR: PAGE BODY *NOT* FOUND!***")
+ texio.write_nl('***lua-typo ERROR: PAGE BODY *NOT* FOUND!***')
end
return body
end
@@ -949,6 +1042,7 @@ check_vtop = function (top, colno, vpos)
vpos_min = vpos_min * 1.5
local linewd = tex.getdimen("textwidth")
local first_bot = true
+ local done = false
local footnote = false
local ftnsplit = false
local orphanflag = false
@@ -964,6 +1058,7 @@ check_vtop = function (top, colno, vpos)
local pageline = 0
local ftnline = 0
local line = 0
+ local bpmn = 0
local body_bottom = false
local page_bottom = false
local pageflag = false
@@ -973,6 +1068,7 @@ check_vtop = function (top, colno, vpos)
if head.id == HLIST and head.subtype == LINE and
(head.height > 0 or head.depth > 0) then
vpos = vpos + head.height + head.depth
+ done = true
local linewd = head.width
local first = head.head
local ListItem = false
@@ -1024,20 +1120,23 @@ check_vtop = function (top, colno, vpos)
elseif not footnote then
parline = parline + 1
end
- if FirstWordMatch then
- local flag = not ListItem and (line > 1)
- firstwd, flag =
- check_line_first_word(firstwd, first, line, colno,
- flag, footnote)
- if flag then
- pageflag = true
- end
+ if FirstWordMatch then
+ local flag = not ListItem and (line > 1)
+ firstwd, flag =
+ check_line_first_word(firstwd, first, line, colno,
+ flag, footnote)
+ if flag then
+ pageflag = true
end
+ end
if ShortFinalWord and pageline == 1 and parline > 1 and
check_page_first_word(first, colno, footnote) then
pageflag = true
end
local ln = slide(first)
+ if ln.id == RULE and ln.subtype == 0 then
+ ln = ln.prev
+ end
local pn = ln.prev
if pn and pn.id == GLUE and pn.subtype == PARFILL then
hyphcount = 0
@@ -1189,6 +1288,22 @@ check_vtop = function (top, colno, vpos)
color_line (head, COLOR)
backpar = false
end
+ elseif head and head.id == HLIST and head.subtype == BOX and
+ head.width > 0 then
+ if head.height == 0 then
+ bpmn, pflag = check_marginnote(head, line, colno, vpos, bpmn)
+ if pflag then pageflag = true end
+ else
+ local hf = head.list
+ if hf and hf.id == VLIST and hf.subtype == 0 then
+ break
+ else
+ vpos = vpos + head.height + head.depth
+ pageline = pageline + 1
+ line = pageline
+ page_bottom, body_bottom = check_EOP (nextnode)
+ end
+ end
elseif head.id == HLIST and
(head.subtype == EQN or head.subtype == ALIGN) and
(head.height > 0 or head.depth > 0) then
@@ -1268,15 +1383,6 @@ check_vtop = function (top, colno, vpos)
vpos = vpos + head.kern
elseif head.id == VLIST then
vpos = vpos + head.height + head.depth
- elseif head.id == HLIST and head.subtype == BOX then
- vpos = vpos + head.height + head.depth
- pageline = pageline + 1
- line = pageline
- page_bottom, body_bottom = check_EOP (nextnode)
- local hf = head.list
- if hf and hf.id == VLIST and hf.subtype == 0 then
- break
- end
end
head = nextnode
end
@@ -1287,30 +1393,37 @@ check_vtop = function (top, colno, vpos)
luatypo.pagelist = luatypo.pagelist .. tostring(pageno) .. ", "
end
end
- return head
+ return head, done
end
luatypo.check_page = function (head)
local textwd = tex.getdimen("textwidth")
- local vpos = 0
- local n2, n3, col, colno
+ local textht = tex.getdimen("textheight")
+ local checked, boxed, n2, n3, col, colno
local body = get_pagebody(head)
+ local pageno = tex.getcount("c@page")
+ local vpos = 0
local footnote = false
local top = body
local first = body.list
- if (first and first.id == HLIST and first.subtype == BOX) or
- (first and first.id == VLIST and first.subtype == 0) then
+ local next
+ local count = 0
+ if ((first and first.id == HLIST and first.subtype == BOX) or
+ (first and first.id == VLIST and first.subtype == 0)) and
+ (first.width == textwd and first.height > 0 and not boxed) then
top = body.list
- first = top.list
+ if first.id == VLIST then
+ boxed = body
+ end
end
while top do
first = top.list
+ next = top.next
if top and top.id == VLIST and top.subtype == 0 and
- top.width > textwd/2 then
- local next = check_vtop(top,colno,vpos)
- if next then
- top = next
- elseif top then
- top = top.next
+ top.width > textwd/2 then
+ local n, ok = check_vtop(top,colno,vpos)
+ if ok then checked = true end
+ if n then
+ next = n
end
elseif (top and top.id == HLIST and top.subtype == BOX) and
(first and first.id == VLIST and first.subtype == 0) and
@@ -1318,7 +1431,8 @@ luatypo.check_page = function (head)
colno = 0
for col in traverse_id(VLIST, first) do
colno = colno + 1
- check_vtop(col,colno,vpos)
+ local n, ok = check_vtop(col,colno,vpos)
+ if ok then checked = true end
end
colno = nil
top = top.next
@@ -1330,14 +1444,20 @@ luatypo.check_page = function (head)
colno = colno + 1
local col = n.list
if col and col.list then
- check_vtop(col,colno,vpos)
+ local n, ok = check_vtop(col,colno,vpos)
+ if ok then checked = true end
end
end
colno = nil
- top = top.next
- else
- top = top.next
end
+ if boxed and not next then
+ next = boxed
+ boxed = nil
+ end
+ top = next
+ end
+ if not checked then
+ luatypo.failedlist = luatypo.failedlist .. tostring(pageno) .. ", "
end
return true
end
@@ -1374,6 +1494,7 @@ return luatypo.check_page
\luatypoSetColor{14}{cyan}% Footnote split
\luatypoSetColor{15}{red}% Too short first (final) word on the page
\luatypoSetColor{16}{LTline}% Line color for multiple flaws
+ \luatypoSetColor{17}{red}% Margin note ending too low
\luatypoBackPI=1em\relax
\luatypoBackFuzz=2pt\relax
\ifdim\parindent=0pt \luatypoLLminWD=20pt\relax
@@ -1384,6 +1505,7 @@ return luatypo.check_page
\luatypoMinFull=3\relax
\luatypoMinPart=4\relax
\luatypoMinLen=4\relax
+ \luatypoMarginparTol=\baselineskip
}%
%%
%%