Debian Codegraph @

texmf-dist/source/latex/wrapstuff/wrapstuff.dtx

raw
1 % \iffalse meta-comment
2 % !TeX program = XeLaTeX
3 % !TeX encoding = UTF-8
4 %<*internal>
5 \iffalse
6 %</internal>
7 %<*readme>
8 wrapstuff
9 =========
10
11 The `wrapstuff` package provides another implementation of text wrapping.
12 Its implementation benefits from the paragraph hooks available since
13 LaTeX 2021-06-01.
14
15 Basic Usage
16 -----------
17 The package only provides a user environment `wrapstuff`.
18
19 \begin{wrapstuff}[<options>]
20 <wrapping stuff>
21 \end{wrapstuff}
22 <main text>
23
24 You can read the package manual (in Chinese) for some explanations.
25
26 Contributing
27 ------------
28 The package is still highly experimental and not fully tested.
29 [Issues](https://github.com/qinglee/wrapstuff/issues) and
30 [pull requests](https://github.com/qinglee/wrapstuff/pulls)
31 are always welcome.
32
33 Copyright and Licence
34 ---------------------
35
36 Copyright (C) 2022 by Qing Lee <[email protected]>
37 -----------------------------------------------------------------
38
39 This work may be distributed and/or modified under the
40 conditions of the LaTeX Project Public License, either
41 version 1.3c of this license or (at your option) any later
42 version. This version of this license is in
43 http://www.latex-project.org/lppl/lppl-1-3c.txt
44 and the latest version of this license is in
45 http://www.latex-project.org/lppl.txt
46 and version 1.3 or later is part of all distributions of
47 LaTeX version 2005/12/01 or later.
48
49 This work has the LPPL maintenance status "maintained".
50
51 The Current Maintainer of this work is Qing Lee.
52
53 This package consists of the file wrapstuff.dtx,
54 and the derived files wrapstuff.pdf,
55 wrapstuff.sty,
56 wrapstuff.ins and
57 README.md (this file).
58 %</readme>
59 %<*internal>
60 \fi
61 \begingroup
62 \def\temp{LaTeX2e}
63 \expandafter\endgroup\ifx\temp\fmtname\else
64 \csname fi\endcsname
65 %</internal>
66 %<*install>
67
68 \input ctxdocstrip %
69
70 \preamble
71
72 Copyright (C) 2022 by Qing Lee <[email protected]>
73 -----------------------------------------------------------------
74
75 This work may be distributed and/or modified under the
76 conditions of the LaTeX Project Public License, either
77 version 1.3c of this license or (at your option) any later
78 version. This version of this license is in
79 http://www.latex-project.org/lppl/lppl-1-3c.txt
80 and the latest version of this license is in
81 http://www.latex-project.org/lppl.txt
82 and version 1.3 or later is part of all distributions of
83 LaTeX version 2005/12/01 or later.
84
85 This work has the LPPL maintenance status "maintained".
86
87 The Current Maintainer of this work is Qing Lee.
88
89 -----------------------------------------------------------------
90
91 \endpreamble
92
93 \postamble
94
95 This work consists of the file wrapstuff.dtx,
96 and the derived files wrapstuff.pdf,
97 wrapstuff.sty,
98 wrapstuff.ins and
99 README.md.
100 \endpostamble
101
102 \generate
103 {
104 %</install>
105 %<*internal>
106 \usedir{source/latex/wrapstuff}
107 \file{wrapstuff.ins} {\from{\jobname.dtx}{install}}
108 %</internal>
109 %<*install>
110 \usedir{tex/latex/wrapstuff}
111 \file{wrapstuff.sty} {\from{\jobname.dtx}{package}}
112 \nopreamble\nopostamble
113 \usedir{doc/latex/wrapstuff}
114 \file{README.md} {\from{\jobname.dtx}{readme}}
115 }
116
117 \endbatchfile
118 %</install>
119 %<*internal>
120 \fi
121 %</internal>
122 %<package>\NeedsTeXFormat{LaTeX2e}[2021-06-01]
123 %<package>\@ifundefined{ExplLoaderFileDate}{\RequirePackage{expl3}}{}
124 %<+package>\GetIdInfo$Id: wrapstuff.dtx 3be38c0 2022-08-05 21:01:02 +0800 Qing Lee <[email protected]> $
125 %<package> {Wrapping text around stuff}
126 %<package>\ProvidesExplPackage{\ExplFileName}
127 %<package> {\ExplFileDate}{0.3}{\ExplFileDescription}
128 %<*driver>
129 \documentclass{ctxdoc}
130 \usepackage{wrapstuff}
131 \usepackage{graphicx}
132 \usepackage{zhlipsum}
133 \ExplSyntaxOn
134 \makeatletter
135 \DeclareDocumentCommand \gitsha { m }
136 {
137 \href { https \c_colon_str //github.com/qinglee/wrapstuff/commit/#1 }
138 { rev. ~ \texttt{#1} }
139 }
140 \DeclareDocumentCommand \QIANZIWEN { }
141 {
142 天地玄黄宇宙洪荒日月盈昃辰宿列张
143 寒来暑往秋收冬藏闰馀成岁律召调阳 \par
144 云腾致雨露结为霜金生丽水玉出昆冈 \par
145 }
146 \DeclareDocumentCommand \ADDSPECEIALKEY { m }
147 {
148 \cs_gset_eq:NN \@@_codedoc_names_typeset_save:
149 \__codedoc_names_typeset:
150 \cs_gset_protected:Npn \__codedoc_names_typeset:
151 {
152 \cs_gset_eq:NN \__codedoc_names_typeset:
153 \@@_codedoc_names_typeset_save:
154 \__codedoc_names_typeset:
155 #1 \\
156 }
157 }
158 \DeclareDocumentCommand \IMAGE { m m }
159 { \includegraphics [ width = \dim_eval:n {#1} ] { example-image-#2.pdf } }
160 \tl_put_left:Nn \Example
161 { \trivlist \item \relax }
162 \tl_put_right:Nn \endExample
163 { \endtrivlist }
164 \SideBySideExampleSet { numbers = none }
165 \makeatother
166 \ExplSyntaxOff
167 \begin{document}
168 \DocInput{\jobname.dtx}
169 \IndexLayout
170 \PrintChanges
171 \PrintIndex
172 \end{document}
173 %</driver>
174 % \fi
175 %
176 % \CheckSum{3127}
177 %
178 % \changes{v0.1}{2022/07/05}{初始版本。}
179 % \changes{v0.1}{2022/07/20}{首次提交到 CTAN 发布。}
180 % \changes{v0.2}{2022/07/21}{改进放置方式。}
181 %
182 % \GetFileId{wrapstuff.sty}
183 %
184 % \title{\bfseries\pkg{wrapstuff} 宏包}
185 % \author{李清}
186 % \date{\filedate\qquad\fileversion\thanks{\gitsha{\ExplFileVersion}.}}
187 % \maketitle
188 %
189 % \begin{documentation}
190 %
191 % \section{基本用法}
192 %
193 % \pkg{wrapstuff} 宏包提供了图文绕排的另一种实现。
194 % \pkg{wrapstuff} 尝试整合和扩展 \pkg{picinpar}、\pkg{floatflt}、\pkg{wrapfig}、
195 % \pkg{cutwin} 和 \pkg{wrapfig2} 等同类宏包的功能。
196 % 本宏包兼容 \pkg{caption}、\pkg{float} 和 \pkg{floatrow} 等宏包,
197 % 并试图兼容显示(display)数学公式和各种 \LaTeX\ 列表环境,可以让他们正确绕排。
198 %
199 % \pkg{wrapstuff} 的实现依赖 \LaTeX\ 2021-06-01 开始提供的段落钩子,
200 % 并依赖 \LaTeXiii\ 2022-04-10 之后的版本。
201 %
202 % \begin{function}{wrapstuff}
203 % \begin{syntax}
204 % \tn{begin}\{wrapstuff\}\oarg{选项}
205 % <绕排内容>
206 % \tn{end}\{wrapstuff\}
207 % <正文>
208 % \end{syntax}
209 % \pkg{wrapstuff} 只提供了一个用户环境 \env{wrapstuff},
210 % 会在环境之后的段落开始绕排。例如
211 % \begin{Example}[frame=single,numbers=none,gobble=5]
212 % \begin{wrapstuff}[c,top=1]
213 % \includegraphics[width=\dimeval{\linewidth/3}]{example-image.pdf}
214 % \end{wrapstuff}
215 % \zhlipsum[1][name=zhufu]
216 % \end{Example}
217 % \end{function}
218 %
219 % \begin{function}{\wrapstuffset}
220 % \begin{syntax}
221 % \tn{wrapstuffset} \Arg{选项列表}
222 % \end{syntax}
223 % \pkg{wrapstuff} 的选项可以在调用宏包时设置,也可以通过 \tn{wrapstuffset} 设置。
224 % 选项将在下面描述。
225 % \end{function}
226 %
227 % \ADDSPECEIALKEY{\textrm{\meta{n}}}
228 % \begin{function}{top}
229 % \begin{syntax}
230 % top = <非负整数>
231 % \end{syntax}
232 % 设置在正文段落的第几行之后开始绕排,可以设置为非负整数。
233 % 非负整数选项 \meta{n} 是设置选项 \opt{top} 为 \meta{n} 的缩写形式。
234 % 初始值是 \num{0}。
235 % \end{function}
236 %
237 % \begin{function}{width}
238 % \begin{syntax}
239 % width = <宽度>
240 % \end{syntax}
241 % 设置绕排内容的宽度,初始值为 \qty{0}{pt},代表自然宽度。
242 % 此时,\env{wrapstuff} 环境内的内容只能有一行,不能使用 |\\| 换行或者 \tn{par} 分段。
243 % 如果需要在环境内换行或者分段,就需要将 \opt{width} 设置成合适的宽度。
244 % \end{function}
245 %
246 % \begin{function}{height}
247 % \begin{syntax}
248 % height = <高度>
249 % \end{syntax}
250 % 设置绕排内容的高度,初始值为 \qty{0}{pt},代表自然高度。
251 % \end{function}
252 %
253 % \begin{function}{lines}
254 % \begin{syntax}
255 % lines = <正整数>
256 % \end{syntax}
257 % 设置绕排内容占据正文的行数,可以设置正整数。
258 % 初始值为空,根据绕排内容的高度自动计算行数。
259 % \end{function}
260 %
261 % \begin{function}{linewidth}
262 % \begin{syntax}
263 % linewidth = <宽度>
264 % \end{syntax}
265 % 设置正文段落的行宽,初始设置为 |\linewidth|,一般不需要调整。
266 % \end{function}
267 %
268 % \begin{function}{l,r,c,i,o,ratio}
269 % \begin{syntax}
270 % l/r/c/i/o
271 % ratio = <实数>
272 % \end{syntax}
273 % 这些选项用于设置绕排内容位于正文中的位置。
274 % 选项 \opt{l/r/c/i/o} 分别设置绕排内容位于正文的左侧、右侧、中间、内侧、外侧。
275 % 选项 \opt{ratio} 设置绕排内容左侧的正文占据行宽的比例,可以设置为 $[0,1]$ 区间中的合理实数。
276 % 选项 \opt{i/o} 可以与 \opt{ratio} 一起使用,这时设置的是内/外侧正文的行宽比例。
277 % 初始设置为 |r|,即位于正文的右侧。
278 % \end{function}
279 %
280 % \begin{function}{column}
281 % \begin{syntax}
282 % column = <(true)|false|par>
283 % \end{syntax}
284 % 控制是否将绕排内容两侧的正文分栏显示,只有设置 |c| 选项或者
285 % 设置 \opt{ratio} 不等于 $0$ 或者 $1$ 时才有效。
286 % \opt{false} 表示不分栏,正文文字方向始终保持从左到右的顺序;
287 % \opt{par} 表示以段落为单位进行分栏,如下示例。
288 % \begin{SideBySideExample}[xrightmargin=\dimeval{20em+5mm}]
289 % \begin{wrapstuff}[c,1]
290 % \IMAGE{2em}{a}
291 % \end{wrapstuff}
292 % \QIANZIWEN
293 % \begin{wrapstuff}[c,1,column=par]
294 % \IMAGE{2em}{b}
295 % \end{wrapstuff}
296 % \QIANZIWEN
297 % \begin{wrapstuff}[c,0,column=false]
298 % \IMAGE{2em}{c}
299 % \end{wrapstuff}
300 % \QIANZIWEN
301 % \end{SideBySideExample}
302 % \end{function}
303 %
304 % \begin{function}{leftsep,rightsep,hsep}
305 % \begin{syntax}
306 % leftsep = <长度>
307 % rightsep = <长度>
308 % hsep = <长度>
309 % \end{syntax}
310 % 设置绕排内容与正文的左/右间距,选项 \opt{hsep} 同时设置 \opt{leftsep} 和 \opt{rightsep}。
311 % 初始值是 \qty{1}{em}。
312 % \end{function}
313 %
314 % \begin{function}{abovesep,belowsep,vsep}
315 % \begin{syntax}
316 % abovesep = <长度>
317 % belowsep = <长度>
318 % vsep = <长度>
319 % \end{syntax}
320 % 设置绕排内容与正文的上/下间距,选项 \opt{vsep} 同时设置 \opt{abovesep} 和 \opt{belowsep}。
321 % 初始值是 \qty{0}{pt}。
322 % \end{function}
323 %
324 % \begin{function}{hoffset}
325 % \begin{syntax}
326 % hoffset = <长度>
327 % \end{syntax}
328 % 设置绕排内容伸出正文版心的长度。
329 % 当设置了选项 \opt{c} 或者选项 \opt{ratio} 的值位于 $(0,1)$ 时,本选项无效。
330 % 一个特殊值 \tn{width} 用于表示绕排内容和相应间距的总宽度,
331 % 可以将 \opt{hoffset} 设置为 \tn{width},完全伸出版心。
332 % 初始值为 \qty{0}{pt}。
333 % \end{function}
334 %
335 % \begin{function}{voffset}
336 % \begin{syntax}
337 % voffset = <长度>
338 % \end{syntax}
339 % 用于调整绕排内容的竖直位置,初始值为 \qty{0}{pt}。
340 % \end{function}
341 %
342 % \begin{function}{type}
343 % \begin{syntax}
344 % type = <浮动体类型>
345 % \end{syntax}
346 % 设置绕排内容的浮动体类型,初始值为空。
347 % 如果需要在 \env{wrapstuff} 环境中使用 \tn{caption} 命令,
348 % 则需要设置 \opt{type} 为 \opt{figure} 或 \opt{table} 等类型,
349 % 并需要同时设置 \opt{width} 指定宽度。
350 % \begin{SideBySideExample}[xrightmargin=\dimeval{18em+5mm}]
351 % \begin{wrapstuff}[type=figure,width=5em]
352 % \centering
353 % \IMAGE{4em}{plain}
354 % \caption{示例}
355 % \end{wrapstuff}
356 % \QIANZIWEN
357 % \end{SideBySideExample}
358 % \end{function}
359 %
360 % \begin{function}{\wrapstuffclear}
361 % 如果当前正文段落的行数不够,\pkg{wrapstuff} 的作用会延续到下一段。
362 % 这可能会导致某些意外结果,可以在下一段之前启用命令 \tn{wrapstuffclear} 消除影响。
363 % \end{function}
364 %
365 % \end{documentation}
366 %
367 %
368 % \StopEventually{}
369 %
370 %
371 %\begin{implementation}
372 %
373 % \section{代码实现}
374 %
375 % \begin{macrocode}
376 %<*package>
377 % \end{macrocode}
378 %
379 % \begin{macrocode}
380 %<@@=wstf>
381 % \end{macrocode}
382 %
383 % \pkg{wrapstuff} 的实现依赖 \LaTeX\ 2021-06-01 开始提供的段落钩子。
384 % \begin{macrocode}
385 \@ifl@t@r \fmtversion { 2021-06-01 }
386 { }
387 {
388 \msg_new:nnn { wrapstuff } { latex-too-old }
389 {
390 You~need~to~update~your~LaTeX~to~the~latest~release. \\
391 Loading~wrapstuff~will~abort!
392 }
393 \msg_critical:nn { wrapstuff } { latex-too-old }
394 }
395 % \end{macrocode}
396 %
397 % 由于使用了 \cs{keys_precompile:nnN},需要比较新的 \LaTeXiii。
398 % \begin{macrocode}
399 \@ifl@t@r \ExplLoaderFileDate { 2022-04-10 }
400 { }
401 {
402 \msg_new:nnn { wrapstuff } { latex3-too-old }
403 {
404 You~need~to~update~your~installation~of~the~bundles~
405 "l3kernel"~and~"l3packages". \\
406 Loading~wrapstuff~will~abort!
407 }
408 \msg_critical:nn { wrapstuff } { latex3-too-old }
409 }
410 % \end{macrocode}
411 %
412 % \begin{macrocode}
413 \prop_gput:Nnn \g_msg_module_name_prop { wstf } { wrapstuff }
414 % \end{macrocode}
415 %
416 % \begin{macro}[var]{
417 % \c_@@_global_tl_tl,
418 % \c_@@_global_dim_tl,
419 % \c_@@_global_int_tl,
420 % \c_@@_global_bool_tl}
421 % 一些需要全局设置的变量。
422 % \begin{macrocode}
423 \tl_const:Nn \c_@@_global_tl_tl
424 { \g_@@_main_setting_tl }
425 \tl_const:Nn \c_@@_global_dim_tl
426 {
427 \g_@@_hang_ht_dim
428 \g_@@_total_ht_dim
429 \g_@@_stuff_ht_dim
430 \g_@@_stuff_wd_dim
431 \g_@@_first_dp_dim
432 \g_@@_first_sep_dim
433 \g_@@_prevdepth_dim
434 \g_@@_column_ht_dim
435 \g_@@_window_ht_dim
436 \g_@@_remaining_dim
437 \g_@@_column_room_dim
438 \g_@@_parshape_indent_dim
439 \g_@@_parshape_length_dim
440 }
441 \tl_const:Nn \c_@@_global_int_tl
442 {
443 \g_@@_top_int
444 \g_@@_column_int
445 \g_@@_window_int
446 }
447 \tl_const:Nn \c_@@_global_bool_tl
448 {
449 \g_@@_next_bool
450 \g_@@_leqno_bool
451 \g_@@_column_bool
452 \g_@@_entire_bool
453 \g_@@_display_bool
454 \g_@@_move_hang_bool
455 \g_@@_next_hang_bool
456 \g_@@_first_set_bool
457 \g_@@_first_save_bool
458 \g_@@_right_move_bool
459 }
460 % \end{macrocode}
461 % \end{macro}
462 %
463 % \begin{macro}{
464 % \@@_tl_init:N,
465 % \@@_dim_init:N,
466 % \@@_int_init:N,
467 % \@@_bool_init:N}
468 % 全局变量的初始化,注意保存好清除和恢复的设置。
469 % \begin{macrocode}
470 \cs_new_protected:Npn \@@_tl_init:N #1
471 {
472 \tl_new:N #1
473 \tl_gput_right:Nn \g_@@_var_clear_tl
474 { \tl_gclear:N #1 }
475 \tl_gput_right:Nn \g_@@_var_push_tl
476 { \tl_gset:Nn \exp_not:N #1 { \exp_not:o {#1} } }
477 }
478 \cs_new_protected:Npn \@@_dim_init:N #1
479 {
480 \dim_new:N #1
481 \tl_gput_right:Nn \g_@@_var_clear_tl
482 { \dim_gzero:N #1 }
483 \tl_gput_right:Nn \g_@@_var_push_tl
484 { \dim_gset:Nn #1 { \dim_use:N #1 } }
485 }
486 \cs_new_protected:Npn \@@_int_init:N #1
487 {
488 \int_new:N #1
489 \tl_gput_right:Nn \g_@@_var_clear_tl
490 { \int_gzero:N #1 }
491 \tl_gput_right:Nn \g_@@_var_push_tl
492 { \int_gset:Nn #1 { \int_use:N #1 } }
493 }
494 \cs_new_protected:Npn \@@_bool_init:N #1
495 {
496 \bool_new:N #1
497 \tl_gput_right:Nn \g_@@_var_clear_tl
498 { \bool_gset_false:N #1 }
499 \tl_gput_right:Nn \g_@@_var_push_tl
500 {
501 \bool_if:NTF #1
502 { \bool_gset_true:N #1 }
503 { \bool_gset_false:N #1 }
504 }
505 }
506 \tl_new:N \g_@@_var_clear_tl
507 \tl_new:N \g_@@_var_push_tl
508 \tl_map_function:NN \c_@@_global_tl_tl \@@_tl_init:N
509 \tl_map_function:NN \c_@@_global_dim_tl \@@_dim_init:N
510 \tl_map_function:NN \c_@@_global_int_tl \@@_int_init:N
511 \tl_map_function:NN \c_@@_global_bool_tl \@@_bool_init:N
512 % \end{macrocode}
513 % \cs{g_@@_top_int} 的初始值是 $-1$。
514 % \begin{macrocode}
515 \int_gdecr:N \g_@@_top_int
516 \tl_gput_right:Nn \g_@@_var_clear_tl
517 { \int_gdecr:N \g_@@_top_int }
518 % \end{macrocode}
519 % \end{macro}
520 %
521 % \begin{macro}{
522 % \@@_clear:,
523 % \@@_clear_variable:,
524 % \@@_clear_kludge:,
525 % \@@_clear_stuff_box:}
526 % \begin{macrocode}
527 \cs_new_protected_nopar:Npn \@@_clear:
528 {
529 \@@_clear_para_hook:
530 \@@_clear_kludge:
531 \@@_clear_variable:
532 }
533 \cs_new_protected_nopar:Npn \@@_clear_variable:
534 {
535 \tl_use:N \g_@@_var_clear_tl
536 \box_gclear:N \g_@@_stuff_box
537 }
538 \cs_new_protected_nopar:Npn \@@_clear_kludge:
539 {
540 \bool_if:NTF \g_@@_next_bool
541 {
542 \skip_vertical:n
543 { \tex_baselineskip:D * \g_@@_window_int }
544 }
545 {
546 \box_if_empty:NF \g_@@_stuff_box
547 { \@@_clear_stuff_box: }
548 }
549 }
550 \cs_new_protected_nopar:Npn \@@_clear_stuff_box:
551 {
552 \@@_ignore_depth:
553 \skip_set:Nn \l_@@_last_skip
554 { \box_dp:N \strutbox }
555 \skip_vertical:N \l_@@_last_skip
556 \box_use_drop:N \g_@@_stuff_box
557 \skip_vertical:N \l_@@_last_skip
558 \@@_ignore_depth:
559 }
560 % \end{macrocode}
561 % \end{macro}
562 %
563 % \begin{macro}{
564 % \@@_status_push:,
565 % \@@_status_pop:,
566 % \@@_status_restore:,
567 % \@@_status_clear:}
568 % 全局变量的保存与恢复。
569 % \begin{macrocode}
570 \cs_new_protected_nopar:Npn \@@_status_push:
571 {
572 \tl_clear:N \l_@@_status_tl
573 \int_gincr:N \g_@@_status_int
574 \exp_args:Ne \@@_status_push_aux:n
575 { \int_use:N \g_@@_status_int }
576 \seq_gpush:No \g_@@_status_seq { \l_@@_status_tl }
577 }
578 \cs_new_protected:Npn \@@_status_push_aux:n #1
579 {
580 \@@_push_cs:nN {#1} \@@_para_before:
581 \@@_push_cs:nN {#1} \@@_para_begin:
582 \@@_push_cs:nN {#1} \@@_para_end:
583 \@@_push_cs:nN {#1} \@@_display_hook:
584 \@@_push_box:N \g_@@_stuff_box
585 \@@_push_var:
586 }
587 \cs_new_protected:Npn \@@_push_cs:nN #1#2
588 {
589 \exp_args:NNc \@@_push_cs_aux:NN #2
590 { @@_ #1 _ \token_to_str:N #2 }
591 }
592 \cs_new_protected:Npn \@@_push_cs_aux:NN #1#2
593 {
594 \cs_gset_eq:NN #2#1
595 \tl_put_right:Nn \l_@@_status_tl
596 {
597 \cs_gset_eq:NN #1#2
598 \cs_undefine:N #2
599 }
600 }
601 \cs_new_protected:Npn \@@_push_box:N #1
602 {
603 \hbox_gset:Nn \g_@@_stauts_box
604 {
605 \hbox_unpack_drop:N \g_@@_stauts_box
606 \box_use:N #1
607 }
608 \tl_put_right:Nn \l_@@_status_tl
609 { \@@_pop_box:N #1 }
610 }
611 \cs_new_protected:Npn \@@_pop_box:N #1
612 {
613 \hbox_gset:Nw \g_@@_stauts_box
614 \hbox_unpack_drop:N \g_@@_stauts_box
615 \box_gset_to_last:N #1
616 \@@_if_last_hlist:TF
617 { \hbox_gset_end: }
618 {
619 \hbox_gset_end:
620 \box_gclear:N \g_@@_stauts_box
621 }
622 }
623 \cs_new_protected_nopar:Npn \@@_push_var:
624 {
625 \tl_put_right:Nx \l_@@_status_tl
626 { \g_@@_var_push_tl }
627 }
628 \cs_new_protected_nopar:Npn \@@_status_pop:
629 {
630 \seq_gpop:NNT \g_@@_status_seq \l_@@_status_tl
631 {
632 \int_gdecr:N \g_@@_status_int
633 \tl_use:N \l_@@_status_tl
634 }
635 }
636 \cs_new_protected_nopar:Npn \@@_status_restore:
637 {
638 \@@_status_push:
639 \@@_clear_para_hook:
640 \@@_clear_display_hook:
641 \@@_clear_variable:
642 \group_insert_after:N \@@_status_pop:
643 }
644 \cs_new_protected_nopar:Npn \@@_status_clear:
645 {
646 \bool_if:NT \g_@@_next_bool
647 {
648 \@@_clear_para_hook:
649 \@@_clear_variable:
650 }
651 }
652 \tl_new:N \l_@@_status_tl
653 \box_new:N \g_@@_stauts_box
654 \int_new:N \g_@@_status_int
655 \seq_new:N \g_@@_status_seq
656 % \end{macrocode}
657 % \end{macro}
658 %
659 % \changes{v0.2}{2022/07/21}{兼容 \tn{parbox} 与 \env{minipage} 等使用环境。}
660 %
661 % \begin{macro}{\wrapstuff@parboxrestore,\@arrayparboxrestore}
662 % 在 \LaTeX\ 的 \cs{parbox} 和 \env{minipage} 等环境中恢复正常的段落状态。
663 % \tn{wrapstuff@parboxrestore} 的初始值是在分组后清除活动的段落钩子和相关全局变量,
664 % 只有在 \env{wrapstuff@par} 环境内部才等于 \cs{@@_status_restore:},
665 % 保存和恢复相关状态。
666 % \begin{macrocode}
667 \cs_new_protected_nopar:Npn \wrapstuff@parboxrestore
668 { \group_insert_after:N \@@_status_clear: }
669 \cs_new_protected_nopar:Npn \@@_parbox_restore:
670 {
671 \cs_set_eq:NN
672 \wrapstuff@parboxrestore
673 \@@_status_restore:
674 }
675 \g@addto@macro \@arrayparboxrestore
676 { \wrapstuff@parboxrestore }
677 % \end{macrocode}
678 % \end{macro}
679 %
680 % \begin{macro}[TF]{
681 % \@@_if_last_none:,
682 % \@@_if_last_hlist:,
683 % \@@_if_last_whatsit:,
684 % \@@_if_last_glue:,
685 % \@@_if_last_kern:,
686 % \@@_if_last_penalty:}
687 % 一些 \hologo{eTeX} 结点判定函数。
688 % \begin{macrocode}
689 \group_begin:
690 \cs_set:Npn \@@_tmp:nn #1
691 {
692 \exp_args:Ncc \@@_tmp_aux:NNn
693 { @@_if_last_ #1 : }
694 { c_@@_ #1 _node }
695 }
696 \cs_set:Npn \@@_tmp_aux:NNn #1#2#3
697 {
698 \int_const:Nn #2 {#3}
699 \prg_new_conditional:Npnn #1 { T , F , TF }
700 {
701 \if_int_compare:w \tex_lastnodetype:D = #2
702 \prg_return_true: \else: \prg_return_false: \fi:
703 }
704 }
705 \@@_tmp:nn { none } { -1 }
706 \@@_tmp:nn { hlist } { 1 }
707 \@@_tmp:nn { whatsit } { 9 }
708 \@@_tmp:nn { glue } { 11 }
709 \@@_tmp:nn { kern } { 12 }
710 \@@_tmp:nn { penalty } { 13 }
711 \group_end:
712 % \end{macrocode}
713 % \end{macro}
714 %
715 % \begin{macro}{\@@_gadd_hook:nn, \@@_package_hook:nn}
716 % \begin{macrocode}
717 \cs_new_protected:Npn \@@_gadd_hook:nn #1
718 { \hook_gput_code:nnn {#1} { wrapstuff } }
719 \cs_new_protected:Npn \@@_package_hook:nn #1
720 { \hook_gput_code:nnn { package/#1/after } { wrapstuff } }
721 % \end{macrocode}
722 % \end{macro}
723 %
724 % \begin{macro}{\@@_para_raw_end:}
725 % 将 \cs{para_raw_end:} 放在分组中是为了保持 \tn{parshape}。
726 % \begin{macrocode}
727 \cs_new_protected_nopar:Npn \@@_para_raw_end:
728 { \group_begin: \para_raw_end: \group_end: }
729 % \end{macrocode}
730 % \end{macro}
731 %
732 % \begin{macro}{\@@_gadd_ht:Nn}
733 % \begin{macrocode}
734 \cs_new_protected:Npn \@@_gadd_ht:Nn #1#2
735 { \box_gset_ht:Nn #1 { \box_ht:N #1 + \dim_eval:n {#2} } }
736 % \end{macrocode}
737 % \end{macro}
738 %
739 % \begin{macro}{wrapstuff}
740 % 主要功能环境接口。
741 % \begin{macrocode}
742 \NewDocumentEnvironment { wrapstuff } { O { } }
743 {
744 \@@_clear:
745 \int_set:Nn \l_@@_top_int { -1 }
746 \tl_if_blank:nTF {#1}
747 { \tl_clear:N \l_@@_main_kv_tl }
748 {
749 \keys_set_filter:nnnN { wrapstuff }
750 { main , ratio }
751 {#1} \l_@@_main_kv_tl
752 }
753 \tl_set:Nx \l_@@_type_tl { \l_@@_type_tl }
754 \dim_set:Nn \l_@@_width_dim { \l_@@_width_tl }
755 \dim_set:Nn \l_@@_height_dim { \l_@@_height_tl }
756 \hbox_gset:Nw \g_@@_stuff_box
757 \dim_compare:nNnTF \l_@@_width_dim > \c_zero_dim
758 { \@@_minipage_begin: }
759 { \@@_hbox_begin: }
760 }
761 {
762 \dim_compare:nNnTF \l_@@_width_dim > \c_zero_dim
763 { \@@_minipage_end: }
764 { \@@_hbox_end: }
765 \@@_set_vsep:
766 \@@_attach_label:
767 \tl_if_empty:NTF \l_@@_main_kv_tl
768 { \tl_gclear:N \g_@@_main_setting_tl }
769 { \@@_save_main_setting: }
770 \@@_set_top_line:
771 \dim_gset:Nn \g_@@_stuff_wd_dim
772 { \box_wd:N \g_@@_stuff_box }
773 \dim_gset:Nn \g_@@_stuff_ht_dim
774 { \box_ht_plus_dp:N \g_@@_stuff_box }
775 \dim_gset_eq:NN
776 \g_@@_remaining_dim
777 \g_@@_stuff_ht_dim
778 \@@_next_para:
779 }
780 \@@_gadd_hook:nn { env/wrapstuff/before } { \par }
781 \cs_new_protected_nopar:Npn \@@_minipage_begin:
782 {
783 \@@_floatrow_hook:
784 \dim_compare:nNnTF \l_@@_height_dim > \c_zero_dim
785 { \begin { minipage } [b] [ \l_@@_height_dim ] [c] { \l_@@_width_dim } }
786 { \begin { minipage } [b] { \l_@@_width_dim } }
787 \tl_if_empty:NF \l_@@_type_tl
788 { \@@_set_float: }
789 }
790 \cs_new_protected_nopar:Npn \@@_minipage_end:
791 {
792 \end { minipage }
793 \hbox_gset_end:
794 \@@_float_pos_hook:
795 }
796 \cs_new_protected_nopar:Npn \@@_hbox_begin:
797 { \tex_ignorespaces:D }
798 \cs_new_protected_nopar:Npn \@@_hbox_end:
799 {
800 \tex_unskip:D
801 \hbox_gset_end:
802 \dim_compare:nNnT \l_@@_height_dim > \c_zero_dim
803 { \@@_gset_height: }
804 }
805 \cs_new_protected_nopar:Npn \@@_gset_height:
806 {
807 \hbox_gset:Nn \g_@@_stuff_box
808 {
809 \box_move_up:nn
810 {
811 ( \l_@@_height_dim
812 - \box_ht:N \g_@@_stuff_box
813 + \box_dp:N \g_@@_stuff_box
814 ) / 2
815 }
816 { \box_use_drop:N \g_@@_stuff_box }
817 }
818 \box_gset_ht:Nn \g_@@_stuff_box { \l_@@_height_dim }
819 \box_gset_dp:Nn \g_@@_stuff_box { \c_zero_dim }
820 }
821 \cs_new_protected_nopar:Npn \@@_set_vsep:
822 {
823 \@@_gadd_ht:Nn \g_@@_stuff_box { \l_@@_abovesep_tl }
824 \dim_set:Nn \l_@@_shift_dim { \l_@@_belowsep_tl }
825 \dim_compare:nNnF \l_@@_shift_dim = \c_zero_dim
826 { \@@_set_belowsep: }
827 }
828 \cs_new_protected_nopar:Npn \@@_set_belowsep:
829 {
830 \hbox_gset:Nn \g_@@_stuff_box
831 {
832 \box_move_up:nn
833 { \l_@@_shift_dim + \box_dp:N \g_@@_stuff_box }
834 { \box_use_drop:N \g_@@_stuff_box }
835 }
836 \box_gset_dp:Nn \g_@@_stuff_box { \c_zero_dim }
837 }
838 \tl_new:N \l_@@_main_kv_tl
839 \box_new:N \g_@@_stuff_box
840 \dim_new:N \l_@@_shift_dim
841 \dim_new:N \l_@@_width_dim
842 \dim_new:N \l_@@_height_dim
843 % \end{macrocode}
844 % \end{macro}
845 %
846 % \changes{v0.2}{2022/07/26}{优化重新编译警告。}
847 %
848 % \begin{macro}{\@@_attach_label:, \@@_write_label:,\@@_rerun_check:}
849 % \begin{macrocode}
850 \cs_new_protected_nopar:Npn \@@_attach_label:
851 {
852 \stepcounter { wrapstuff }
853 \hbox_gset:Nn \g_@@_stuff_box
854 {
855 \@@_write_label:
856 \box_use_drop:N \g_@@_stuff_box
857 }
858 }
859 \cs_new_protected_nopar:Npn \@@_write_label:
860 {
861 \exp_args:Nee \@@_write_label_aux:nn
862 { \@@_counter:n { wrapstuff } }
863 { \@@_counter:n { page } }
864 }
865 \cs_new_protected:Npx \@@_write_label_aux:nn #1#2
866 {
867 \prop_gput_if_new:Nnn \exp_not:N \g_@@_page_prop {#1} {#2}
868 \iow_shipout_x:Nn \exp_not:N \@auxout
869 {
870 \c_backslash_str wrapstuff@label
871 {#1}
872 { \exp_not:N \wrapstuff@counter { page } }
873 }
874 }
875 \newcounter { wrapstuff }
876 \cs_new:Npn \@@_counter:n #1
877 { \int_value:w \value {#1} }
878 \cs_new_eq:NN \wrapstuff@counter \@@_counter:n
879 \cs_new_protected_nopar:Npn \wrapstuff@label
880 { \prop_gput:Nnn \g_@@_page_prop }
881 \@@_gadd_hook:nn { begindocument }
882 {
883 \legacy_if:nTF { @filesw }
884 {
885 \iow_now:Nx \@mainaux
886 {
887 \c_backslash_str providecommand
888 \c_backslash_str wrapstuff@label [2] { }
889 }
890 }
891 { \cs_gset_eq:NN \@@_write_label: \@@_empty: }
892 }
893 \@@_gadd_hook:nn { enddocument/afterlastpage }
894 {
895 \legacy_if:nT { @filesw }
896 { \prop_gclear:N \g_@@_page_prop }
897 }
898 \@@_gadd_hook:nn { enddocument/info }
899 {
900 \prop_if_empty:NF \g_@@_rerun_prop
901 { \@@_rerun_check: }
902 }
903 \cs_new_protected_nopar:Npn \@@_rerun_check:
904 {
905 \prop_map_inline:Nn \g_@@_rerun_prop
906 {
907 \prop_get:NnN \g_@@_page_prop { ##1 } \l_@@_page_tl
908 \int_if_even:nF { \l_@@_page_tl - ##2 }
909 { \prop_map_break:n { \@@_rerun_warning: } }
910 }
911 }
912 \cs_new_protected_nopar:Npn \@@_rerun_warning:
913 { \msg_warning:nn { wstf } { rerun-required } }
914 \msg_new:nnn { wstf } { rerun-required }
915 {
916 Page(s)~may~have~changed.\\
917 Rerun~to~get~i/o~setting~right.
918 }
919 \tl_new:N \l_@@_page_tl
920 \prop_new:N \g_@@_page_prop
921 \prop_new:N \g_@@_rerun_prop
922 % \end{macrocode}
923 % \end{macro}
924 %
925 % \begin{macro}{\@@_save_main_setting:}
926 % \begin{macrocode}
927 \cs_new_protected_nopar:Npn \@@_save_main_setting:
928 {
929 \exp_args:Nnno
930 \keys_set_filter:nnnN { wrapstuff }
931 { main }
932 { \l_@@_main_kv_tl } \l_@@_main_kv_tl
933 \bool_if:NTF \l_@@_swap_bool
934 { \@@_swap_ratio: }
935 { \@@_set_ratio:N \l_@@_ratio_fp }
936 \tl_if_empty:NF \l_@@_main_kv_tl
937 { \@@_save_main_setting_aux: }
938 }
939 \cs_new_protected:Npn \@@_set_ratio:N #1
940 {
941 \tl_gset:Nx \g_@@_main_setting_tl
942 { \fp_set:Nn \exp_not:N \l_@@_ratio_fp { \fp_use:N #1 } }
943 }
944 \cs_new_protected:Npn \@@_set_ratio:n #1
945 {
946 \tl_gset:Nx \g_@@_main_setting_tl
947 { \fp_set:Nn \exp_not:N \l_@@_ratio_fp { \fp_eval:n {#1} } }
948 }
949 \cs_new_protected_nopar:Npn \@@_save_main_setting_aux:
950 {
951 \exp_args:Nno
952 \keys_precompile:nnN
953 { wrapstuff }
954 { \l_@@_main_kv_tl } \l_@@_main_kv_tl
955 \tl_gconcat:NNN
956 \g_@@_main_setting_tl
957 \g_@@_main_setting_tl
958 \l_@@_main_kv_tl
959 }
960 % \end{macrocode}
961 % \end{macro}
962 %
963 % \begin{macro}{\@@_set_top_line:}
964 % \begin{macrocode}
965 \cs_new_protected_nopar:Npn \@@_set_top_line:
966 {
967 \int_compare:nNnF \l_@@_top_int < \c_zero_int
968 {
969 \tl_gput_right:Nx \g_@@_main_setting_tl
970 {
971 \int_set:Nn \l_@@_top_int
972 { \int_use:N \l_@@_top_int }
973 }
974 }
975 }
976 % \end{macrocode}
977 % \end{macro}
978 %
979 % \begin{macro}{\@@_swap_ratio:}
980 % \begin{macrocode}
981 \cs_new_protected_nopar:Npn \@@_swap_ratio:
982 {
983 \exp_args:Ne \@@_swap_ratio_aux:n
984 { \@@_counter:n { wrapstuff } }
985 }
986 \cs_new_protected:Npn \@@_swap_ratio_aux:n #1
987 {
988 \fp_compare:nF
989 { \c_zero_fp < \l_@@_ratio_fp < \c_one_fp }
990 { \fp_zero:N \l_@@_ratio_fp }
991 \prop_get:NnNF \g_@@_page_prop {#1} \l_@@_page_tl
992 { \tl_set:Nx \l_@@_page_tl { \@@_counter:n { page } } }
993 \int_if_odd:nTF { \l_@@_page_tl }
994 { \bool_if:NTF \l_@@_inner_bool }
995 { \bool_if:NTF \l_@@_outer_bool }
996 { \@@_set_ratio:N \l_@@_ratio_fp }
997 { \@@_set_ratio:n { \c_one_fp - \l_@@_ratio_fp } }
998 \prop_gput:Nno \g_@@_rerun_prop {#1} { \l_@@_page_tl }
999 }
1000 \bool_new:N \l_@@_swap_bool
1001 \bool_new:N \l_@@_inner_bool
1002 \bool_new:N \l_@@_outer_bool
1003 % \end{macrocode}
1004 % \end{macro}
1005 %
1006 % \begin{macro}{\@@_next_para:}
1007 % 将 \env{wrapstuff} 环境之后的段落放入内部环境 \env{wrapstuff@par} 中。
1008 % 为了控制钩子执行顺序,需要使用 |wrapstuff| 标签,
1009 % 而不用更为方便的 \cs{hook_gput_next_code:nn} 实现。
1010 % \begin{macrocode}
1011 \@@_gadd_hook:nn { para/before } { \@@_para_before: }
1012 \@@_gadd_hook:nn { para/after } { \@@_para_after: }
1013 \@@_gadd_hook:nn { para/begin } { \@@_para_begin: }
1014 \@@_gadd_hook:nn { para/end } { \@@_para_end: }
1015 \cs_new_protected_nopar:Npn \@@_next_para:
1016 {
1017 \cs_gset_eq:NN \@@_para_before: \@@_env_before:
1018 \cs_gset_eq:NN \@@_para_begin: \@@_env_begin:
1019 \cs_gset_eq:NN \@@_para_end: \@@_env_end:
1020 }
1021 \cs_new_protected_nopar:Npn \@@_env_before:
1022 { \dim_gset_eq:NN \g_@@_prevdepth_dim \tex_prevdepth:D }
1023 \cs_new_protected_nopar:Npn \@@_env_begin:
1024 { \begin { wrapstuff@par } }
1025 \cs_new_protected_nopar:Npn \@@_env_end:
1026 { \end { wrapstuff@par } }
1027 \cs_new_protected_nopar:Npn \@@_clear_para_hook:
1028 {
1029 \cs_gset_eq:NN \@@_para_before: \@@_empty:
1030 \cs_gset_eq:NN \@@_para_after: \@@_empty:
1031 \cs_gset_eq:NN \@@_para_begin: \@@_empty:
1032 \cs_gset_eq:NN \@@_para_end: \@@_empty:
1033 }
1034 \cs_new_protected_nopar:Npn \@@_empty:
1035 { }
1036 \cs_new_eq:NN \@@_para_before: \@@_empty:
1037 \cs_new_eq:NN \@@_para_after: \@@_empty:
1038 \cs_new_eq:NN \@@_para_begin: \@@_empty:
1039 \cs_new_eq:NN \@@_para_end: \@@_empty:
1040 % \end{macrocode}
1041 % \end{macro}
1042 %
1043 % \begin{macro}[int]{wrapstuff@par}
1044 % 内部环境,实现主要功能。
1045 % \begin{macrocode}
1046 \NewDocumentEnvironment { wrapstuff@par } { }
1047 {
1048 \tl_use:N \g_@@_main_setting_tl
1049 \dim_set:Nn \l_@@_leftsep_dim { \l_@@_leftsep_tl }
1050 \dim_set:Nn \l_@@_rightsep_dim { \l_@@_rightsep_tl }
1051 \dim_set:Nn \l_@@_voffset_dim { \l_@@_voffset_tl }
1052 \dim_set:Nn \l_@@_line_dim { \l_@@_linewidth_tl }
1053 \dim_set:Nn \l_@@_min_dim { \box_dp:N \strutbox }
1054 \dim_set_eq:NN \l_@@_main_width_dim \l_@@_line_dim
1055 \dim_sub:Nn \l_@@_line_dim
1056 { \tex_leftskip:D + \tex_rightskip:D }
1057 \dim_set:Nn \l_@@_window_dim
1058 { \l_@@_line_dim - \g_@@_stuff_wd_dim }
1059 \fp_compare:nNnTF \l_@@_ratio_fp > \c_zero_fp
1060 {
1061 \fp_compare:nNnTF \l_@@_ratio_fp < \c_one_fp
1062 { \@@_set_window: }
1063 { \@@_set_hang_right: }
1064 }
1065 { \@@_set_hang_left: }
1066 \int_compare:nNnTF \g_@@_window_int > \c_zero_int
1067 {
1068 \int_set_eq:NN \l_@@_window_int \g_@@_window_int
1069 \int_zero:N \l_@@_top_int
1070 }
1071 { \@@_set_lines: }
1072 \bool_if:NTF \l_@@_hang_bool
1073 {
1074 \dim_set_eq:NN \l_@@_display_dim \l_@@_window_dim
1075 \int_set_eq:NN \l_@@_window_line_int \l_@@_window_int
1076 }
1077 {
1078 \dim_set_eq:NN \l_@@_display_dim \l_@@_l_dim
1079 \int_set:Nn \l_@@_window_int { \l_@@_window_int * 2 }
1080 \int_set:Nn \l_@@_window_line_int
1081 {
1082 \bool_if:NTF \g_@@_column_bool
1083 { \l_@@_window_int / 2 + \g_@@_column_int }
1084 { \l_@@_window_int }
1085 }
1086 }
1087 \cs_gset_eq:NN \@@_para_before: \@@_empty:
1088 \cs_gset_eq:NN \@@_para_begin: \@@_empty:
1089 \@@_save_parshape:
1090 \@@_parbox_restore:
1091 \vbox_set:Nw \l_@@_body_box
1092 \@@_set_prevdepth:N \g_@@_prevdepth_dim
1093 \@@_save_tex_skip:
1094 \@@_tex_parameter:
1095 \@@_restore_parshape:
1096 \@@_display_parameter:
1097 \@@_make_main_parshape:
1098 \para_raw_noindent:
1099 }
1100 {
1101 \@@_save_hangfrom:
1102 \@@_save_tex_skip:
1103 \@@_group_kludge:
1104 \@@_tex_parameter:
1105 \@@_make_main_parshape:
1106 \para_raw_end:
1107 \int_gset_eq:NN \g_@@_line_int \tex_prevgraf:D
1108 \vbox_set_end:
1109 \@@_adjust_tex_skip:
1110 \cs_gset_eq:NN \@@_para_end: \@@_empty:
1111 \cs_gset_eq:NN \@@_para_after: \@@_empty:
1112 \int_compare:nNnTF \g_@@_line_int > \l_@@_top_int
1113 { \@@_build_par: }
1114 { \@@_put_par: }
1115 }
1116 \box_new:N \l_@@_body_box
1117 \box_new:N \l_@@_window_box
1118 \int_new:N \l_@@_window_int
1119 \int_new:N \g_@@_line_int
1120 \int_new:N \l_@@_window_line_int
1121 \dim_new:N \l_@@_l_dim
1122 \dim_new:N \l_@@_r_dim
1123 \dim_new:N \l_@@_min_dim
1124 \dim_new:N \l_@@_line_dim
1125 \dim_new:N \l_@@_window_dim
1126 \dim_new:N \l_@@_display_dim
1127 \dim_new:N \l_@@_voffset_dim
1128 \dim_new:N \l_@@_leftsep_dim
1129 \dim_new:N \l_@@_rightsep_dim
1130 \dim_new:N \l_@@_main_width_dim
1131 \bool_new:N \l_@@_hang_bool
1132 % \end{macrocode}
1133 % \end{macro}
1134 %
1135 % \begin{macro}{\@@_set_hang_left:, \@@_set_hang_right:, \@@_set_window:,}
1136 % \begin{macrocode}
1137 \cs_new_protected_nopar:Npn \@@_set_hang_left:
1138 {
1139 \bool_set_true:N \l_@@_hang_bool
1140 \@@_set_hoffset:N \l_@@_rightsep_dim
1141 \dim_zero:N \l_@@_l_dim
1142 \dim_set_eq:NN \l_@@_r_dim \l_@@_window_dim
1143 \cs_set_eq:NN \@@_build_box: \@@_build_hang:
1144 }
1145 \cs_new_protected_nopar:Npn \@@_set_hang_right:
1146 {
1147 \bool_set_true:N \l_@@_hang_bool
1148 \@@_set_hoffset:N \l_@@_leftsep_dim
1149 \dim_zero:N \l_@@_r_dim
1150 \dim_set_eq:NN \l_@@_l_dim \l_@@_window_dim
1151 \cs_set_eq:NN \@@_build_box: \@@_build_hang:
1152 }
1153 \cs_new_protected_nopar:Npn \@@_set_window:
1154 {
1155 \bool_set_false:N \l_@@_hang_bool
1156 \dim_sub:Nn \l_@@_window_dim
1157 { \l_@@_leftsep_dim + \l_@@_rightsep_dim }
1158 \dim_set:Nn \l_@@_l_dim
1159 { \@@_ratio:Nn \l_@@_ratio_fp { \l_@@_window_dim } }
1160 \dim_set:Nn \l_@@_r_dim
1161 { \l_@@_window_dim - \l_@@_l_dim }
1162 \bool_if:NTF \l_@@_column_bool
1163 { \cs_set_eq:NN \@@_build_box: \@@_build_column: }
1164 { \cs_set_eq:NN \@@_build_box: \@@_build_block: }
1165 }
1166 % \end{macrocode}
1167 % \end{macro}
1168 %
1169 % \changes{v0.2}{2022/07/24}{修复 \opt{hoffset} 选项。}
1170 %
1171 % \begin{macro}{\@@_set_hoffset:N}
1172 % \begin{macrocode}
1173 \cs_new_protected:Npn \@@_set_hoffset:N #1
1174 {
1175 \dim_sub:Nn \l_@@_window_dim {#1}
1176 \group_begin:
1177 \dim_set:Nn \l_@@_width_dim { #1 + \g_@@_stuff_wd_dim }
1178 \cs_set_eq:NN \width \l_@@_width_dim
1179 \exp_args:NNNx \group_end:
1180 \dim_add:Nn \l_@@_window_dim
1181 { \dim_eval:n { \l_@@_hoffset_tl } }
1182 }
1183 % \end{macrocode}
1184 % \end{macro}
1185 %
1186 % \begin{macro}{\@@_set_lines:, \@@_window_init:}
1187 % \begin{macrocode}
1188 \cs_new_protected_nopar:Npn \@@_set_lines:
1189 {
1190 \bool_if:NTF \g_@@_next_bool
1191 { \tl_clear:N \l_@@_lines_tl }
1192 { \tl_set:Nx \l_@@_lines_tl { \l_@@_lines_tl } }
1193 \int_set:Nn \l_@@_window_int
1194 {
1195 \tl_if_empty:NTF \l_@@_lines_tl
1196 { \@@_unit:n { \g_@@_remaining_dim + \l_@@_min_dim } }
1197 { \l_@@_lines_tl }
1198 }
1199 \bool_if:NF \g_@@_next_bool
1200 { \@@_window_init: }
1201 \int_compare:nNnTF \g_@@_top_int < \c_zero_int
1202 {
1203 \int_compare:nNnT \l_@@_top_int < \c_zero_int
1204 { \int_zero:N \l_@@_top_int }
1205 }
1206 { \int_set_eq:NN \l_@@_top_int \g_@@_top_int }
1207 }
1208 \cs_new_protected_nopar:Npn \@@_window_init:
1209 {
1210 \int_gset_eq:NN \g_@@_column_int \l_@@_window_int
1211 \dim_gset:Nn \g_@@_window_ht_dim
1212 { \tex_baselineskip:D * \g_@@_column_int }
1213 \tl_if_empty:NF \l_@@_lines_tl
1214 {
1215 \dim_gset:Nn \g_@@_remaining_dim
1216 { \g_@@_window_ht_dim - \box_ht:N \strutbox }
1217 \dim_gset_eq:NN \g_@@_stuff_ht_dim \g_@@_remaining_dim
1218 }
1219 }
1220 % \end{macrocode}
1221 % \end{macro}
1222 %
1223 % \begin{macro}{\@@_make_main_parshape:}
1224 % 主要处理用于标题悬挂的 \tn{@hangfrom} 和用于列表环境的 \tn{parshape}。
1225 % \begin{macrocode}
1226 \cs_new_protected_nopar:Npn \@@_make_main_parshape:
1227 {
1228 \dim_compare:nNnTF \g_@@_hangindent_dim > \c_zero_dim
1229 {
1230 \int_compare:nNnTF \g_@@_hangafter_int = \c_one_int
1231 { \@@_make_hangfrom: }
1232 { \@@_make_main_parshape_aux: }
1233 }
1234 { \@@_make_main_parshape_aux: }
1235 }
1236 \cs_new_protected_nopar:Npn \@@_make_main_parshape_aux:
1237 {
1238 \bool_gset_false:N \g_@@_hangfrom_bool
1239 \tex_parshape:D
1240 \int_eval:n { \l_@@_top_int + 1 } ~
1241 \prg_replicate:nn
1242 { \l_@@_top_int }
1243 { \g_@@_parshape_indent_dim \g_@@_parshape_length_dim }
1244 \c_zero_dim \c_max_dim
1245 }
1246 \cs_new_protected_nopar:Npn \@@_save_parshape:
1247 {
1248 \int_gset_eq:NN \g_@@_parshape_int \tex_parshape:D
1249 \int_compare:nNnTF \g_@@_parshape_int = \c_one_int
1250 {
1251 \dim_gset:Nn \g_@@_parshape_indent_dim
1252 { \tex_parshapeindent:D \c_one_int }
1253 \dim_gset:Nn \g_@@_parshape_length_dim
1254 { \tex_parshapelength:D \c_one_int }
1255 }
1256 {
1257 \int_gzero:N \g_@@_parshape_int
1258 \dim_gzero:N \g_@@_parshape_indent_dim
1259 \dim_gset_eq:NN \g_@@_parshape_length_dim \l_@@_main_width_dim
1260 \int_gset_eq:NN \g_@@_hangafter_int \tex_hangafter:D
1261 \dim_gset_eq:NN \g_@@_hangindent_dim \tex_hangindent:D
1262 }
1263 }
1264 \cs_new_protected_nopar:Npn \@@_restore_parshape:
1265 {
1266 \int_compare:nNnTF \g_@@_parshape_int = \c_one_int
1267 {
1268 \tex_parshape:D \g_@@_parshape_int
1269 \g_@@_parshape_indent_dim
1270 \g_@@_parshape_length_dim
1271 }
1272 { \@@_restore_hangfrom: }
1273 }
1274 \cs_new_protected_nopar:Npn \@@_parshape_kern:
1275 {
1276 \dim_compare:nNnT \l_@@_l_dim = \c_zero_dim
1277 {
1278 \dim_compare:nNnF \g_@@_parshape_indent_dim = \c_zero_dim
1279 { \tex_kern:D - \g_@@_parshape_indent_dim }
1280 }
1281 }
1282 \cs_new_protected_nopar:Npn \@@_make_hangfrom:
1283 {
1284 \bool_if:NTF \l_@@_hang_bool
1285 { \@@_make_hangfrom_aux: }
1286 { \@@_make_main_parshape_aux: }
1287 }
1288 \cs_new_protected_nopar:Npn \@@_make_hangfrom_aux:
1289 {
1290 \@@_restore_hangfrom:
1291 \int_zero:N \tex_parshape:D
1292 \bool_gset_true:N \g_@@_hangfrom_bool
1293 \dim_set_eq:NN \tex_hsize:D \l_@@_window_dim
1294 }
1295 \cs_new_protected_nopar:Npn \@@_save_hangfrom:
1296 {
1297 \int_gset_eq:NN \g_@@_hangafter_int \tex_hangafter:D
1298 \dim_gset_eq:NN \g_@@_hangindent_dim \tex_hangindent:D
1299 }
1300 \cs_new_protected_nopar:Npn \@@_restore_hangfrom:
1301 {
1302 \int_set_eq:NN \tex_hangafter:D \g_@@_hangafter_int
1303 \dim_set_eq:NN \tex_hangindent:D \g_@@_hangindent_dim
1304 }
1305 \bool_new:N \g_@@_hangfrom_bool
1306 \int_new:N \g_@@_parshape_int
1307 \int_new:N \g_@@_hangafter_int
1308 \dim_new:N \g_@@_hangindent_dim
1309 % \end{macrocode}
1310 % \end{macro}
1311 %
1312 % \begin{macro}{\@@_group_kludge:}
1313 % \LaTeX\ 的 \tn{list} 环境中,为了保持 \tn{parshape},\tn{par} 被重定义为 |{\@@par}|。
1314 % \begin{macrocode}
1315 \cs_new_protected_nopar:Npn \@@_group_kludge:
1316 {
1317 \scan_stop:
1318 \int_compare:nNnTF \tex_currentgrouptype:D = \c_one_int
1319 {
1320 \c_group_end_token
1321 \cs_gset_eq:NN \@@_group_begin: \c_group_begin_token
1322 }
1323 { \cs_gset_eq:NN \@@_group_begin: \@@_empty: }
1324 \legacy_if:nTF { @noitemarg }
1325 { \cs_gset_eq:NN \@@_set_itemarg: \@noitemargtrue }
1326 { \cs_gset_eq:NN \@@_set_itemarg: \@@_empty: }
1327 }
1328 \cs_new_eq:NN \@@_set_itemarg: \@@_empty:
1329 \cs_new_eq:NN \@@_group_begin: \@@_empty:
1330 \@@_gadd_hook:nn { env/wrapstuff@par/after }
1331 {
1332 \@@_set_itemarg:
1333 \@@_group_begin:
1334 }
1335 % \end{macrocode}
1336 % \end{macro}
1337 %
1338 % \begin{macro}{\@@_ratio:Nn, \@@_unit:n}
1339 % \begin{macrocode}
1340 \cs_new:Npn \@@_ratio:Nn #1#2
1341 { \fp_to_dim:n { #1 \dim_to_fp:n {#2} } }
1342 \cs_new:Npn \@@_unit:n #1
1343 {
1344 \int_eval:n
1345 {
1346 \exp_last_unbraced:Ne \@@_unit_aux:w
1347 { \dim_to_decimal_in_unit:nn {#1} { \tex_baselineskip:D } }
1348 \s_stop
1349 }
1350 }
1351 \cs_new:Npn \@@_unit_aux:w #1 . #2 \s_stop
1352 { #1 + 1 }
1353 % \end{macrocode}
1354 % \end{macro}
1355 %
1356 % \begin{macro}{\@@_save_tex_skip:,\@@_tex_parameter:}
1357 % \begin{macrocode}
1358 \cs_new_protected_nopar:Npn \@@_save_tex_skip:
1359 {
1360 \skip_gset_eq:NN \g_@@_left_skip \tex_leftskip:D
1361 \skip_gset_eq:NN \g_@@_right_skip \tex_rightskip:D
1362 \skip_gset_eq:NN \g_@@_parfill_skip \tex_parfillskip:D
1363 \skip_gset_eq:NN \g_@@_baseline_skip \tex_baselineskip:D
1364 \skip_gset:Nn \g_@@_main_left_skip { - \tex_leftskip:D }
1365 }
1366 \cs_new_protected_nopar:Npn \@@_adjust_tex_skip:
1367 {
1368 \@@_adjust_skip:N \g_@@_left_skip
1369 \@@_adjust_skip:N \g_@@_right_skip
1370 \@@_adjust_skip:N \g_@@_parfill_skip
1371 }
1372 \cs_new_protected:Npn \@@_adjust_skip:N #1
1373 { \skip_gsub:Nn #1 { \dim_eval:n {#1} } }
1374 \cs_new_protected_nopar:Npn \@@_tex_parameter:
1375 {
1376 \int_zero:N \tex_clubpenalty:D
1377 \int_zero:N \tex_widowpenalty:D
1378 \int_zero:N \tex_interlinepenalty:D
1379 \int_zero:N \tex_displaywidowpenalty:D
1380 \int_zero:N \tex_clubpenalties:D
1381 \int_zero:N \tex_widowpenalties:D
1382 \int_zero:N \tex_interlinepenalties:D
1383 \int_zero:N \tex_displaywidowpenalties:D
1384 \skip_set_eq:NN \tex_leftskip:D \g_@@_left_skip
1385 \skip_set_eq:NN \tex_rightskip:D \g_@@_right_skip
1386 \skip_set_eq:NN \tex_parfillskip:D \g_@@_parfill_skip
1387 \skip_set_eq:NN \tex_baselineskip:D \g_@@_baseline_skip
1388 }
1389 \skip_new:N \g_@@_left_skip
1390 \skip_new:N \g_@@_right_skip
1391 \skip_new:N \g_@@_parfill_skip
1392 \skip_new:N \g_@@_baseline_skip
1393 \skip_new:N \g_@@_main_left_skip
1394 % \end{macrocode}
1395 % \end{macro}
1396 %
1397 % \begin{macro}{\@@_display_parameter:}
1398 % \begin{macrocode}
1399 \cs_new_protected_nopar:Npn \@@_display_parameter:
1400 {
1401 \bool_gset_false:N \g_@@_display_bool
1402 \tex_everydisplay:D \exp_after:wN
1403 {
1404 \tex_the:D \tex_everydisplay:D
1405 \@@_display_hook:
1406 }
1407 }
1408 \cs_new_protected_nopar:Npn \@@_display_hook:
1409 {
1410 \@@_test_leqno:
1411 \dim_compare:nNnF \tex_displaywidth:D < \c_max_dim
1412 {
1413 \bool_gset_true:N \g_@@_display_bool
1414 \dim_set_eq:NN \tex_displaywidth:D \l_@@_display_dim
1415 }
1416 }
1417 \cs_new_eq:NN \@@_test_leqno: \@@_empty:
1418 \cs_new_protected_nopar:Npn \@@_clear_display_hook:
1419 { \cs_gset_eq:NN \@@_display_hook: \@@_empty: }
1420 % \end{macrocode}
1421 % \end{macro}
1422 %
1423 % \begin{macro}{\@@_split_parameter:}
1424 % \begin{macrocode}
1425 \cs_new_protected_nopar:Npn \@@_split_parameter:
1426 {
1427 \skip_zero:N \tex_splittopskip:D
1428 \dim_set_eq:NN \tex_vfuzz:D \c_max_dim
1429 \int_set_eq:NN \tex_vbadness:D \c_max_int
1430 }
1431 % \end{macrocode}
1432 % \end{macro}
1433 %
1434 % \begin{macro}{\@@_build_par:}
1435 % \begin{macrocode}
1436 \cs_new_protected_nopar:Npn \@@_build_par:
1437 {
1438 \bool_if:NTF \g_@@_hangfrom_bool
1439 { \@@_build_box: }
1440 { \@@_build_par_aux: }
1441 \box_if_empty:NTF \l_@@_window_box
1442 { \@@_put_next_par: }
1443 { \@@_put_box: }
1444 }
1445 \cs_new_protected_nopar:Npn \@@_build_par_aux:
1446 {
1447 \@@_extract_display_hbox:NN \l_@@_body_box \l_@@_bottom_box
1448 \int_compare:nNnT \l_@@_top_int > \c_zero_int
1449 { \@@_put_body_box: }
1450 \box_if_empty:NTF \l_@@_bottom_box
1451 {
1452 \box_if_empty:NF \g_@@_display_box
1453 { \@@_build_display_box: }
1454 }
1455 { \@@_build_body_box: }
1456 }
1457 \box_new:N \l_@@_bottom_box
1458 % \end{macrocode}
1459 % \end{macro}
1460 %
1461 % \begin{macro}{\@@_put_par:}
1462 % \begin{macrocode}
1463 \cs_new_protected_nopar:Npn \@@_put_par:
1464 {
1465 \int_gset:Nn \g_@@_top_int
1466 { \l_@@_top_int - \g_@@_line_int }
1467 \int_gzero:N \g_@@_window_int
1468 \@@_put_body_box:
1469 \skip_zero:N \tex_parskip:D
1470 \para_raw_noindent:
1471 \@@_next_para:
1472 }
1473 % \end{macrocode}
1474 % \end{macro}
1475 %
1476 % \begin{macro}{\@@_put_body_box:}
1477 % \begin{macrocode}
1478 \cs_new_protected_nopar:Npn \@@_put_body_box:
1479 {
1480 \@@_para_raw_end:
1481 \dim_compare:nNnTF { \box_wd:N \l_@@_body_box } < \c_max_dim
1482 { \@@_put_body_aux:N \l_@@_body_box }
1483 {
1484 \@@_extract_hbox:NN \l_@@_body_box \l_@@_bottom_box
1485 \@@_put_body_aux:N \l_@@_body_box
1486 \box_set_eq_drop:NN \l_@@_body_box \l_@@_bottom_box
1487 }
1488 \@@_para_raw_end:
1489 }
1490 \cs_new_protected_nopar:Npn \@@_put_body_aux:N #1
1491 {
1492 \dim_gset:Nn \g_@@_prevdepth_dim { \box_dp:N #1 }
1493 \dim_compare:nNnT \g_@@_prevdepth_dim = \c_zero_dim
1494 { \@@_extract_depth:N #1 }
1495 \vbox_unpack_drop:N #1
1496 \@@_set_prevdepth:N \g_@@_prevdepth_dim
1497 }
1498 \cs_new_protected_nopar:Npn \@@_extract_depth:N #1
1499 {
1500 \vbox_set:Nn \l_@@_last_box
1501 {
1502 \vbox_unpack:N #1
1503 \@@_if_last_hlist:F
1504 {
1505 \tex_unskip:D \tex_unpenalty:D
1506 \tex_unskip:D \tex_unpenalty:D
1507 }
1508 \@@_if_last_hlist:T
1509 {
1510 \box_set_to_last:N \l_@@_last_box
1511 \dim_gset:Nn \g_@@_prevdepth_dim
1512 { \box_dp:N \l_@@_last_box }
1513 }
1514 }
1515 }
1516 % \end{macrocode}
1517 % \end{macro}
1518 %
1519 % \begin{macro}{\@@_put_next_par:}
1520 % \begin{macrocode}
1521 \cs_new_protected_nopar:Npn \@@_put_next_par:
1522 {
1523 \int_gzero:N \g_@@_top_int
1524 \int_gzero:N \g_@@_window_int
1525 \skip_zero:N \tex_parskip:D
1526 \para_raw_noindent:
1527 \@@_next_para:
1528 }
1529 % \end{macrocode}
1530 % \end{macro}
1531 %
1532 % \begin{macro}{\@@_build_display_box:}
1533 % \begin{macrocode}
1534 \cs_new_protected_nopar:Npn \@@_build_display_box:
1535 {
1536 \bool_set_true:N \l_@@_display_bool
1537 \bool_if:NTF \g_@@_amsmath_bool
1538 { \@@_build_display_amsmath: }
1539 { \@@_build_display_normal: }
1540 \box_if_empty:NTF \l_@@_body_box
1541 { \@@_build_display_auxi: }
1542 { \@@_build_display_auxii: }
1543 }
1544 \cs_new_protected_nopar:Npn \@@_build_display_amsmath:
1545 {
1546 \group_begin:
1547 \vbox_gset:Nn \g_@@_equation_box
1548 {
1549 \@@_break:
1550 \vbox_unpack_drop:N \g_@@_display_box
1551 \skip_gset_eq:NN \g_@@_pos_skip \tex_lastskip:D
1552 \tex_unskip:D
1553 \int_gset_eq:NN \g_@@_pos_int \tex_lastpenalty:D
1554 \tex_unpenalty:D
1555 \skip_gadd:Nn \g_@@_pos_skip { \tex_lastskip:D }
1556 \tex_unskip:D
1557 \tex_unpenalty:D
1558 }
1559 \@@_split_parameter:
1560 \vbox_set_split_to_ht:NNn \l_@@_last_box \g_@@_equation_box
1561 { \c_zero_dim }
1562 \group_end:
1563 \box_gset_wd:Nn \g_@@_equation_box { \l_@@_display_dim }
1564 \vbox_gset:Nn \g_@@_display_box
1565 {
1566 \tex_penalty:D \g_@@_display_pre_int
1567 \skip_vertical:N \g_@@_display_pre_skip
1568 }
1569 \skip_gset_eq:NN \g_@@_pre_skip \g_@@_display_pre_skip
1570 }
1571 \cs_new_protected_nopar:Npn \@@_build_display_normal:
1572 {
1573 \vbox_gset:Nn \g_@@_display_box
1574 {
1575 \vbox_unpack_drop:N \g_@@_display_box
1576 \skip_gset_eq:NN \g_@@_pos_skip \tex_lastskip:D
1577 \tex_unskip:D
1578 \int_gset_eq:NN \g_@@_pos_int \tex_lastpenalty:D
1579 \tex_unpenalty:D
1580 \box_gset_to_last:N \g_@@_equation_box
1581 \skip_gset_eq:NN \g_@@_pre_skip \tex_lastskip:D
1582 \tex_unskip:D
1583 \skip_gadd:Nn \g_@@_pre_skip { \tex_lastskip:D }
1584 \tex_unskip:D
1585 \skip_vertical:N \g_@@_pre_skip
1586 }
1587 }
1588 \cs_new_protected_nopar:Npn \@@_build_display_auxi:
1589 {
1590 \bool_if:NTF \g_@@_amsmath_bool
1591 { \box_set_eq_drop:NN \l_@@_window_box \g_@@_equation_box }
1592 {
1593 \hbox_set_to_wd:Nnn \l_@@_window_box
1594 { \l_@@_display_dim }
1595 {
1596 \tex_hss:D
1597 \@@_adjust_equation:
1598 \box_use_drop:N \g_@@_equation_box
1599 \tex_hss:D
1600 }
1601 }
1602 \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_window_box }
1603 \dim_add:Nn \l_@@_voffset_dim
1604 { \box_ht:N \g_@@_display_box / 2 }
1605 }
1606 \cs_new_protected_nopar:Npn \@@_build_display_auxii:
1607 {
1608 \box_if_horizontal:NTF \l_@@_body_box
1609 {
1610 \box_set_eq:NN \l_@@_bottom_box \l_@@_body_box
1611 \@@_build_display_auxiii:
1612 }
1613 {
1614 \@@_extract_hbox:NN \l_@@_body_box \l_@@_bottom_box
1615 \str_if_eq:eeTF
1616 {
1617 \dim_eval:n { \box_ht:N \l_@@_body_box }
1618 \dim_eval:n { \box_dp:N \l_@@_body_box }
1619 \dim_eval:n { \box_ht:N \l_@@_bottom_box }
1620 \dim_eval:n { \box_dp:N \l_@@_bottom_box }
1621 }
1622 { \c_@@_zero_pt_str }
1623 {
1624 \vbox_unpack_drop:N \l_@@_body_box
1625 \box_clear:N \l_@@_bottom_box
1626 \@@_build_display_auxi:
1627 }
1628 { \@@_build_display_auxiii: }
1629 }
1630 }
1631 \str_const:Nx \c_@@_zero_pt_str
1632 {
1633 \dim_use:N \c_zero_dim
1634 \dim_use:N \c_zero_dim
1635 \dim_use:N \c_zero_dim
1636 \dim_use:N \c_zero_dim
1637 }
1638 \cs_new_protected_nopar:Npn \@@_build_display_auxiii:
1639 {
1640 \bool_set_true:N \l_@@_attach_equation_bool
1641 \box_gclear:N \g_@@_display_box
1642 \bool_if:NF \g_@@_amsmath_bool
1643 { \@@_adjust_equation: }
1644 \@@_build_body_box:
1645 }
1646 \bool_new:N \l_@@_display_bool
1647 \bool_new:N \l_@@_attach_equation_bool
1648 % \end{macrocode}
1649 % \end{macro}
1650 %
1651 % \changes{v0.2}{2022/07/23}{改进对显示数学公式的处理。}
1652 %
1653 % \begin{macro}{\@@_attach_left:N,\@@_attach_right:N}
1654 % \begin{macrocode}
1655 \cs_new_protected:Npn \@@_attach_left:N #1
1656 {
1657 \@@_attach_equation:Nn #1
1658 { \g_@@_parshape_indent_dim }
1659 }
1660 \cs_new_protected:Npn \@@_attach_right:N #1
1661 {
1662 \@@_attach_equation:Nn #1
1663 {
1664 \l_@@_line_dim
1665 - \l_@@_display_dim
1666 + \g_@@_parshape_indent_dim
1667 }
1668 }
1669 \cs_new_protected:Npn \@@_attach_equation:Nn #1#2
1670 {
1671 \vbox_set:Nn \l_@@_last_box
1672 {
1673 \vbox_unpack:N #1
1674 \box_set_to_last:N \l_@@_last_box
1675 \bool_if:NTF \g_@@_amsmath_bool
1676 { \@@_attach_equation_amsmath:Nn }
1677 { \@@_attach_equation_normal:Nn }
1678 \l_@@_last_box {#2}
1679 }
1680 }
1681 \cs_new_protected:Npn \@@_attach_equation_amsmath:Nn #1#2
1682 {
1683 \vbox_gset:Nn \g_@@_equation_box
1684 {
1685 \@@_nobreak:
1686 \skip_vertical:n
1687 {
1688 \g_@@_display_pre_skip
1689 + \g_@@_display_pre_dim
1690 - \box_dp:N #1
1691 }
1692 \box_move_right:nn {#2}
1693 { \box_use_drop:N \g_@@_equation_box }
1694 }
1695 }
1696 \cs_new_protected:Npn \@@_attach_equation_normal:Nn #1#2
1697 {
1698 \vbox_set:Nn \l_@@_last_box
1699 {
1700 \@@_tex_parameter:
1701 \dim_set_eq:NN \tex_hsize:D \l_@@_display_dim
1702 \para_raw_noindent:
1703 \hbox_unpack_drop:N #1 \tex_unskip:D
1704 \@@_insert_equation:
1705 \para_raw_end:
1706 \skip_gset_eq:NN \g_@@_pos_skip \tex_lastskip:D
1707 \tex_unskip:D
1708 \int_gset_eq:NN \g_@@_pos_int \tex_lastpenalty:D
1709 \tex_unpenalty:D
1710 \box_set_to_last:N \l_@@_last_box
1711 \skip_set_eq:NN \l_@@_last_skip \tex_lastskip:D
1712 \tex_unskip:D
1713 \skip_add:Nn \l_@@_last_skip { \tex_lastskip:D }
1714 \vbox_gset:Nn \g_@@_equation_box
1715 {
1716 \@@_nobreak:
1717 \skip_vertical:N \l_@@_last_skip
1718 \box_move_right:nn {#2}
1719 {
1720 \hbox_to_wd:nn
1721 { \l_@@_display_dim }
1722 {
1723 \tex_hss:D
1724 \box_use_drop:N \l_@@_last_box
1725 \tex_hss:D
1726 }
1727 }
1728 }
1729 }
1730 }
1731 \cs_new_protected_nopar:Npn \@@_insert_equation:
1732 {
1733 \c_math_toggle_token \c_math_toggle_token
1734 \dim_compare:nNnTF \tex_displaywidth:D = \l_@@_display_dim
1735 { \box_use_drop:N \g_@@_equation_box }
1736 {
1737 \bool_if:NTF \g_@@_eqnum_bool
1738 { \@@_repack_equation: }
1739 { \box_use_drop:N \g_@@_equation_box }
1740 }
1741 \c_math_toggle_token \c_math_toggle_token
1742 }
1743 \cs_new_protected_nopar:Npn \@@_repack_equation:
1744 {
1745 \box_gclear:N \g_@@_equation_box
1746 \box_use_drop:N \g_@@_eqbody_box
1747 \bool_if:NTF \g_@@_leqno_bool
1748 { \tex_leqno:D }
1749 { \tex_eqno:D }
1750 \box_use_drop:N \g_@@_eqnum_box
1751 }
1752 \cs_new_protected_nopar:Npn \@@_adjust_equation:
1753 {
1754 \@@_test_eqnum:
1755 \bool_if:NT \g_@@_eqnum_bool
1756 { \@@_adjust_equation_width: }
1757 }
1758 \cs_new_protected_nopar:Npn \@@_test_eqnum:
1759 {
1760 \hbox_set:Nn \l_@@_last_box
1761 {
1762 \bool_gset_false:N \g_@@_eqnum_bool
1763 \hbox_unpack:N \g_@@_equation_box
1764 \@@_if_last_hlist:F { \use_none_delimit_by_s_stop:w }
1765 \box_gset_to_last:N \g_@@_eqnum_box
1766 \@@_if_last_kern:F { \use_none_delimit_by_s_stop:w }
1767 \tex_unkern:D
1768 \@@_if_last_hlist:F { \use_none_delimit_by_s_stop:w }
1769 \box_gset_to_last:N \g_@@_eqbody_box
1770 \@@_if_last_none:F { \use_none_delimit_by_s_stop:w }
1771 \bool_gset_true:N \g_@@_eqnum_bool
1772 \use_none_delimit_by_s_stop:w \s_stop
1773 }
1774 }
1775 \cs_new_protected_nopar:Npn \@@_adjust_equation_width:
1776 {
1777 \bool_if:NTF \g_@@_leqno_bool
1778 { \@@_adjust_leqno: }
1779 {
1780 \box_gset_wd:Nn \g_@@_equation_box
1781 { \box_wd:N \g_@@_eqbody_box }
1782 }
1783 }
1784 \cs_new_protected_nopar:Npn \@@_adjust_leqno:
1785 {
1786 \box_set_eq_drop:NN \l_@@_last_box \g_@@_eqnum_box
1787 \box_gset_eq_drop:NN \g_@@_eqnum_box \g_@@_eqbody_box
1788 \box_gset_eq_drop:NN \g_@@_eqbody_box \l_@@_last_box
1789 \hbox_gset:Nn \g_@@_equation_box
1790 {
1791 \skip_horizontal:n
1792 {
1793 \box_wd:N \g_@@_eqbody_box
1794 - \box_wd:N \g_@@_equation_box
1795 }
1796 \box_use_drop:N \g_@@_equation_box
1797 }
1798 }
1799 \box_new:N \g_@@_eqbody_box
1800 \box_new:N \g_@@_eqnum_box
1801 \box_new:N \g_@@_equation_box
1802 \int_new:N \g_@@_pos_int
1803 \skip_new:N \g_@@_pos_skip
1804 \bool_new:N \g_@@_eqnum_bool
1805 % \end{macrocode}
1806 % \end{macro}
1807 %
1808 % \begin{macro}{\@@_add_pos_kludge:}
1809 % \begin{macrocode}
1810 \cs_new_protected_nopar:Npn \@@_add_pos_kludge:
1811 {
1812 \dim_gset:Nn \g_@@_prevdepth_dim
1813 { \box_dp:N \l_@@_window_box }
1814 \bool_gset_false:N \g_@@_equation_dp_bool
1815 \bool_if:NTF \g_@@_next_bool
1816 {
1817 \tex_vadjust:D
1818 {
1819 \box_if_empty:NF \g_@@_equation_box
1820 { \@@_output_equation_box: }
1821 \@@_nobreak:
1822 \bool_if:NT \l_@@_display_bool
1823 { \skip_vertical:N \g_@@_pos_skip }
1824 }
1825 }
1826 {
1827 \bool_if:NT \l_@@_display_bool
1828 {
1829 \tex_vadjust:D
1830 {
1831 \box_if_empty:NF \g_@@_equation_box
1832 { \@@_output_equation_box: }
1833 \tex_penalty:D \g_@@_pos_int
1834 \skip_vertical:N \g_@@_pos_skip
1835 }
1836 }
1837 }
1838 \int_gzero:N \g_@@_pos_int
1839 \skip_gzero:N \g_@@_pos_skip
1840 }
1841 \cs_new_protected_nopar:Npn \@@_output_equation_box:
1842 {
1843 \cs_gset_eq:NN
1844 \@@_para_after:
1845 \@@_set_equation_depth:
1846 \bool_gset_true:N \g_@@_equation_dp_bool
1847 \dim_gset:Nn \g_@@_prevdepth_dim
1848 { \box_dp:N \g_@@_equation_box }
1849 \vbox_unpack_drop:N \g_@@_equation_box
1850 }
1851 \cs_new_protected_nopar:Npn \@@_set_equation_depth:
1852 {
1853 \cs_gset_eq:NN \@@_para_after: \@@_empty:
1854 \bool_gset_false:N \g_@@_equation_dp_bool
1855 \@@_set_prevdepth:N \g_@@_prevdepth_dim
1856 }
1857 \bool_new:N \g_@@_equation_dp_bool
1858 % \end{macrocode}
1859 % \end{macro}
1860 %
1861 % \begin{macro}{\@@_build_body_box:}
1862 % \begin{macrocode}
1863 \cs_new_protected_nopar:Npn \@@_build_body_box:
1864 {
1865 \box_set_eq:NN \l_@@_save_body_box \l_@@_bottom_box
1866 \@@_build_window:
1867 \int_compare:nNnTF \g_@@_line_int > \l_@@_window_line_int
1868 { \@@_extract_hbox:NN \l_@@_body_box \l_@@_bottom_box }
1869 { \box_clear:N \l_@@_bottom_box }
1870 \box_if_empty:NF \l_@@_bottom_box
1871 { \bool_set_false:N \l_@@_attach_equation_bool }
1872 \box_clear:N \l_@@_window_box
1873 \@@_build_box:
1874 }
1875 \box_new:N \l_@@_save_body_box
1876 % \end{macrocode}
1877 % \end{macro}
1878 %
1879 % \begin{macro}{\@@_build_body_box:}
1880 % \begin{macrocode}
1881 \cs_new_protected_nopar:Npn \@@_build_window:
1882 {
1883 \vbox_set:Nn \l_@@_body_box
1884 {
1885 \dim_zero:N \tex_emergencystretch:D
1886 \dim_set_eq:NN \tex_hfuzz:D \c_max_dim
1887 \dim_set_eq:NN \tex_vfuzz:D \c_max_dim
1888 \int_set_eq:NN \tex_hbadness:D \c_max_int
1889 \int_set_eq:NN \tex_vbadness:D \c_max_int
1890 \int_set:Nn \tex_tolerance:D { 1000 }
1891 \para_raw_noindent:
1892 \hbox_unpack_drop:N \l_@@_bottom_box
1893 \@@_tex_parameter:
1894 \@@_make_parshape:
1895 \@@_interline_penalties:
1896 \para_raw_end:
1897 \int_gset_eq:NN \g_@@_line_int \tex_prevgraf:D
1898 }
1899 }
1900 % \end{macrocode}
1901 % \end{macro}
1902 %
1903 % \begin{macro}{\@@_make_parshape:}
1904 % \begin{macrocode}
1905 \cs_new_protected_nopar:Npn \@@_make_parshape:
1906 {
1907 \tex_parshape:D
1908 \int_eval:n { \l_@@_window_line_int + 1 } ~
1909 \bool_if:NTF \l_@@_hang_bool
1910 {
1911 \prg_replicate:nn
1912 { \l_@@_window_int }
1913 { \c_zero_dim \l_@@_window_dim }
1914 }
1915 {
1916 \bool_if:NTF \l_@@_column_bool
1917 {
1918 \prg_replicate:nn
1919 { \l_@@_window_int / 2 }
1920 { \c_zero_dim \l_@@_l_dim }
1921 \prg_replicate:nn
1922 {
1923 \bool_if:NTF \g_@@_column_bool
1924 { \g_@@_column_int }
1925 { \l_@@_window_int / 2 }
1926 }
1927 { \c_zero_dim \l_@@_r_dim }
1928 }
1929 {
1930 \prg_replicate:nn
1931 { \l_@@_window_int / 2 }
1932 {
1933 \c_zero_dim \l_@@_l_dim
1934 \c_zero_dim \l_@@_r_dim
1935 }
1936 }
1937 }
1938 \c_zero_dim \c_max_dim
1939 }
1940 % \end{macrocode}
1941 % \end{macro}
1942 %
1943 % \begin{macro}{\@@_interline_penalties:}
1944 % \begin{macrocode}
1945 \cs_new_protected_nopar:Npn \@@_interline_penalties:
1946 {
1947 \bool_if:NF \l_@@_hang_bool
1948 {
1949 \bool_if:NTF \l_@@_column_bool
1950 { \@@_column_penalties: }
1951 { \@@_block_penalties: }
1952 }
1953 }
1954 \cs_new_protected_nopar:Npn \@@_column_penalties:
1955 {
1956 \tex_interlinepenalties:D
1957 \int_eval:n { \l_@@_window_int / 2 + \c_one_int } ~
1958 \prg_replicate:nn
1959 { \l_@@_window_int / 2 - \c_one_int }
1960 { \c_@@_nobreak_int }
1961 \c_@@_break_int
1962 \c_zero_int
1963 }
1964 \cs_new_protected_nopar:Npn \@@_block_penalties:
1965 {
1966 \tex_interlinepenalties:D \l_@@_window_int
1967 \prg_replicate:nn
1968 { \l_@@_window_int - \c_one_int }
1969 { \c_@@_break_int }
1970 \c_zero_int
1971 }
1972 % \end{macrocode}
1973 % \end{macro}
1974 %
1975 % \begin{macro}{\@@_break:,\@@_nobreak:}
1976 % \begin{macrocode}
1977 \cs_new_protected_nopar:Npn \@@_break:
1978 { \tex_penalty:D \c_@@_break_int }
1979 \cs_new_protected_nopar:Npn \@@_nobreak:
1980 { \tex_penalty:D \c_@@_nobreak_int }
1981 \int_const:Nn \c_@@_break_int { -10000 }
1982 \int_const:Nn \c_@@_nobreak_int { 10000 }
1983 % \end{macrocode}
1984 % \end{macro}
1985 %
1986 % \changes{v0.2}{2022/07/22}{提高稳定性。}
1987 %
1988 % \begin{macro}{\@@_build_box:, \@@_build_block:}
1989 % \begin{macrocode}
1990 \cs_new_protected_nopar:Npn \@@_build_block:
1991 {
1992 \vbox_set:Nn \l_@@_window_box
1993 {
1994 \@@_split_parameter:
1995 \skip_set_eq:NN \tex_baselineskip:D \g_@@_baseline_skip
1996 \@@_build_line:
1997 }
1998 }
1999 \cs_new_protected_nopar:Npn \@@_build_line:
2000 {
2001 \vbox_set_split_to_ht:NNn \l_@@_l_box \l_@@_body_box
2002 { \g_@@_baseline_skip }
2003 \vbox_set_split_to_ht:NNn \l_@@_r_box \l_@@_body_box
2004 { \g_@@_baseline_skip }
2005 \@@_build_line_repack:
2006 \box_if_empty:NTF \l_@@_body_box
2007 { \@@_put_last_line: }
2008 {
2009 \@@_put_line_box:
2010 \@@_build_line:
2011 }
2012 }
2013 \cs_new_protected_nopar:Npn \@@_build_line_repack:
2014 {
2015 \vbox_set:Nn \l_@@_l_box
2016 { \vbox_unpack_drop:N \l_@@_l_box }
2017 \box_if_empty:NF \l_@@_r_box
2018 {
2019 \vbox_set:Nn \l_@@_r_box
2020 { \vbox_unpack_drop:N \l_@@_r_box }
2021 }
2022 \@@_save_first_ht:
2023 }
2024 \cs_new_protected_nopar:Npn \@@_put_last_line:
2025 {
2026 \bool_if:NT \l_@@_attach_equation_bool
2027 { \@@_attach_left:N \l_@@_l_box }
2028 \@@_put_line_box:
2029 }
2030 \cs_new_protected_nopar:Npn \@@_put_line_box:
2031 {
2032 \hbox_to_wd:nn { \l_@@_line_dim }
2033 {
2034 \box_use_drop:N \l_@@_l_box
2035 \tex_hfil:D
2036 \box_use_drop:N \l_@@_r_box
2037 }
2038 }
2039 \cs_new_protected_nopar:Npn \@@_save_first_ht:
2040 {
2041 \dim_gset:Nn \g_@@_ht_dim
2042 {
2043 \dim_max:nn
2044 { \box_ht:N \l_@@_l_box }
2045 { \box_ht:N \l_@@_r_box }
2046 }
2047 \cs_set_eq:NN \@@_save_first_ht: \@@_empty:
2048 }
2049 \dim_new:N \g_@@_ht_dim
2050 \box_new:N \l_@@_l_box
2051 \box_new:N \l_@@_r_box
2052 % \end{macrocode}
2053 % \end{macro}
2054 %
2055 % \begin{macro}{\@@_build_column_fuzzy:}
2056 % \begin{macrocode}
2057 \cs_new_protected_nopar:Npn \@@_build_column_fuzzy:
2058 {
2059 \hbox_set_to_wd:Nnn \l_@@_window_box
2060 { \l_@@_line_dim }
2061 {
2062 \@@_split_parameter:
2063 \@@_build_column_aux:
2064 \box_if_empty:NT \l_@@_bottom_box
2065 { \@@_build_column_fuzzy_aux: }
2066 \@@_repack_left_box:
2067 \bool_if:NT \l_@@_attach_equation_bool
2068 { \@@_attach_left:N \l_@@_l_box }
2069 \box_use:N \l_@@_l_box
2070 \tex_hfil:D
2071 \box_move_up:nn
2072 { \box_ht:N \l_@@_l_box - \box_ht:N \l_@@_r_box }
2073 { \box_use_drop:N \l_@@_r_box }
2074 }
2075 }
2076 \cs_new_protected_nopar:Npn \@@_build_column_aux:
2077 {
2078 \vbox_set_split_to_ht:NNn \l_@@_l_box \l_@@_body_box
2079 { \box_ht:N \l_@@_body_box / 2 }
2080 \vbox_set_top:Nn \l_@@_l_box
2081 { \vbox_unpack_drop:N \l_@@_l_box }
2082 \box_set_eq_drop:NN \l_@@_r_box \l_@@_body_box
2083 }
2084 \cs_new_protected_nopar:Npn \@@_build_column_fuzzy_aux:
2085 {
2086 \dim_compare:nNnTF
2087 {
2088 \box_ht_plus_dp:N \l_@@_r_box -
2089 \box_ht_plus_dp:N \l_@@_l_box
2090 }
2091 >
2092 { \l_@@_min_dim }
2093 {
2094 \box_if_empty:NF \l_@@_last_l_box
2095 {
2096 \box_set_eq_drop:NN \l_@@_l_box \l_@@_last_l_box
2097 \box_set_eq_drop:NN \l_@@_r_box \l_@@_last_r_box
2098 }
2099 }
2100 { \@@_rebuild_window: }
2101 }
2102 \cs_new_protected_nopar:Npn \@@_rebuild_window:
2103 {
2104 \int_compare:nNnT \l_@@_window_int > { 2 }
2105 { \@@_rebuild_window_aux: }
2106 }
2107 \cs_new_protected_nopar:Npn \@@_rebuild_window_aux:
2108 {
2109 \int_sub:Nn \l_@@_window_int { 2 }
2110 \box_set_eq_drop:NN \l_@@_last_l_box \l_@@_l_box
2111 \box_set_eq_drop:NN \l_@@_last_r_box \l_@@_r_box
2112 \box_set_eq:NN \l_@@_bottom_box \l_@@_save_body_box
2113 \int_set_eq:NN \l_@@_window_line_int \l_@@_window_int
2114 \@@_build_window:
2115 \@@_build_column_aux:
2116 \@@_build_column_fuzzy_aux:
2117 }
2118 \box_new:N \l_@@_last_l_box
2119 \box_new:N \l_@@_last_r_box
2120 % \end{macrocode}
2121 % \end{macro}
2122 %
2123 % \begin{macro}{\@@_build_column_strict:}
2124 % \begin{macrocode}
2125 \cs_new_protected_nopar:Npn \@@_build_column_strict:
2126 {
2127 \group_begin:
2128 \@@_split_parameter:
2129 \@@_build_column_aux:
2130 \box_if_empty:NTF \l_@@_r_box
2131 { \@@_build_column_strict_auxi: }
2132 {
2133 \box_if_empty:NTF \l_@@_bottom_box
2134 { \@@_build_column_strict_auxii: }
2135 {
2136 \bool_if:NTF \g_@@_column_bool
2137 { \@@_build_column_strict_auxiii: }
2138 { \@@_build_column_strict_auxiv: }
2139 }
2140 }
2141 \group_end:
2142 \box_set_eq_drop:NN \l_@@_window_box \g_@@_window_box
2143 }
2144 \cs_new_protected_nopar:Npn \@@_build_column_strict_auxi:
2145 {
2146 \@@_repack_left_box:
2147 \bool_if:NT \l_@@_attach_equation_bool
2148 { \@@_attach_left:N \l_@@_l_box }
2149 \box_gset_eq_drop:NN \g_@@_window_box \l_@@_l_box
2150 \bool_gset_true:N \g_@@_column_bool
2151 \bool_if:NF \g_@@_first_save_bool
2152 {
2153 \bool_gset_true:N \g_@@_first_save_bool
2154 \dim_gset:Nn \g_@@_first_sep_dim
2155 { \tex_baselineskip:D - \g_@@_ht_dim }
2156 \dim_gset_eq:NN \g_@@_first_dp_dim \g_@@_prevdepth_dim
2157 }
2158 \int_case:nnT { \g_@@_window_int }
2159 {
2160 { \c_zero_int } { }
2161 { \g_@@_line_int } { }
2162 }
2163 { \@@_column_move_entire_aux: }
2164 }
2165 \cs_new_protected_nopar:Npn \@@_column_move_entire_aux:
2166 {
2167 \bool_gset_true:N \g_@@_entire_bool
2168 \bool_gset_true:N \g_@@_next_hang_bool
2169 }
2170 \cs_new_protected_nopar:Npn \@@_column_move_entire:
2171 {
2172 \dim_gsub:Nn \g_@@_first_sep_dim
2173 { \box_dp:N \l_@@_window_box }
2174 \bool_gset_false:N \g_@@_entire_bool
2175 \dim_gzero:N \g_@@_column_ht_dim
2176 \dim_gset_eq:NN \g_@@_prevdepth_dim \g_@@_first_dp_dim
2177 \@@_column_right_move_set:nn
2178 { \g_@@_stuff_ht_dim }
2179 { \g_@@_window_ht_dim }
2180 \int_gset_eq:NN \g_@@_window_int \g_@@_column_int
2181 }
2182 \cs_new_protected:Npn \@@_column_right_move_set:nn #1#2
2183 {
2184 \bool_gset_true:N \g_@@_right_move_bool
2185 \bool_gset_true:N \g_@@_first_set_bool
2186 \tl_gput_right:Nn \g_@@_main_setting_tl
2187 {
2188 \bool_if:NTF \g_@@_first_set_bool
2189 {
2190 \bool_gset_false:N \g_@@_first_set_bool
2191 \bool_set_true:N \l_@@_first_move_bool
2192 }
2193 { \bool_set_false:N \l_@@_first_move_bool }
2194 \fp_zero:N \l_@@_ratio_fp
2195 }
2196 \@@_make_next_stuff:nn
2197 { \l_@@_line_dim - \l_@@_r_dim - \l_@@_rightsep_dim }
2198 {#1}
2199 \dim_gset:Nn \g_@@_column_room_dim {#2}
2200 \int_gzero:N \g_@@_top_int
2201 }
2202 \cs_new_protected_nopar:Npn \@@_build_column_strict_auxii:
2203 {
2204 \bool_gset_false:N \g_@@_entire_bool
2205 \@@_repack_left_box:
2206 \bool_if:NT \l_@@_attach_equation_bool
2207 { \@@_attach_right:N \l_@@_r_box }
2208 \dim_gset:Nn \g_@@_hang_ht_dim
2209 {
2210 \g_@@_stuff_ht_dim - \tex_baselineskip:D *
2211 \@@_unit:n { \box_ht_plus_dp:N \l_@@_r_box }
2212 - \box_ht_plus_dp:N \g_@@_equation_box
2213 - \g_@@_pos_skip
2214 }
2215 \dim_compare:nNnTF \g_@@_hang_ht_dim > \c_zero_dim
2216 { \@@_column_move_right: }
2217 { \@@_column_put_right: }
2218 \box_gset_ht:Nn \g_@@_window_box { \box_ht:N \l_@@_l_box }
2219 \box_gset_dp:Nn \g_@@_window_box { \box_dp:N \l_@@_l_box }
2220 }
2221 \cs_new_protected_nopar:Npn \@@_column_move_right:
2222 {
2223 \int_compare:nNnTF \g_@@_window_int > \c_zero_int
2224 {
2225 \dim_gset:Nn \g_@@_column_room_dim
2226 {
2227 \g_@@_window_ht_dim
2228 - \g_@@_first_sep_dim
2229 - \box_ht_plus_dp:N \l_@@_r_box
2230 - \box_ht_plus_dp:N \g_@@_equation_box
2231 }
2232 \@@_next_hang_para:
2233 }
2234 {
2235 \dim_gset:Nn \g_@@_column_room_dim
2236 {
2237 \box_ht:N \l_@@_l_box
2238 - \box_ht_plus_dp:N \l_@@_r_box
2239 - \box_ht_plus_dp:N \g_@@_equation_box
2240 }
2241 \dim_gset:Nn \g_@@_first_sep_dim
2242 { \tex_baselineskip:D - \g_@@_ht_dim }
2243 \bool_gset_true:N \g_@@_right_move_bool
2244 \bool_gset_true:N \g_@@_next_hang_bool
2245 }
2246 \hbox_gset_to_wd:Nnn \g_@@_window_box
2247 { \l_@@_line_dim }
2248 {
2249 \box_use:N \l_@@_l_box
2250 \tex_hfil:D
2251 \box_move_up:nn
2252 { \g_@@_column_room_dim }
2253 { \box_use:N \l_@@_r_box }
2254 }
2255 \dim_gset:Nn \g_@@_column_ht_dim
2256 {
2257 \box_ht_plus_dp:N \l_@@_r_box
2258 + \box_ht_plus_dp:N \g_@@_equation_box
2259 + \g_@@_pos_skip
2260 }
2261 }
2262 \cs_new_protected_nopar:Npn \@@_column_put_right:
2263 {
2264 \hbox_gset_to_wd:Nnn \g_@@_window_box
2265 { \l_@@_line_dim }
2266 {
2267 \box_use:N \l_@@_l_box
2268 \tex_hfil:D
2269 \box_move_up:nn
2270 {
2271 \int_compare:nNnTF \g_@@_window_int > \c_zero_int
2272 { \g_@@_window_ht_dim - \g_@@_first_sep_dim }
2273 { \box_ht:N \l_@@_l_box }
2274 - \box_ht:N \l_@@_r_box
2275 }
2276 { \box_use:N \l_@@_r_box }
2277 }
2278 \skip_gzero:N \g_@@_pos_skip
2279 }
2280 \cs_new_protected_nopar:Npn \@@_next_hang_para:
2281 {
2282 \bool_if:NTF \g_@@_entire_bool
2283 { \@@_column_move_entire: }
2284 {
2285 \@@_column_right_move_set:nn
2286 { \g_@@_hang_ht_dim }
2287 { \g_@@_column_room_dim }
2288 \int_gzero:N \g_@@_window_int
2289 }
2290 \bool_gset_false:N \g_@@_next_hang_bool
2291 }
2292 \cs_new_protected_nopar:Npn \@@_build_column_strict_auxiii:
2293 {
2294 \bool_gset_false:N \g_@@_column_bool
2295 \@@_repack_left_box:
2296 \hbox_gset_to_wd:Nnn \g_@@_window_box
2297 { \l_@@_line_dim }
2298 {
2299 \box_use:N \l_@@_l_box
2300 \tex_hfil:D
2301 \box_use:N \l_@@_r_box
2302 }
2303 \box_gset_ht:Nn \g_@@_window_box
2304 { \box_ht:N \l_@@_l_box }
2305 }
2306 \cs_new_protected_nopar:Npn \@@_build_column_strict_auxiv:
2307 {
2308 \@@_repack_left_box:
2309 \hbox_gset_to_wd:Nnn \g_@@_window_box
2310 { \l_@@_line_dim }
2311 {
2312 \box_use:N \l_@@_l_box
2313 \tex_hfil:D
2314 \box_move_up:nn
2315 { \box_ht:N \l_@@_l_box - \box_ht:N \l_@@_r_box }
2316 { \box_use_drop:N \l_@@_r_box }
2317 }
2318 }
2319 \cs_new_protected_nopar:Npn \@@_repack_left_box:
2320 {
2321 \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_l_box }
2322 \vbox_set:Nn \l_@@_l_box
2323 { \vbox_unpack_drop:N \l_@@_l_box }
2324 }
2325 \box_new:N \g_@@_window_box
2326 \bool_new:N \l_@@_first_move_bool
2327 % \end{macrocode}
2328 % \end{macro}
2329 %
2330 % \begin{macro}{\@@_build_box:,\@@_build_column:}
2331 % \begin{macrocode}
2332 \bool_new:N \l_@@_column_bool
2333 \cs_new_eq:NN \@@_build_column: \@@_build_column_strict:
2334 \cs_new_eq:NN \@@_build_box: \@@_build_column:
2335 % \end{macrocode}
2336 % \end{macro}
2337 %
2338 % \begin{macro}{\@@_build_hang:}
2339 % \begin{macrocode}
2340 \cs_new_protected_nopar:Npn \@@_build_hang:
2341 {
2342 \bool_if:NTF \g_@@_hangfrom_bool
2343 { \@@_build_hangfrom: }
2344 {
2345 \vbox_set_top:Nn \l_@@_window_box
2346 { \vbox_unpack:N \l_@@_body_box }
2347 \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_window_box }
2348 }
2349 \box_set_eq_drop:NN \l_@@_window_box \l_@@_body_box
2350 \bool_if:NT \l_@@_attach_equation_bool
2351 { \@@_build_hang_attach: }
2352 \dim_compare:nNnT \g_@@_column_room_dim > \c_zero_dim
2353 { \@@_build_hang_move: }
2354 }
2355 \cs_new_protected_nopar:Npn \@@_build_hang_attach:
2356 {
2357 \dim_compare:nNnTF \l_@@_r_dim = \c_zero_dim
2358 { \@@_attach_left:N \l_@@_window_box }
2359 { \@@_attach_right:N \l_@@_window_box }
2360 }
2361 \cs_new_protected_nopar:Npn \@@_build_hang_move:
2362 {
2363 \dim_set:Nn \l_@@_shift_dim
2364 {
2365 \dim_max:nn
2366 { \box_ht:N \l_@@_window_box }
2367 { \tex_baselineskip:D * \g_@@_line_int }
2368 + \box_ht_plus_dp:N \g_@@_equation_box
2369 + \tex_parskip:D
2370 }
2371 \dim_gsub:Nn \g_@@_column_room_dim { \l_@@_shift_dim }
2372 \dim_compare:nNnTF \g_@@_column_room_dim > \c_zero_dim
2373 {
2374 \box_if_empty:NTF \l_@@_bottom_box
2375 { \bool_if:NT \g_@@_right_move_bool { \@@_set_next_hang: } }
2376 }
2377 { \use:n }
2378 {
2379 \bool_gset_false:N \g_@@_move_hang_bool
2380 \bool_gset_false:N \g_@@_right_move_bool
2381 }
2382 }
2383 \cs_new_protected_nopar:Npn \@@_set_next_hang:
2384 {
2385 \bool_if:NF \g_@@_move_hang_bool
2386 {
2387 \bool_gset_true:N \g_@@_move_hang_bool
2388 \dim_gset_eq:NN \g_@@_hang_ht_dim \g_@@_remaining_dim
2389 }
2390 \dim_gsub:Nn \g_@@_hang_ht_dim { \l_@@_shift_dim }
2391 \@@_column_right_move_set:nn
2392 { \g_@@_hang_ht_dim }
2393 { \g_@@_column_room_dim }
2394 \int_gzero:N \g_@@_window_int
2395 }
2396 % \end{macrocode}
2397 % \end{macro}
2398 %
2399 % \begin{macro}{\@@_build_hangfrom:}
2400 % \begin{macrocode}
2401 \cs_new_protected_nopar:Npn \@@_build_hangfrom:
2402 {
2403 \group_begin:
2404 \vbox_gset:Nn \g_@@_window_box
2405 {
2406 \@@_break:
2407 \vbox_unpack:N \l_@@_body_box
2408 }
2409 \@@_split_parameter:
2410 \vbox_set_split_to_ht:NNn \l_@@_last_box \g_@@_window_box
2411 { \c_zero_dim }
2412 \dim_gset:Nn \g_@@_ht_dim
2413 {
2414 \g_@@_baseline_skip
2415 - \g_@@_prevdepth_dim
2416 - \box_ht:N \l_@@_body_box
2417 + \box_ht:N \g_@@_window_box
2418 }
2419 \group_end:
2420 \box_set_eq_drop:NN \l_@@_body_box \g_@@_window_box
2421 }
2422 % \end{macrocode}
2423 % \end{macro}
2424 %
2425 % \changes{v0.3}{2022/07/31}{修复 stuff 深度不为零时的垂直对齐问题。}
2426 %
2427 % \begin{macro}{\@@_put_box:}
2428 % \begin{macrocode}
2429 \cs_new_protected_nopar:Npn \@@_put_box:
2430 {
2431 \@@_para_raw_end:
2432 \dim_compare:nNnTF \g_@@_prevdepth_dim > \c_@@_ignore_depth_dim
2433 { \@@_add_vskip: }
2434 { \@@_set_vskip: }
2435 \skip_set_eq:NN \l_@@_par_skip \tex_parskip:D
2436 \skip_zero:N \tex_parskip:D
2437 \dim_set:Nn \l_@@_window_ht_dim
2438 { \box_ht_plus_dp:N \l_@@_window_box }
2439 \bool_if:NTF \g_@@_right_move_bool
2440 { \@@_put_box_aux: }
2441 {
2442 \box_if_empty:NTF \l_@@_bottom_box
2443 { \@@_put_next_test: }
2444 { \@@_put_box_aux: }
2445 }
2446 }
2447 \dim_new:N \l_@@_window_ht_dim
2448 \skip_new:N \l_@@_par_skip
2449 \cs_new_protected_nopar:Npn \@@_put_next_test:
2450 {
2451 \box_if_empty:NF \g_@@_equation_box
2452 {
2453 \dim_add:Nn \l_@@_window_ht_dim
2454 { \box_ht_plus_dp:N \g_@@_equation_box + \g_@@_pos_skip }
2455 }
2456 \dim_compare:nNnTF
2457 { \g_@@_remaining_dim + \g_@@_pos_skip } > \l_@@_window_ht_dim
2458 { \@@_set_next: }
2459 { \@@_put_box_aux: }
2460 }
2461 \cs_new_protected_nopar:Npn \@@_put_box_aux:
2462 {
2463 \@@_output_window_box:
2464 \box_if_empty:NTF \l_@@_bottom_box
2465 { \@@_put_trailer_box: }
2466 { \@@_put_bottom_box: }
2467 }
2468 \cs_new_protected_nopar:Npn \@@_put_trailer_box:
2469 {
2470 \bool_if:NTF \g_@@_next_hang_bool
2471 {
2472 \@@_next_hang_para:
2473 \@@_next_para_trailer:
2474 }
2475 {
2476 \bool_if:NTF \g_@@_right_move_bool
2477 { \@@_next_para_trailer: }
2478 {
2479 \@@_add_pos_kludge:
2480 \@@_put_pos_box:
2481 \@@_clear_variable:
2482 }
2483 }
2484 }
2485 \cs_new_protected_nopar:Npn \@@_put_bottom_box:
2486 {
2487 \@@_para_raw_end:
2488 \para_raw_noindent:
2489 \hbox_unpack_drop:N \l_@@_bottom_box
2490 \box_if_empty:NF \g_@@_equation_box
2491 { \@@_insert_equation: }
2492 \@@_put_pos_box:
2493 \@@_clear_variable:
2494 }
2495 \cs_new_protected_nopar:Npn \@@_output_window_box:
2496 {
2497 \@@_hbox:n
2498 {
2499 \@@_put_window_box:
2500 \bool_if:NF \g_@@_next_bool
2501 { \@@_output_stuff_box: }
2502 }
2503 }
2504 \cs_new_protected_nopar:Npn \@@_put_pos_box:
2505 {
2506 \box_if_empty:NF \g_@@_pos_box
2507 { \@@_output_pos_box: }
2508 }
2509 \cs_new_protected_nopar:Npn \@@_output_pos_box:
2510 {
2511 \@@_if_last_none:F
2512 { \@@_output_pos_box_aux: }
2513 \hbox_unpack_drop:N \g_@@_pos_box
2514 }
2515 \cs_new_protected_nopar:Npn \@@_output_pos_box_aux:
2516 {
2517 \@@_para_raw_end:
2518 \bool_if:NT \g_@@_equation_dp_bool
2519 { \@@_set_equation_depth: }
2520 \para_raw_noindent:
2521 }
2522 \cs_new_protected:Npn \@@_hbox:n #1
2523 {
2524 \para_raw_noindent:
2525 \hbox_gset:Nn \g_@@_last_box {#1}
2526 \box_gset_wd:Nn \g_@@_last_box { \l_@@_line_dim }
2527 \box_use_drop:N \g_@@_last_box
2528 }
2529 \cs_new_protected_nopar:Npn \@@_put_window_box:
2530 {
2531 \dim_compare:nNnF \l_@@_l_dim > \c_zero_dim
2532 { \skip_horizontal:n { \l_@@_line_dim - \l_@@_r_dim } }
2533 \box_use:N \l_@@_window_box
2534 }
2535 \cs_new_protected_nopar:Npn \@@_output_stuff_box:
2536 {
2537 \hbox_gset:Nn \g_@@_stuff_box
2538 {
2539 \@@_parshape_kern:
2540 \box_move_up:nn
2541 {
2542 \box_dp:N \g_@@_stuff_box
2543 + \box_ht:N \l_@@_window_box
2544 - ( \l_@@_window_ht_dim
2545 + \box_ht_plus_dp:N \g_@@_stuff_box ) / 2
2546 + \l_@@_voffset_dim
2547 }
2548 { \box_use_drop:N \g_@@_stuff_box }
2549 }
2550 \box_gset_ht:Nn \g_@@_stuff_box { \c_zero_dim }
2551 \box_gset_dp:Nn \g_@@_stuff_box { \c_zero_dim }
2552 \skip_horizontal:n
2553 {
2554 \dim_compare:nNnTF \l_@@_r_dim > \c_zero_dim
2555 {
2556 \dim_compare:nNnTF
2557 { \box_wd:N \l_@@_window_box }
2558 <
2559 { \l_@@_window_dim }
2560 { \l_@@_leftsep_dim }
2561 {
2562 - \l_@@_r_dim
2563 - \l_@@_rightsep_dim
2564 - \g_@@_stuff_wd_dim
2565 }
2566 }
2567 { \l_@@_leftsep_dim }
2568 }
2569 \box_use_drop:N \g_@@_stuff_box
2570 }
2571 % \end{macrocode}
2572 % \end{macro}
2573 %
2574 % \begin{macro}{\@@_add_vskip:}
2575 % \begin{macrocode}
2576 \cs_new_protected_nopar:Npn \@@_add_vskip:
2577 {
2578 \box_if_empty:NTF \g_@@_display_box
2579 { \@@_add_vskip_auxi: }
2580 { \@@_add_vskip_display: }
2581 }
2582 \cs_new_protected_nopar:Npn \@@_add_vskip_display:
2583 {
2584 \bool_set_true:N \l_@@_display_pre_bool
2585 \vbox_unpack_drop:N \g_@@_display_box
2586 \@@_ignore_depth:
2587 }
2588 \cs_new_protected_nopar:Npn \@@_add_vskip_auxi:
2589 {
2590 \dim_compare:nNnTF \tex_pagegoal:D < \c_max_dim
2591 { \@@_add_vskip_auxii: }
2592 {
2593 \bool_if:NTF \g_@@_next_bool
2594 { \@@_add_vskip_auxii: }
2595 { \@@_add_vskip_auxiii: }
2596 }
2597 }
2598 \cs_new_protected_nopar:Npn \@@_add_vskip_auxii:
2599 {
2600 \@@_add_vskip_auxiv:
2601 \bool_if:NTF \l_@@_first_move_bool
2602 { \@@_first_move_skip: }
2603 { \skip_vertical:N \g_@@_pre_skip }
2604 \@@_ignore_depth:
2605 }
2606 \cs_new_protected_nopar:Npn \@@_add_vskip_auxiii:
2607 {
2608 \@@_add_vskip_auxiv:
2609 \skip_vertical:N \g_@@_pre_skip
2610 \dim_compare:nNnTF \tex_topskip:D > \g_@@_ht_dim
2611 {
2612 \skip_sub:Nn \tex_topskip:D { \g_@@_ht_dim }
2613 \tex_hrule:D height \c_zero_dim \scan_stop:
2614 }
2615 { \@@_ignore_depth: }
2616 }
2617 \cs_new_protected_nopar:Npn \@@_add_vskip_auxiv:
2618 {
2619 \skip_gset:Nn \g_@@_pre_skip
2620 {
2621 \g_@@_baseline_skip
2622 - \g_@@_prevdepth_dim
2623 - \g_@@_ht_dim
2624 }
2625 \dim_compare:nNnT \g_@@_pre_skip < \tex_lineskiplimit:D
2626 { \skip_gset_eq:NN \g_@@_pre_skip \tex_lineskip:D }
2627 }
2628 \cs_new_protected_nopar:Npn \@@_first_move_skip:
2629 {
2630 \skip_vertical:n
2631 {
2632 \g_@@_first_sep_dim
2633 - \g_@@_window_ht_dim
2634 - \tex_parskip:D
2635 \dim_compare:nNnT \g_@@_column_ht_dim > \c_zero_dim
2636 { + \g_@@_column_ht_dim + \g_@@_pre_skip }
2637 }
2638 }
2639 \skip_new:N \g_@@_pre_skip
2640 \bool_new:N \l_@@_display_pre_bool
2641 % \end{macrocode}
2642 % \end{macro}
2643 %
2644 % \begin{macro}{\@@_set_vskip:}
2645 % \begin{macrocode}
2646 \cs_new_protected_nopar:Npn \@@_set_vskip:
2647 {
2648 \box_if_empty:NTF \g_@@_display_box
2649 {
2650 \skip_gset:Nn \g_@@_pre_skip
2651 { \g_@@_baseline_skip - \g_@@_ht_dim }
2652 }
2653 { \@@_add_vskip_display: }
2654 }
2655 % \end{macrocode}
2656 % \end{macro}
2657 %
2658 % \begin{macro}{\@@_ignore_depth:,\@@_set_prevdepth:N}
2659 % \begin{macrocode}
2660 \cs_new_protected_nopar:Npn \@@_ignore_depth:
2661 { \dim_set_eq:NN \tex_prevdepth:D \c_@@_ignore_depth_dim }
2662 \cs_new_protected_nopar:Npn \@@_set_prevdepth:N
2663 { \dim_set_eq:NN \tex_prevdepth:D }
2664 \dim_const:Nn \c_@@_ignore_depth_dim { -1000pt }
2665 % \end{macrocode}
2666 % \end{macro}
2667 %
2668 % \begin{macro}{\@@_set_next:}
2669 % \begin{macrocode}
2670 \cs_new_protected_nopar:Npn \@@_set_next:
2671 {
2672 \dim_set:Nn \l_@@_height_dim
2673 {
2674 \bool_if:NT \g_@@_next_bool { \l_@@_par_skip }
2675 + \g_@@_pre_skip
2676 + \l_@@_window_ht_dim
2677 }
2678 \dim_gadd:Nn \g_@@_total_ht_dim { \l_@@_height_dim }
2679 \dim_set:Nn \l_@@_shift_dim
2680 { \g_@@_remaining_dim - \l_@@_height_dim }
2681 \dim_compare:nNnTF
2682 { - \l_@@_shift_dim } < \l_@@_min_dim
2683 { \@@_set_next_para: }
2684 { \@@_set_next_output: }
2685 }
2686 \cs_new_protected_nopar:Npn \@@_set_next_para:
2687 {
2688 \int_gset:Nn \g_@@_window_int
2689 {
2690 \dim_compare:nNnTF \l_@@_shift_dim > \c_zero_dim
2691 { \@@_unit:n { \l_@@_shift_dim } }
2692 { \c_one_int }
2693 }
2694 \@@_set_next_verify:
2695 \@@_output_window_box:
2696 \@@_make_next_stuff:nn
2697 { \g_@@_stuff_wd_dim }
2698 { \l_@@_shift_dim }
2699 \int_gzero:N \g_@@_top_int
2700 \@@_next_para_trailer:
2701 }
2702 \cs_new_protected_nopar:Npn \@@_set_next_output:
2703 {
2704 \@@_output_window_box:
2705 \@@_add_pos_kludge:
2706 \@@_put_pos_box:
2707 \@@_clear_variable:
2708 }
2709 \cs_new_protected_nopar:Npn \@@_set_next_verify:
2710 {
2711 \dim_set:Nn \l_@@_height_dim
2712 { \g_@@_window_ht_dim - \g_@@_total_ht_dim - \l_@@_min_dim }
2713 \dim_while_do:nNnn
2714 { \tex_baselineskip:D * \g_@@_window_int + \l_@@_par_skip }
2715 <
2716 { \l_@@_height_dim }
2717 { \int_gincr:N \g_@@_window_int }
2718 \bool_if:NF \g_@@_next_bool
2719 {
2720 \dim_add:Nn \l_@@_window_ht_dim
2721 { \tex_baselineskip:D * \g_@@_window_int + \l_@@_par_skip }
2722 }
2723 }
2724 % \end{macrocode}
2725 % \end{macro}
2726 %
2727 % \begin{macro}{\@@_next_para_trailer:}
2728 % \begin{macrocode}
2729 \cs_new_protected_nopar:Npn \@@_next_para_trailer:
2730 {
2731 \@@_add_pos_kludge:
2732 \box_if_empty:NTF \g_@@_pos_box
2733 { \@@_next_para: }
2734 {
2735 \@@_env_begin:
2736 \hbox_unpack_drop:N \g_@@_pos_box
2737 \@@_env_end:
2738 }
2739 }
2740 % \end{macrocode}
2741 % \end{macro}
2742 %
2743 % \begin{macro}{\@@_make_next_stuff:nn}
2744 % \begin{macrocode}
2745 \cs_new_protected:Npn \@@_make_next_stuff:nn #1#2
2746 {
2747 \bool_gset_true:N \g_@@_next_bool
2748 \dim_gset:Nn \g_@@_stuff_wd_dim {#1}
2749 \dim_gset:Nn \g_@@_remaining_dim {#2}
2750 }
2751 % \end{macrocode}
2752 % \end{macro}
2753 %
2754 % \begin{macro}{\@@_extract_hbox:NN}
2755 % \begin{macrocode}
2756 \cs_new_protected:Npn \@@_extract_display_hbox:NN #1
2757 {
2758 \box_gclear:N \g_@@_pos_box
2759 \vbox_set:Nn #1
2760 {
2761 \vbox_unpack_drop:N #1
2762 \bool_if:NTF \g_@@_display_bool
2763 { \@@_test_display_math: }
2764 { \box_gclear:N \g_@@_display_box }
2765 \box_if_empty:NTF \g_@@_display_box
2766 {
2767 \bool_gset_false:N \g_@@_amsmath_bool
2768 \@@_extract_last_hbox:N \g_@@_last_box
2769 }
2770 { \box_gclear:N \g_@@_last_box }
2771 }
2772 \box_if_empty:NF \g_@@_display_box
2773 { \dim_gset:Nn \g_@@_display_pre_dim { \box_dp:N #1 } }
2774 \@@_extract_hbox_aux:N
2775 }
2776 \cs_new_protected:Npn \@@_extract_hbox:NN #1
2777 {
2778 \vbox_set:Nn #1
2779 {
2780 \vbox_unpack_drop:N #1
2781 \@@_extract_last_hbox:N \g_@@_last_box
2782 }
2783 \@@_extract_hbox_aux:N
2784 }
2785 \cs_new_protected:Npn \@@_extract_hbox_aux:N #1
2786 {
2787 \box_if_empty:NTF \g_@@_last_box
2788 { \box_clear:N #1 }
2789 { \@@_repack_hbox:N #1 }
2790 }
2791 \cs_new_protected:Npn \@@_repack_hbox:N #1
2792 {
2793 \hbox_set:Nn #1
2794 {
2795 \skip_if_eq:nnF
2796 { \g_@@_main_left_skip } { \c_zero_skip }
2797 { \skip_horizontal:N \g_@@_main_left_skip }
2798 \hbox_unpack_drop:N \g_@@_last_box
2799 \tex_unskip:D \tex_unskip:D \tex_unpenalty:D
2800 }
2801 }
2802 \cs_new_protected:Npn \@@_extract_last_hbox:N #1
2803 {
2804 \@@_if_last_hlist:TF
2805 {
2806 \box_gset_to_last:N #1
2807 \tex_unskip:D
2808 }
2809 { \box_gclear:N #1 }
2810 }
2811 \box_new:N \g_@@_last_box
2812 \box_new:N \g_@@_display_box
2813 \dim_new:N \g_@@_display_pre_dim
2814 % \end{macrocode}
2815 % \end{macro}
2816 %
2817 % \begin{macro}{\@@_test_display_math:}
2818 % \begin{macrocode}
2819 \cs_new_protected_nopar:Npn \@@_test_display_math:
2820 {
2821 \@@_if_last_hlist:T { \@@_extract_pos_hbox: }
2822 \box_clear:N \l_@@_add_box
2823 \box_gclear:N \g_@@_display_box
2824 \skip_gzero:N \g_@@_last_skip
2825 \skip_gzero:N \g_@@_display_pre_skip
2826 \bool_gset_false:N \g_@@_amsmath_bool
2827 \@@_add_last_skip:w
2828 \@@_add_last_penalty:w
2829 \@@_add_last_box:w
2830 \@@_add_last_skip:w
2831 \@@_add_last_skip:w
2832 \@@_add_last_penalty:w
2833 \@@_add_last_finalise:w \s_stop
2834 }
2835 \cs_new_protected_nopar:Npn \@@_extract_pos_hbox:
2836 {
2837 \box_gset_to_last:N \g_@@_last_box
2838 \@@_repack_hbox:N \l_@@_last_box
2839 \box_gset_eq_drop:NN \g_@@_pos_box \l_@@_last_box
2840 \tex_unskip:D
2841 }
2842 \box_new:N \l_@@_add_box
2843 \box_new:N \g_@@_pos_box
2844 % \end{macrocode}
2845 % \end{macro}
2846 %
2847 % \begin{macro}{\@@_add_last_stop:w}
2848 % \begin{macrocode}
2849 \cs_new_protected_nopar:Npn \@@_add_last_stop:w
2850 {
2851 \vbox_unpack_drop:N \l_@@_add_box
2852 \use_none_delimit_by_s_stop:w
2853 }
2854 % \end{macrocode}
2855 % \end{macro}
2856 %
2857 % \begin{macro}{\@@_add_last_skip:w}
2858 % \begin{macrocode}
2859 \cs_new_protected_nopar:Npn \@@_add_last_skip:w
2860 {
2861 \@@_if_last_glue:TF
2862 {
2863 \skip_set_eq:NN \l_@@_last_skip \tex_lastskip:D
2864 \vbox_set:Nn \l_@@_add_box
2865 {
2866 \skip_vertical:N \l_@@_last_skip
2867 \vbox_unpack_drop:N \l_@@_add_box
2868 }
2869 \tex_unskip:D
2870 \skip_gadd:Nn \g_@@_last_skip { \l_@@_last_skip }
2871 }
2872 { \@@_skip_stop:w }
2873 }
2874 \skip_new:N \l_@@_last_skip
2875 \skip_new:N \g_@@_last_skip
2876 \cs_new_eq:NN \@@_skip_stop:w \@@_add_last_stop:w
2877 % \end{macrocode}
2878 % \end{macro}
2879 %
2880 % \begin{macro}{\@@_add_last_penalty:w}
2881 % \begin{macrocode}
2882 \cs_new_protected_nopar:Npn \@@_add_last_penalty:w
2883 {
2884 \@@_if_last_penalty:TF
2885 {
2886 \int_set_eq:NN \l_@@_last_int \tex_lastpenalty:D
2887 \vbox_set:Nn \l_@@_add_box
2888 {
2889 \tex_penalty:D \l_@@_last_int
2890 \vbox_unpack_drop:N \l_@@_add_box
2891 }
2892 \tex_unpenalty:D
2893 \skip_gset_eq:NN \g_@@_pre_skip \g_@@_last_skip
2894 \skip_gzero:N \g_@@_last_skip
2895 }
2896 { \@@_penalty_stop:w }
2897 }
2898 \int_new:N \l_@@_last_int
2899 \cs_new_eq:NN \@@_penalty_stop:w \@@_add_last_stop:w
2900 % \end{macrocode}
2901 % \end{macro}
2902 %
2903 % \begin{macro}{\@@_add_last_box:w}
2904 % \begin{macrocode}
2905 \cs_new_protected_nopar:Npn \@@_add_last_box:w
2906 {
2907 \@@_if_last_hlist:TF
2908 {
2909 \skip_gzero:N \g_@@_last_skip
2910 \box_set_to_last:N \l_@@_last_box
2911 \vbox_set:Nn \l_@@_add_box
2912 {
2913 \box_use_drop:N \l_@@_last_box
2914 \vbox_unpack_drop:N \l_@@_add_box
2915 }
2916 }
2917 { \@@_box_stop:w }
2918 }
2919 \box_new:N \l_@@_last_box
2920 \cs_new_eq:NN \@@_box_stop:w \@@_add_last_stop:w
2921 % \end{macrocode}
2922 % \end{macro}
2923 %
2924 % \begin{macro}{\@@_add_last_finalise:w}
2925 % \begin{macrocode}
2926 \cs_new_protected_nopar:Npn \@@_add_last_finalise:w
2927 {
2928 \int_gset_eq:NN \g_@@_display_pre_int \l_@@_last_int
2929 \skip_gadd:Nn \g_@@_display_pre_skip { \g_@@_pre_skip }
2930 \int_case:nnTF { \tex_lastnodetype:D }
2931 {
2932 { \c_@@_hlist_node } { }
2933 { \c_@@_none_node } { }
2934 { \c_@@_whatsit_node } { }
2935 }
2936 { \box_gset_eq_drop:NN \g_@@_display_box \l_@@_add_box }
2937 { \vbox_unpack_drop:N \l_@@_add_box }
2938 \use_none_delimit_by_s_stop:w
2939 }
2940 \int_new:N \g_@@_display_pre_int
2941 \skip_new:N \g_@@_display_pre_skip
2942 % \end{macrocode}
2943 % \end{macro}
2944 %
2945 % \begin{macro}{\@@_amsmath_boot:w,\@@_amsmath_recursion:w,\@@_amsmath_multline:w}
2946 % \pkg{amsmath} 的 \env{align} 等数学环境内部是一个 \tn{halign} 环境,结构不一样,需要另外处理。
2947 % \begin{macrocode}
2948 \cs_new_protected_nopar:Npn \@@_amsmath_boot:w
2949 {
2950 \@@_add_last_skip:w
2951 \@@_add_last_penalty:w
2952 \cs_set_eq:NN \@@_box_stop:w \@@_add_last_stop:w
2953 \@@_add_last_box:w
2954 \bool_gset_true:N \g_@@_amsmath_bool
2955 \cs_set_eq:NN \@@_skip_stop:w \@@_amsmath_multline:w
2956 \cs_set_eq:NN \@@_penalty_stop:w \@@_amsmath_stop:NN
2957 \@@_amsmath_recursion:w
2958 }
2959 \cs_new_protected_nopar:Npn \@@_amsmath_recursion:w
2960 {
2961 \@@_add_last_skip:w
2962 \@@_add_last_skip:w
2963 \@@_add_last_penalty:w
2964 \@@_add_last_box:w
2965 \@@_amsmath_recursion:w
2966 }
2967 \cs_new_protected:Npn \@@_amsmath_stop:NN #1#2
2968 {
2969 \cs_set_eq:NN \@@_skip_stop:w \@@_add_last_stop:w
2970 \cs_set_eq:NN \@@_penalty_stop:w \@@_add_last_stop:w
2971 }
2972 \bool_new:N \g_@@_amsmath_bool
2973 % \end{macrocode}
2974 % \end{macro}
2975 %
2976 % \begin{macro}{\@@_amsmath_multline:w}
2977 % \env{multline} 环境的结构与其他环境不一样。\pkg{amsmath} 的 \tn{@display@init} 定义为
2978 % \begin{verbatim}
2979 % \def\@display@init#1{%
2980 % \global\dt@ptrue \spread@equation
2981 % \everycr{%
2982 % \noalign{%
2983 % #1%
2984 % \ifdt@p
2985 % \global\dt@pfalse
2986 % \vskip-\lineskiplimit
2987 % \vskip\normallineskiplimit
2988 % \else
2989 % \penalty\@eqpen \global\dspbrk@lvl\m@ne
2990 % \fi
2991 % }%
2992 % }%
2993 % }
2994 % \end{verbatim}
2995 % \env{align} 等环境的开头 \tn{ifdt@p} 为真,会插入两个 \tn{vskip},
2996 % 但是 \env{multline} 定义中的 \tn{mmeasure@} 没有重定义 \tn{everycr},
2997 % 上述定义中的 \tn{dt@pfalse} 被执行,导致环境开头被加入了 \tn{penalty},
2998 % 不确定是有意为之还是疏忽^^A
2999 % \footnote{\url{https://github.com/latex3/latex2e/issues/793}}。
3000 % \begin{macrocode}
3001 \cs_new_protected_nopar:Npn \@@_amsmath_multline:w
3002 {
3003 \@@_amsmath_stop:NN ? ?
3004 \@@_add_last_penalty:w
3005 \skip_gset_eq:NN \g_@@_display_pre_skip
3006 \g_@@_pre_skip
3007 \@@_add_last_skip:w
3008 \@@_add_last_penalty:w
3009 \@@_add_last_finalise:w
3010 }
3011 % \end{macrocode}
3012 % \end{macro}
3013 %
3014 % \begin{macro}{\@@_amsmath_leqno:}
3015 % \pkg{amsmath} 的 \opt{leqno} 是直接用 \cs{tex_leqno:D} 实现的,与 \LaTeX\ 的实现不一样。
3016 % \begin{macrocode}
3017 \cs_new_protected_nopar:Npn \@@_amsmath_leqno:
3018 {
3019 \legacy_if:nTF { tagsleft@ }
3020 { \bool_gset_true:N \g_@@_leqno_bool }
3021 { \bool_gset_false:N \g_@@_leqno_bool }
3022 }
3023 % \end{macrocode}
3024 % \end{macro}
3025 %
3026 % \begin{macrocode}
3027 \@@_package_hook:nn { amsmath }
3028 {
3029 \cs_gset_eq:NN \@@_box_stop:w
3030 \@@_amsmath_boot:w
3031 \cs_gset_eq:NN \@@_test_leqno:
3032 \@@_amsmath_leqno:
3033 }
3034 % \end{macrocode}
3035 %
3036 % \begin{macro}{\@@_set_float:}
3037 % \begin{macrocode}
3038 \cs_new_protected_nopar:Npn \@@_set_float:
3039 {
3040 \cs_set_eq:NN \@captype \l_@@_type_tl
3041 \@@_float_pre_hook:
3042 \@@_caption_hook:
3043 \@floatboxreset
3044 }
3045 % \end{macrocode}
3046 % \end{macro}
3047 %
3048 % \begin{macro}{\@@_float_pre_hook:, \@@_float_pos_hook:}
3049 % \begin{macrocode}
3050 \cs_new_eq:NN \@@_float_pre_hook: \@@_empty:
3051 \cs_new_eq:NN \@@_float_pos_hook: \@@_empty:
3052 \@@_package_hook:nn { float }
3053 {
3054 \bool_new:N \g_@@_float_pos_bool
3055 \cs_gset_protected_nopar:Npn \@@_float_pre_hook:
3056 { \exp_args:No \@@_float_pre_aux:n { \l_@@_type_tl } }
3057 \cs_new_protected:Npn \@@_float_pre_aux:n #1
3058 {
3059 \cs_if_exist_use:cTF { fst@ #1 }
3060 {
3061 \@float@setevery {#1}
3062 \bool_gset_true:N \g_@@_float_pos_bool
3063 }
3064 { \bool_gset_false:N \g_@@_float_pos_bool }
3065 }
3066 \cs_gset_protected_nopar:Npn \@@_float_pos_hook:
3067 {
3068 \bool_if:NT \g_@@_float_pos_bool
3069 { \exp_args:No \@@_float_pos_aux:n { \l_@@_type_tl } }
3070 }
3071 \cs_new_protected:Npn \@@_float_pos_aux:n #1
3072 {
3073 \hbox_gset:Nn \g_@@_stuff_box
3074 {
3075 \use:c { fst@ #1 }
3076 \cs_set_eq:NN \@currbox \g_@@_stuff_box
3077 \vbox_gset:Nn \g_@@_stuff_box
3078 { \box_use_drop:N \g_@@_stuff_box }
3079 \exp_args:Ne \float@makebox
3080 { \dim_eval:n { \box_wd:N \g_@@_stuff_box } }
3081 }
3082 }
3083 }
3084 % \end{macrocode}
3085 % \end{macro}
3086 %
3087 % \begin{macro}{\@@_floatrow_hook:}
3088 % \begin{macrocode}
3089 \cs_new_eq:NN \@@_floatrow_hook: \@@_empty:
3090 \@@_package_hook:nn { floatrow }
3091 {
3092 \cs_gset_protected_nopar:Npn \@@_floatrow_hook:
3093 {
3094 \cs_set_eq:NN \@captype \l_@@_type_tl
3095 \killfloatstyle
3096 \FR@redefs
3097 \dim_zero:N \FBc@wd
3098 \exp_args:Ne \flrow@setlist
3099 {
3100 { \l_@@_type_tl }
3101 { wrapfloat }
3102 { wrap \l_@@_type_tl }
3103 }
3104 \FRifFBOX \@@@@setframe \relax \@@@@FStrue
3105 \hbox_gset:Nw \g_@@_stuff_box
3106 \tl_set:Nx \FBB@wd { \dim_use:N \l_@@_width_dim }
3107 \FB@fs@wd
3108 \dim_set:Nn \l_@@_width_dim { \FBo@wd }
3109 }
3110 \cs_gset_protected_nopar:Npn \@@_float_pre_hook:
3111 { \the \FR@everyfloat }
3112 \cs_gset_protected_nopar:Npn \@@_float_pos_hook:
3113 {
3114 \legacy_if:nTF { FBbuild }
3115 {
3116 \cs_set_eq:NN \@currbox \g_@@_stuff_box
3117 \vbox_gset:Nn \g_@@_stuff_box
3118 { \box_use_drop:N \g_@@_stuff_box }
3119 \flrow@FB { \l_@@_width_dim }
3120 }
3121 {
3122 \cs_undefine:N \flrow@typ@tmpset
3123 \box_use_drop:N \g_@@_stuff_box
3124 }
3125 \hbox_gset_end:
3126 }
3127 }
3128 % \end{macrocode}
3129 % \end{macro}
3130 %
3131 % \begin{macro}{\@@_caption_hook:}
3132 % \begin{macrocode}
3133 \cs_new_eq:NN \@@_caption_hook: \@@_empty:
3134 \@@_package_hook:nn { caption }
3135 {
3136 \cs_gset_protected_nopar:Npn \@@_caption_hook:
3137 { \exp_args:No \@@_caption_aux:n { \l_@@_type_tl } }
3138 \cs_new_protected:Npn \@@_caption_aux:n #1
3139 {
3140 \caption@settype {#1}
3141 \caption@clearmargin
3142 \caption@setoptions { wrap #1 }
3143 }
3144 }
3145 % \end{macrocode}
3146 % \end{macro}
3147 %
3148 % \begin{macro}{top}
3149 % \begin{macrocode}
3150 \keys_define:nn { wrapstuff }
3151 {
3152 abovesep .tl_set:N = \l_@@_abovesep_tl ,
3153 belowsep .tl_set:N = \l_@@_belowsep_tl ,
3154 leftsep .tl_set:N = \l_@@_leftsep_tl ,
3155 rightsep .tl_set:N = \l_@@_rightsep_tl ,
3156 linewidth .tl_set:N = \l_@@_linewidth_tl ,
3157 lines .tl_set:N = \l_@@_lines_tl ,
3158 width .tl_set:N = \l_@@_width_tl ,
3159 height .tl_set:N = \l_@@_height_tl ,
3160 hoffset .tl_set:N = \l_@@_hoffset_tl ,
3161 voffset .tl_set:N = \l_@@_voffset_tl ,
3162 type .tl_set:N = \l_@@_type_tl ,
3163 ratio .fp_set:N = \l_@@_ratio_fp ,
3164 top .int_set:N = \l_@@_top_int ,
3165 i .code:n = \@@_swap_true:N \c_true_bool ,
3166 o .code:n = \@@_swap_true:N \c_false_bool ,
3167 l .code:n = \@@_swap_false:N \c_zero_fp ,
3168 r .code:n = \@@_swap_false:N \c_one_fp ,
3169 c .code:n = \@@_swap_false:N \c_@@_c_fp ,
3170 column .choice: ,
3171 column/true .code:n =
3172 {
3173 \bool_set_true:N \l_@@_column_bool
3174 \cs_set_eq:NN \@@_build_column:
3175 \@@_build_column_strict:
3176 } ,
3177 column/par .code:n =
3178 {
3179 \bool_set_true:N \l_@@_column_bool
3180 \cs_set_eq:NN \@@_build_column:
3181 \@@_build_column_fuzzy:
3182 } ,
3183 column/false .code:n =
3184 { \bool_set_false:N \l_@@_column_bool } ,
3185 hsep .code:n =
3186 {
3187 \tl_set:Nn \l_@@_leftsep_tl {#1}
3188 \tl_set_eq:NN \l_@@_rightsep_tl
3189 \l_@@_leftsep_tl
3190 } ,
3191 vsep .code:n =
3192 {
3193 \tl_set:Nn \l_@@_abovesep_tl {#1}
3194 \tl_set_eq:NN \l_@@_belowsep_tl
3195 \l_@@_abovesep_tl
3196 } ,
3197 unknown .code:n =
3198 { \exp_args:No \@@_unknown_key:n { \l_keys_key_str } } ,
3199 leftsep .groups:n = main ,
3200 rightsep .groups:n = main ,
3201 hsep .groups:n = main ,
3202 linewidth .groups:n = main ,
3203 lines .groups:n = main ,
3204 column .groups:n = main ,
3205 hoffset .groups:n = main ,
3206 voffset .groups:n = main ,
3207 top .groups:n = stuff ,
3208 abovesep .groups:n = stuff ,
3209 belowsep .groups:n = stuff ,
3210 vsep .groups:n = stuff ,
3211 width .groups:n = stuff ,
3212 height .groups:n = stuff ,
3213 float .groups:n = stuff ,
3214 ratio .groups:n = ratio ,
3215 l .groups:n = ratio ,
3216 r .groups:n = ratio ,
3217 c .groups:n = ratio ,
3218 i .groups:n = ratio ,
3219 o .groups:n = ratio ,
3220 column .default:n = true ,
3221 column .initial:n = true ,
3222 abovesep .initial:n = \c_zero_dim ,
3223 belowsep .initial:n = \c_zero_dim ,
3224 leftsep .initial:n = 1em ,
3225 rightsep .initial:n = 1em ,
3226 linewidth .initial:n = \linewidth ,
3227 hoffset .initial:n = \c_zero_dim ,
3228 voffset .initial:n = \c_zero_dim ,
3229 width .initial:n = \c_zero_dim ,
3230 height .initial:n = \c_zero_dim ,
3231 ratio .initial:n = \c_one_fp ,
3232 abovesep .value_required:n = true ,
3233 belowsep .value_required:n = true ,
3234 leftsep .value_required:n = true ,
3235 rightsep .value_required:n = true ,
3236 linewidth .value_required:n = true ,
3237 width .value_required:n = true ,
3238 height .value_required:n = true ,
3239 hoffset .value_required:n = true ,
3240 voffset .value_required:n = true ,
3241 hsep .value_required:n = true ,
3242 vsep .value_required:n = true ,
3243 l .value_forbidden:n = true ,
3244 r .value_forbidden:n = true ,
3245 c .value_forbidden:n = true ,
3246 i .value_forbidden:n = true ,
3247 o .value_forbidden:n = true
3248 }
3249 \fp_const:Nn \c_@@_c_fp { 0.5 }
3250 \cs_new_protected:Npn \@@_swap_true:N #1
3251 {
3252 \bool_set_true:N \l_@@_swap_bool
3253 \bool_set_eq:NN \l_@@_inner_bool #1
3254 \bool_if:NTF \l_@@_inner_bool
3255 { \bool_set_false:N \l_@@_outer_bool }
3256 { \bool_set_true:N \l_@@_outer_bool }
3257 }
3258 \cs_new_protected_nopar:Npn \@@_swap_false:N
3259 {
3260 \bool_set_false:N \l_@@_swap_bool
3261 \fp_set_eq:NN \l_@@_ratio_fp
3262 }
3263 \cs_new_protected:Npn \@@_unknown_key:n #1
3264 {
3265 \regex_match:NnTF \c_@@_integer_regex {#1}
3266 { \int_set:Nn \l_@@_top_int }
3267 { \@@_unknown_key_error:n }
3268 {#1}
3269 }
3270 \regex_const:Nn \c_@@_integer_regex { \A \d+ \Z }
3271 \cs_new_protected_nopar:Npn \@@_unknown_key_error:n
3272 { \msg_error:nnn { wstf } { unknown-key } }
3273 \msg_new:nnnn { wstf } { unknown-key }
3274 { The~key~"#1"~is~unknown~and~is~being~ignored. }
3275 {
3276 The~package~wrapstuff~does~not~have~a~key~called~"#1".\\
3277 Check~that~you~have~spelled~the~key~name~correctly.
3278 }
3279 % \end{macrocode}
3280 % \end{macro}
3281 %
3282 % \begin{macro}{\wrapstuffset}
3283 % \begin{macrocode}
3284 \NewDocumentCommand \wrapstuffset { m }
3285 { \keys_set:nn { wrapstuff } {#1} }
3286 % \end{macrocode}
3287 % \end{macro}
3288 %
3289 % \begin{macro}{\wrapstuffclear}
3290 % 保险起见,加入 \tn{par} 结束段落,同时结束 \env{wrapstuff@par} 环境。
3291 % \begin{macrocode}
3292 \NewDocumentCommand \wrapstuffclear { }
3293 {
3294 \par
3295 \@@_clear:
3296 }
3297 % \end{macrocode}
3298 % \end{macro}
3299 %
3300 % \begin{macrocode}
3301 \cs_if_exist:NTF \ProcessKeyOptions
3302 { \ProcessKeyOptions [ wrapstuff ] }
3303 {
3304 \RequirePackage { l3keys2e }
3305 \ProcessKeysOptions { wrapstuff }
3306 }
3307 % \end{macrocode}
3308 %
3309 % \begin{macrocode}
3310 %</package>
3311 % \end{macrocode}
3312 %
3313 % \end{implementation}
3314 %
3315 % \Finale
3316 %
3317 \endinput