| 1 |
\ProvidesPackage |
| 2 |
{lualineno} [2026-02-12 v0.1 |
| 3 |
Line numbering in LuaTeX] |
| 4 |
|
| 5 |
\directlua{require('lualineno')} |
| 6 |
\AddToHook{build/page/reset}{\lualineno{unset}} |
| 7 |
|
| 8 |
\AddToHook{package/multicol/after}{% |
| 9 |
\directlua{ |
| 10 |
local replace = "\csstring\\\csstring\\directlua { |
| 11 |
local right_box = token.create('mult@rightbox').index |
| 12 |
local col_attr = luatexbase.attributes['lualineno_col'] |
| 13 |
local i = right_box |
| 14 |
local last = tex.count['doublecol@number'] - 2 |
| 15 |
local column = 0 |
| 16 |
while i < last do |
| 17 |
i = i + 2 |
| 18 |
column = column + 1 |
| 19 |
tex.box[i][col_attr] = column |
| 20 |
end |
| 21 |
tex.box[right_box][col_attr] = column + 1}\csstring\\\csstring\\mc@align@columns" |
| 22 |
local find = "\csstring\\\csstring\\mc@align@columns" |
| 23 |
local patch, success = token.get_macro("page@sofar"):gsub(find, replace) |
| 24 |
if success > 0 then |
| 25 |
token.set_macro("page@sofar", patch) |
| 26 |
else |
| 27 |
texio.write_nl('log', "lualineno: failed to patch |
| 28 |
\csstring\\\csstring\\page@sofar (multicol)") |
| 29 |
end}} |
| 30 |
|
| 31 |
\AddToHook{package/balance/after}{% |
| 32 |
\expandafter\renewcommand\expandafter |
| 33 |
\@BAlancecol\expandafter{\@BAlancecol\directlua{ |
| 34 |
local sec_col = token.create('@outputbox').index |
| 35 |
local first_col = token.create('@leftcolumn').index |
| 36 |
local col_attr = luatexbase.attributes['lualineno_col'] |
| 37 |
tex.box[sec_col][col_attr] = 2 |
| 38 |
tex.box[first_col][col_attr] = 1}}} |
| 39 |
|
| 40 |
\AddToHook{package/flushend/after}{% |
| 41 |
\directlua{ |
| 42 |
local replace = "\csstring\\\csstring\\set@outputbox@with@footnote@and@float |
| 43 |
\csstring\\\csstring\\fi \csstring\\\csstring\\directlua { |
| 44 |
local sec_col = token.create('@outputbox').index |
| 45 |
local first_col = token.create('@leftcolumn').index |
| 46 |
local col_attr = luatexbase.attributes['lualineno_col'] |
| 47 |
tex.box[sec_col][col_attr] = 2 |
| 48 |
tex.box[first_col][col_attr] = 1}" |
| 49 |
local find = "\csstring\\\csstring\\set@outputbox@with@footnote@and@float |
| 50 |
\csstring\\\csstring\\fi " |
| 51 |
local patch, success = token.get_macro("last@outputdblcol"):gsub(find, replace) |
| 52 |
if success > 0 then |
| 53 |
token.set_macro("last@outputdblcol", patch) |
| 54 |
else |
| 55 |
texio.write_nl('log', "lualineno: failed to patch |
| 56 |
\csstring\\\csstring\\last@outputdblcol (flushend)") |
| 57 |
end}} |
| 58 |
|
| 59 |
\AddToHook{package/ltxgrid/after}{% |
| 60 |
\def\box@column#1{% |
| 61 |
\ltxgrid@info@sw{\class@info{\string\box@column\string#1}}{}% |
| 62 |
\raise\topskip |
| 63 |
\hb@xt@\columnwidth\bgroup |
| 64 |
\dimen@\ht#1\@ifdim{\dimen@>\@colht}{\dimen@\@colht}{}% |
| 65 |
\count@\vbadness\vbadness\@M |
| 66 |
\dimen@ii\vfuzz\vfuzz\maxdimen |
| 67 |
\ltxgrid@info@sw{\saythe\@colht\saythe\dimen@}{}% |
| 68 |
\vtop attr \directlua{tex.print(luatexbase.attributes['lualineno_col'])} |
| 69 |
= \pagegrid@cur to\dimen@\bgroup |
| 70 |
\hrule\@height\z@ |
| 71 |
\unvbox#1% |
| 72 |
\raggedcolumn@skip |
| 73 |
\egroup |
| 74 |
\vfuzz\dimen@ii |
| 75 |
\vbadness\count@ |
| 76 |
\hss |
| 77 |
\egroup |
| 78 |
}} |
| 79 |
|
| 80 |
\AddToHook{package/breqn/after}{% |
| 81 |
\directlua{ |
| 82 |
local replace = "\csstring\\\csstring\\directlua { |
| 83 |
local box = tex.getbox('EQ@numbox') |
| 84 |
if box then |
| 85 |
local n = node.copy_list(box) |
| 86 |
n.subtype = 7 |
| 87 |
node.write(n) |
| 88 |
end}" |
| 89 |
local find = "\csstring\\\csstring\\copy \csstring\\\csstring\\EQ@numbox " |
| 90 |
local function patch_breqn(macro) |
| 91 |
local patch, success = token.get_macro(macro):gsub(find, replace) |
| 92 |
if success > 0 then |
| 93 |
token.set_macro(macro, patch) |
| 94 |
else |
| 95 |
texio.write_nl('log', "lualineno: failed to patch |
| 96 |
\csstring\\\csstring\\" .. macro .. " (breqn)") |
| 97 |
end |
| 98 |
end |
| 99 |
patch_breqn("eq@typeset@RShifted") |
| 100 |
patch_breqn("eq@typeset@LShifted") |
| 101 |
patch_breqn("eq@typeset@rightnumber") |
| 102 |
patch_breqn("eq@typeset@leftnumber") |
| 103 |
}} |
| 104 |
|
| 105 |
|
| 106 |
\endinput |