1 \documentclass[10ptj]{ltjsarticle}
2 \usepackage[width=40\zw, lines=40,centering]{geometry}
3 \usepackage{amsmath,luacode,xcolor}
7 local insert = table.insert
8 local rangedimensions, max = node.rangedimensions, math.max
9 function lineskip.p_profile(before, after)
12 local w_acc, d_before = 0, 0
13 local x = before.head; local xn = x.next
16 if xn then w, _, d= rangedimensions(before,x,xn)
17 else w, _, d= rangedimensions(before,x) end
19 d_before = d; t[w_acc] = t[w_acc] or {}
20 if t[w_acc][1] then t[w_acc][1]=max(t[w_acc][1],d)
21 else t[w_acc][1]=d end
24 x = xn; if x then xn = x.next end
28 local w_acc, h_before = 0, 0
29 local x = after.head; local xn = x.next
32 if xn then w, h = rangedimensions(after,x,xn)
33 else w, h = rangedimensions(after,x) end
35 h_before = h; t[w_acc] = t[w_acc] or {}
36 if t[w_acc][2] then t[w_acc][2]=max(t[w_acc][2],h)
37 else t[w_acc][2]=h end
40 x = xn; if x then xn = x.next end
44 for i,v in pairs(t) do insert(t2, { i, v[1], v[2] } ) end
45 table.sort(t2, function(a,b) return a[1]<b[1] end)
47 local bls = tex.baselineskip.width
48 local dmax, d, hmax, h, lmin = 0, 0, 0, 0, 1/0
49 for i,v in ipairs(t2) do
50 d, h = (v[2] or d), (v[3] or h)
51 if d>dmax then dmax=d end
52 if h>hmax then hmax=h end
53 if (bls-h-d)<lmin then lmin=bls-h-d end
54 --print(v[1], d, h, bls-h-d)
56 return lmin, bls - lmin - (before.depth+after.height)
59 function lineskip.p_dummy(before, after)
60 local bls = tex.baselineskip.width
65 local setglue = node.setglue
66 local floor, min = math.floor, math.min
67 function lineskip.l_dummy(dist, g, adj, normal)
68 if dist < tex.lineskiplimit then
69 local ng = tex.lineskip; g.subtype=2
70 setglue(g, ng.width + adj, ng.stretch, ng.shrink, ng.stretch_order, ng.shrink_order)
72 local ng = tex.baselineskip; g.subtype=2
73 setglue(g, normal, ng.stretch, ng.shrink, ng.stretch_order, ng.shrink_order)
76 function lineskip.l_fixed(dist, g, adj, normal)
77 local ng = tex.baselineskip; local f = ng.width*lineskip.fixed_factor
80 normal - f * floor((dist-lineskip.fixed_mindist)/f),
81 ng.stretch, ng.shrink, ng.stretch_order, ng.shrink_order)
85 local l_profiler, l_skip = lineskip.p_dummy, lineskip.l_dummy
86 function lineskip.setting(profiler, skip_method)
87 l_profiler = lineskip['p_'..tostring(profiler)] or lineskip.p_dummy
88 l_skip = lineskip['l_'..tostring(skip_method)] or lineskip.l_dummy
91 luatexbase.add_to_callback('post_linebreak_filter',
93 for x in node.traverse_id(12, h) do
94 if (x.subtype==1)or(x.subtype==2)then
95 local p, n = x.prev, x.next
97 while ((p.id==14)or(p.id==12)or(p.id==13)) and p.prev do p = p.prev end
98 if p.id==0 and n.id==0 then
99 local normal = tex.baselineskip.width - p.depth - n.height
100 local lmin, adj; lmin, adj = l_profiler(p,n)
101 l_skip(lmin or normal,x,adj, normal)
102 print(p.depth, x.width, n.height, p.depth+x.width+n.height)
113 lineskip.fixed_mindist = tex.lineskip.width
114 lineskip.fixed_factor = 0.5
118 \def\R#1#2{\directlua{lineskip.setting('#1','#2')}%
119 \noindent\fbox{\parbox{25\zw}{%
120 \baselineskip14pt\noindent
121 \setbox2=\vtop{\noindent\hsize20\zw\textcolor{cyan!30!white}{%
122 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
123 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
124 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
125 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
126 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
127 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
128 □□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■□□□□■
130 }}\dp2=0pt\rlap{\copy2}\par\vspace*{-\baselineskip}
132 \the\baselineskip あああああああああああああああ\\
133 あああああああああ$X_{X_{X_X}}$ああああああ\\
135 ……であるから$b=\dfrac1{X_2}$となる.\\
136 一方$\dfrac{A^A}{B_B}=21$なので……\\
137 ……であるから$b=\dfrac1{X_2}$となる.\vadjust{あああああ$\dfrac34$}\\
138 一方$\dfrac{A^A}{B_B}=21$なので……
140 ……であるから$b=\dfrac1{X_2}$となる.\\
141 一方$\dfrac{A^A}{B_B}=21$なので……