diff options
author | Norbert Preining <norbert@preining.info> | 2022-07-21 03:00:45 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-07-21 03:00:45 +0000 |
commit | 5cf5182b44c08dfb2bc977ce5aa5ca6d03b36923 (patch) | |
tree | b32d29c9fb1289ccc994ee099b27c4a45b621a0a /macros/latex/contrib/wrapstuff | |
parent | 2773132ea593028dafe764f7560fd94ecb827d3d (diff) |
CTAN sync 202207210300
Diffstat (limited to 'macros/latex/contrib/wrapstuff')
-rw-r--r-- | macros/latex/contrib/wrapstuff/README.md | 50 | ||||
-rw-r--r-- | macros/latex/contrib/wrapstuff/wrapstuff.dtx | 3011 | ||||
-rw-r--r-- | macros/latex/contrib/wrapstuff/wrapstuff.pdf | bin | 0 -> 422157 bytes |
3 files changed, 3061 insertions, 0 deletions
diff --git a/macros/latex/contrib/wrapstuff/README.md b/macros/latex/contrib/wrapstuff/README.md new file mode 100644 index 0000000000..017a8bf27c --- /dev/null +++ b/macros/latex/contrib/wrapstuff/README.md @@ -0,0 +1,50 @@ +wrapstuff +========= + +The `wrapstuff` package provides another implementation of text wrapping. +Its implementation benefits from the paragraph hooks available since +LaTeX 2021-06-01. + +Basic Usage +----------- +The package only provides a user environment `wrapstuff`. + + \begin{wrapstuff}[<options>] + <wrapping stuff> + \end{wrapstuff} + <main text> + +You can read the package manual (in Chinese) for some explanations. + +Contributing +------------ +The package is still highly experimental and not fully tested. +[Issues](https://github.com/qinglee/wrapstuff/issues) and +[pull requests](https://github.com/qinglee/wrapstuff/pulls) +are always welcome. + +Copyright and Licence +--------------------- + + Copyright (C) 2022 by Qing Lee <sobenlee@gmail.com> + ----------------------------------------------------------------- + + This work may be distributed and/or modified under the + conditions of the LaTeX Project Public License, either + version 1.3c of this license or (at your option) any later + version. This version of this license is in + http://www.latex-project.org/lppl/lppl-1-3c.txt + and the latest version of this license is in + http://www.latex-project.org/lppl.txt + and version 1.3 or later is part of all distributions of + LaTeX version 2005/12/01 or later. + + This work has the LPPL maintenance status "maintained". + + The Current Maintainer of this work is Qing Lee. + + This package consists of the file wrapstuff.dtx, + and the derived files wrapstuff.pdf, + wrapstuff.sty, + wrapstuff.ins and + README.md (this file). diff --git a/macros/latex/contrib/wrapstuff/wrapstuff.dtx b/macros/latex/contrib/wrapstuff/wrapstuff.dtx new file mode 100644 index 0000000000..5b8c03ec03 --- /dev/null +++ b/macros/latex/contrib/wrapstuff/wrapstuff.dtx @@ -0,0 +1,3011 @@ +% \iffalse meta-comment +% !TeX program = XeLaTeX +% !TeX encoding = UTF-8 +%<*internal> +\iffalse +%</internal> +%<*readme> +wrapstuff +========= + +The `wrapstuff` package provides another implementation of text wrapping. +Its implementation benefits from the paragraph hooks available since +LaTeX 2021-06-01. + +Basic Usage +----------- +The package only provides a user environment `wrapstuff`. + + \begin{wrapstuff}[<options>] + <wrapping stuff> + \end{wrapstuff} + <main text> + +You can read the package manual (in Chinese) for some explanations. + +Contributing +------------ +The package is still highly experimental and not fully tested. +[Issues](https://github.com/qinglee/wrapstuff/issues) and +[pull requests](https://github.com/qinglee/wrapstuff/pulls) +are always welcome. + +Copyright and Licence +--------------------- + + Copyright (C) 2022 by Qing Lee <sobenlee@gmail.com> + ----------------------------------------------------------------- + + This work may be distributed and/or modified under the + conditions of the LaTeX Project Public License, either + version 1.3c of this license or (at your option) any later + version. This version of this license is in + http://www.latex-project.org/lppl/lppl-1-3c.txt + and the latest version of this license is in + http://www.latex-project.org/lppl.txt + and version 1.3 or later is part of all distributions of + LaTeX version 2005/12/01 or later. + + This work has the LPPL maintenance status "maintained". + + The Current Maintainer of this work is Qing Lee. + + This package consists of the file wrapstuff.dtx, + and the derived files wrapstuff.pdf, + wrapstuff.sty, + wrapstuff.ins and + README.md (this file). +%</readme> +%<*internal> +\fi +\begingroup + \def\temp{LaTeX2e} +\expandafter\endgroup\ifx\temp\fmtname\else +\csname fi\endcsname +%</internal> +%<*install> + +\input ctxdocstrip % + +\preamble + + Copyright (C) 2022 by Qing Lee <sobenlee@gmail.com> +----------------------------------------------------------------- + + This work may be distributed and/or modified under the + conditions of the LaTeX Project Public License, either + version 1.3c of this license or (at your option) any later + version. This version of this license is in + http://www.latex-project.org/lppl/lppl-1-3c.txt + and the latest version of this license is in + http://www.latex-project.org/lppl.txt + and version 1.3 or later is part of all distributions of + LaTeX version 2005/12/01 or later. + + This work has the LPPL maintenance status "maintained". + + The Current Maintainer of this work is Qing Lee. + +----------------------------------------------------------------- + +\endpreamble + +\postamble + + This work consists of the file wrapstuff.dtx, + and the derived files wrapstuff.pdf, + wrapstuff.sty, + wrapstuff.ins and + README.md. +\endpostamble + +\generate + { +%</install> +%<*internal> + \usedir{source/latex/wrapstuff} + \file{wrapstuff.ins} {\from{\jobname.dtx}{install}} +%</internal> +%<*install> + \usedir{tex/latex/wrapstuff} + \file{wrapstuff.sty} {\from{\jobname.dtx}{package}} + \nopreamble\nopostamble + \usedir{doc/latex/wrapstuff} + \file{README.md} {\from{\jobname.dtx}{readme}} + } + +\endbatchfile +%</install> +%<*internal> +\fi +%</internal> +%<package>\NeedsTeXFormat{LaTeX2e} +%<package>\@ifundefined{ExplLoaderFileDate}{\RequirePackage{expl3}}{} +%<+package>\GetIdInfo$Id: wrapstuff.dtx 564fe9d 2022-07-20 19:55:58 +0800 Qing Lee <sobenlee@gmail.com> $ +%<package> {Wrapping text around stuff} +%<package>\ProvidesExplPackage{\ExplFileName} +%<package> {\ExplFileDate}{0.1}{\ExplFileDescription} +%<*driver> +\documentclass{ctxdoc} +\usepackage{wrapstuff} +\usepackage{graphicx} +\usepackage{zhlipsum} +\ExplSyntaxOn +\makeatletter +\DeclareDocumentCommand \gitsha { m } + { + \href { https \c_colon_str //github.com/qinglee/wrapstuff/commit/#1 } + { rev. ~ \texttt{#1} } + } +\DeclareDocumentCommand \QIANZIWEN { } + { + 天地玄黄宇宙洪荒日月盈昃辰宿列张 + 寒来暑往秋收冬藏闰馀成岁律召调阳 \par + 云腾致雨露结为霜金生丽水玉出昆冈 \par + } +\DeclareDocumentCommand \ADDSPECEIALKEY { m } + { + \cs_gset_eq:NN \@@_codedoc_names_typeset_save: + \__codedoc_names_typeset: + \cs_gset_protected:Npn \__codedoc_names_typeset: + { + \cs_gset_eq:NN \__codedoc_names_typeset: + \@@_codedoc_names_typeset_save: + \__codedoc_names_typeset: + #1 \\ + } + } +\DeclareDocumentCommand \IMAGE { m m } + { \includegraphics [ width = \dim_eval:n {#1} ] { example-image-#2.pdf } } +\tl_put_left:Nn \Example + { \trivlist \item \relax } +\tl_put_right:Nn \endExample + { \endtrivlist } +\SideBySideExampleSet { numbers = none } +\makeatother +\ExplSyntaxOff +\begin{document} + \DocInput{\jobname.dtx} + \IndexLayout + \PrintChanges + \PrintIndex +\end{document} +%</driver> +% \fi +% +% \CheckSum{2923} +% +% \changes{v0.1}{2022/07/05}{初始版本。} +% \changes{v0.1}{2022/07/20}{首次提交到 CTAN 发布。} +% +% \GetFileId{wrapstuff.sty} +% +% \title{\bfseries\pkg{wrapstuff} 宏包} +% \author{李清} +% \date{\filedate\qquad\fileversion\thanks{\gitsha{\ExplFileVersion}.}} +% \maketitle +% +% \begin{documentation} +% +% \section{基本用法} +% +% \pkg{wrapstuff} 宏包提供了图文绕排的另一种实现。 +% \pkg{wrapstuff} 的实现依赖 \LaTeX\ 2021-06-01 开始提供的段落钩子, +% 并依赖 \LaTeXiii\ 2022-04-10 之后的版本。 +% +% \begin{function}{wrapstuff} +% \begin{syntax} +% \tn{begin}\{wrapstuff\}\oarg{选项} +% <绕排内容> +% \tn{end}\{wrapstuff\} +% <正文> +% \end{syntax} +% \pkg{wrapstuff} 只提供了一个用户环境 \env{wrapstuff}, +% 会在环境之后的段落开始绕排。例如 +% \begin{Example}[frame=single,numbers=none,gobble=5] +% \begin{wrapstuff}[c,top=1] +% \includegraphics[width=\dimeval{\linewidth/3}]{example-image.pdf} +% \end{wrapstuff} +% \zhlipsum[1][name=zhufu] +% \end{Example} +% \end{function} +% +% \begin{function}{\wrapstuffset} +% \begin{syntax} +% \tn{wrapstuffset} \Arg{选项列表} +% \end{syntax} +% \pkg{wrapstuff} 的选项可以在调用宏包时设置,也可以通过 \tn{wrapstuffset} 设置。 +% 选项将在下面描述。 +% \end{function} +% +% \ADDSPECEIALKEY{\textrm{\meta{n}}} +% \begin{function}{top} +% \begin{syntax} +% top = <非负整数> +% \end{syntax} +% 设置在正文段落的第几行之后开始绕排,可以设置为非负整数。 +% 非负整数选项 \meta{n} 是设置选项 \opt{top} 为 \meta{n} 的缩写形式。 +% 初始值是 \num{0}。 +% \end{function} +% +% \begin{function}{width} +% \begin{syntax} +% width = <宽度> +% \end{syntax} +% 设置绕排内容的宽度,初始值为 \qty{0}{pt},代表自然宽度。 +% \end{function} +% +% \begin{function}{height} +% \begin{syntax} +% height = <高度> +% \end{syntax} +% 设置绕排内容的高度,初始值为 \qty{0}{pt},代表自然高度。 +% \end{function} +% +% \begin{function}{leftsep,rightsep,hsep} +% \begin{syntax} +% leftsep = <长度> +% rightsep = <长度> +% hsep = <长度> +% \end{syntax} +% 设置绕排内容与正文的左/右间距,选项 \opt{hsep} 同时设置 \opt{leftsep} 和 \opt{rightsep}。 +% 初始值是 \qty{1}{em}。 +% \end{function} +% +% \begin{function}{abovesep,belowsep,vsep} +% \begin{syntax} +% abovesep = <长度> +% belowsep = <长度> +% vsep = <长度> +% \end{syntax} +% 设置绕排内容与正文的上/下间距,选项 \opt{vsep} 同时设置 \opt{abovesep} 和 \opt{belowsep}。 +% 初始值是 \qty{0}{pt}。 +% \end{function} +% +% \begin{function}{l,r,c,i,o,ratio} +% \begin{syntax} +% l/r/c/i/o +% ratio = <实数> +% \end{syntax} +% 这些选项用于设置绕排内容位于正文中的位置。 +% 选项 \opt{l/r/c/i/o} 分别设置绕排内容位于正文的左侧、右侧、中间、内侧、外侧。 +% 选项 \opt{ratio} 设置绕排内容左侧的正文占据行宽的比例,可以设置为 $[0,1]$ 区间中的合理实数。 +% 选项 \opt{i/o} 可以与 \opt{ratio} 一起使用,这时设置的是内/外侧正文的行宽比例。 +% 初始设置为 |r|,即位于正文的右侧。 +% \end{function} +% +% \begin{function}{column} +% \begin{syntax} +% column = <(true)|false|par> +% \end{syntax} +% 控制是否将绕排内容两侧的正文分栏显示,只有设置 |c| 选项或者 +% 设置 \opt{ratio} 不等于 $0$ 或者 $1$ 时才有效。 +% \opt{false} 表示不分栏,正文文字方向始终保持从左到右的顺序; +% \opt{par} 表示以段落为单位进行分栏,如下示例。 +% \begin{SideBySideExample}[xrightmargin=\dimeval{20em+5mm}] +% \begin{wrapstuff}[c,1] +% \IMAGE{2em}{a} +% \end{wrapstuff} +% \QIANZIWEN +% \begin{wrapstuff}[c,1,column=par] +% \IMAGE{2em}{b} +% \end{wrapstuff} +% \QIANZIWEN +% \begin{wrapstuff}[c,0,column=false] +% \IMAGE{2em}{c} +% \end{wrapstuff} +% \QIANZIWEN +% \end{SideBySideExample} +% \end{function} +% +% \begin{function}{hoffset} +% \begin{syntax} +% hoffset = <长度> +% \end{syntax} +% 设置绕排内容伸出正文版心的长度。 +% 当设置了选项 \opt{c} 或者选项 \opt{ratio} 的值位于 $(0,1)$ 时,本选项无效。 +% 一个特殊值 \tn{width} 用于表示绕排内容和相应间距的总宽度, +% 可以将 \opt{hoffset} 设置为 \tn{width},完全伸出版心。 +% 初始值为 \qty{0}{pt}。 +% \end{function} +% +% \begin{function}{voffset} +% \begin{syntax} +% voffset = <长度> +% \end{syntax} +% 用于调整绕排内容的竖直位置,初始值为 \qty{0}{pt}。 +% \end{function} +% +% \begin{function}{type} +% \begin{syntax} +% type = <浮动体类型> +% \end{syntax} +% 设置绕排内容的浮动体类型,初始值为空。 +% 如果需要在 \env{wrapstuff} 环境中使用 \tn{caption} 命令, +% 则需要设置 \opt{type} 为 \opt{figure} 或 \opt{table} 等类型, +% 并需要同时设置 \opt{width} 指定宽度。 +% \begin{SideBySideExample}[xrightmargin=\dimeval{18em+5mm}] +% \begin{wrapstuff}[type=figure,width=5em] +% \centering +% \IMAGE{4em}{plain} +% \caption{示例} +% \end{wrapstuff} +% \QIANZIWEN +% \end{SideBySideExample} +% \end{function} +% +% \begin{function}{lines} +% \begin{syntax} +% lines = <正整数> +% \end{syntax} +% 设置绕排内容占据正文的行数,可以设置正整数。 +% 初始值为空,根据绕排内容的高度自动计算行数。 +% \end{function} +% +% \begin{function}{linewidth} +% \begin{syntax} +% linewidth = <宽度> +% \end{syntax} +% 设置正文段落的行宽,初始设置为 |\linewidth|,一般不需要调整。 +% \end{function} +% +% \begin{function}{\wrapstuffclear} +% 如果当前正文段落的行数不够,\pkg{wrapstuff} 的作用会延续到下一段。 +% 这可能会导致某些意外结果,可以在下一段之前启用命令 \tn{wrapstuffclear} 消除影响。 +% \end{function} +% +% \end{documentation} +% +% +% \StopEventually{} +% +% +%\begin{implementation} +% +% \section{代码实现} +% +% \begin{macrocode} +%<*package> +% \end{macrocode} +% +% \begin{macrocode} +%<@@=wstf> +% \end{macrocode} +% +% \pkg{wrapstuff} 的实现依赖 \LaTeX\ 2021-06-01 开始提供的段落钩子。 +% \begin{macrocode} +\@ifl@t@r \fmtversion { 2021-06-01 } + { } + { + \msg_new:nnn { wrapstuff } { latex-too-old } + { + You~need~to~update~your~LaTeX~to~the~latest~release. \\ + Loading~wrapstuff~will~abort! + } + \msg_critical:nn { wrapstuff } { latex-too-old } + } +% \end{macrocode} +% +% 由于使用了 \cs{keys_precompile:nnN},需要比较新的 \LaTeXiii。 +% \begin{macrocode} +\@ifl@t@r \ExplLoaderFileDate { 2022-04-10 } + { } + { + \msg_new:nnn { wrapstuff } { latex3-too-old } + { + You~need~to~update~your~installation~of~the~bundles~ + "l3kernel"~and~"l3packages". \\ + Loading~wrapstuff~will~abort! + } + \msg_critical:nn { wrapstuff } { latex3-too-old } + } +% \end{macrocode} +% +% \begin{macrocode} +\prop_gput:Nnn \g_msg_module_name_prop { wstf } { wrapstuff } +% \end{macrocode} +% +% \begin{macro}[TF]{ +% \@@_if_last_none:, +% \@@_if_last_hlist:, +% \@@_if_last_whatsit:, +% \@@_if_last_glue:, +% \@@_if_last_kern:, +% \@@_if_last_penalty:} +% 一些 \hologo{eTeX} 结点判定函数。 +% \begin{macrocode} +\group_begin: +\cs_set:Npn \@@_tmp:nn #1 + { + \group_begin: + \exp_args:Ncc \@@_tmp_aux:NNn + { @@_if_last_ #1 : } + { c_@@_ #1 _node } + } +\cs_set:Npn \@@_tmp_aux:NNn #1#2#3 + { + \group_end: + \int_const:Nn #2 {#3} + \prg_new_conditional:Npnn #1 { T , F , TF } + { + \if_int_compare:w \tex_lastnodetype:D = #2 + \prg_return_true: \else: \prg_return_false: \fi: + } + } +\@@_tmp:nn { none } { -1 } +\@@_tmp:nn { hlist } { 1 } +\@@_tmp:nn { whatsit } { 9 } +\@@_tmp:nn { glue } { 11 } +\@@_tmp:nn { kern } { 12 } +\@@_tmp:nn { penalty } { 13 } +\group_end: +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_gadd_hook:nn, \@@_package_hook:nn} +% \begin{macrocode} +\cs_new_protected:Npn \@@_gadd_hook:nn #1 + { \hook_gput_code:nnn {#1} { wrapstuff } } +\cs_new_protected:Npn \@@_package_hook:nn #1 + { \hook_gput_code:nnn { package/#1/after } { wrapstuff } } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{wrapstuff} +% 主要功能环境接口。 +% \begin{macrocode} +\NewDocumentEnvironment { wrapstuff } { O { } } + { + \@@_clear: + \int_set:Nn \l_@@_top_int { -1 } + \tl_if_blank:nTF {#1} + { \tl_clear:N \l_@@_main_kv_tl } + { + \keys_set_filter:nnnN { wrapstuff } + { main , ratio } + {#1} \l_@@_main_kv_tl + } + \tl_set:Nx \l_@@_type_tl { \l_@@_type_tl } + \dim_set:Nn \l_@@_width_dim { \l_@@_width_tl } + \dim_set:Nn \l_@@_height_dim { \l_@@_height_tl } + \hbox_gset:Nw \g_@@_stuff_box + \dim_compare:nNnTF \l_@@_width_dim > \c_zero_dim + { \@@_minipage_begin: } + { \@@_hbox_begin: } + } + { + \dim_compare:nNnTF \l_@@_width_dim > \c_zero_dim + { \@@_minipage_end: } + { \@@_hbox_end: } + \@@_set_vsep: + \@@_attach_label: + \tl_if_empty:NTF \l_@@_main_kv_tl + { \tl_gclear:N \g_@@_main_setting_tl } + { \@@_save_main_setting: } + \@@_set_top_line: + \dim_gset:Nn \g_@@_stuff_wd_dim + { \box_wd:N \g_@@_stuff_box } + \dim_gset:Nn \g_@@_stuff_ht_dim + { \box_ht_plus_dp:N \g_@@_stuff_box } + \dim_gset_eq:NN + \g_@@_remaining_dim + \g_@@_stuff_ht_dim + \@@_next_para: + } +\@@_gadd_hook:nn { env/wrapstuff/before } { \par } +\cs_new_protected_nopar:Npn \@@_minipage_begin: + { + \@@_floatrow_hook: + \dim_compare:nNnTF \l_@@_height_dim > \c_zero_dim + { \begin { minipage } [b] [ \l_@@_height_dim ] [c] { \l_@@_width_dim } } + { \begin { minipage } [b] { \l_@@_width_dim } } + \tl_if_empty:NF \l_@@_type_tl + { \@@_set_float: } + } +\cs_new_protected_nopar:Npn \@@_minipage_end: + { + \end { minipage } + \hbox_gset_end: + \@@_float_pos_hook: + } +\cs_new_protected_nopar:Npn \@@_hbox_begin: + { \tex_ignorespaces:D } +\cs_new_protected_nopar:Npn \@@_hbox_end: + { + \tex_unskip:D + \hbox_gset_end: + \dim_compare:nNnT \l_@@_height_dim > \c_zero_dim + { \@@_gset_height: } + } +\cs_new_protected_nopar:Npn \@@_gset_height: + { + \hbox_gset:Nn \g_@@_stuff_box + { + \box_move_up:nn + { + ( \l_@@_height_dim + - \box_ht:N \g_@@_stuff_box + + \box_dp:N \g_@@_stuff_box + ) / 2 + } + { \box_use_drop:N \g_@@_stuff_box } + } + \box_gset_ht:Nn \g_@@_stuff_box { \l_@@_height_dim } + \box_gset_dp:Nn \g_@@_stuff_box { \c_zero_dim } + } +\cs_new_protected_nopar:Npn \@@_set_vsep: + { + \@@_gadd_ht:Nn \g_@@_stuff_box { \l_@@_abovesep_tl } + \dim_set:Nn \l_@@_shift_dim { \l_@@_belowsep_tl } + \dim_compare:nNnF \l_@@_shift_dim = \c_zero_dim + { \@@_set_belowsep: } + } +\cs_new_protected_nopar:Npn \@@_set_belowsep: + { + \hbox_gset:Nn \g_@@_stuff_box + { + \box_move_up:nn + { \l_@@_shift_dim + \box_dp:N \g_@@_stuff_box } + { \box_use_drop:N \g_@@_stuff_box } + } + \box_gset_dp:Nn \g_@@_stuff_box { \c_zero_dim } + } +\tl_new:N \l_@@_main_kv_tl +\tl_new:N \g_@@_main_setting_tl +\box_new:N \g_@@_stuff_box +\dim_new:N \g_@@_stuff_ht_dim +\dim_new:N \g_@@_stuff_wd_dim +\dim_new:N \l_@@_shift_dim +\dim_new:N \l_@@_width_dim +\dim_new:N \l_@@_height_dim +\dim_new:N \g_@@_prevdepth_dim +\dim_new:N \g_@@_remaining_dim +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_attach_label:, \@@_write_label:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_attach_label: + { + \stepcounter { wrapstuff } + \hbox_gset:Nn \g_@@_stuff_box + { + \@@_write_label: + \box_use_drop:N \g_@@_stuff_box + } + } +\cs_new_protected_nopar:Npn \@@_write_label: + { + \iow_shipout_x:Nx \@auxout + { + \c_backslash_str wrapstuff@label + { \@@_counter:n { wrapstuff } } + { \exp_not:N \wrapstuff@counter { page } } + } + } +\cs_new:Npn \@@_counter:n #1 + { \int_value:w \value {#1} } +\cs_new_eq:NN \wrapstuff@counter \@@_counter:n +\cs_new_protected_nopar:Npn \wrapstuff@label + { \@newl@bel { wrapstuff@label } } +\tl_const:Nn \c_@@_label_tl + { wrapstuff@label@ \int_value:w \value { wrapstuff } } +\@@_gadd_hook:nn { begindocument } + { + \legacy_if:nTF { @filesw } + { + \iow_now:Nx \@mainaux + { + \c_backslash_str providecommand + \c_backslash_str wrapstuff@label [2] { } + } + } + { \cs_gset_eq:NN \@@_write_label: \@@_empty: } + } +\newcounter { wrapstuff } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_save_main_setting:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_save_main_setting: + { + \exp_args:Nnno + \keys_set_filter:nnnN { wrapstuff } + { main } + { \l_@@_main_kv_tl } \l_@@_main_kv_tl + \bool_if:NTF \l_@@_swap_bool + { \@@_swap_ratio: } + { \@@_set_ratio:N \l_@@_ratio_fp } + \tl_if_empty:NF \l_@@_main_kv_tl + { \@@_save_main_setting_aux: } + } +\cs_new_protected:Npn \@@_set_ratio:N #1 + { + \tl_gset:Nx \g_@@_main_setting_tl + { \fp_set:Nn \exp_not:N \l_@@_ratio_fp { \fp_use:N #1 } } + } +\cs_new_protected:Npn \@@_set_ratio:n #1 + { + \tl_gset:Nx \g_@@_main_setting_tl + { \fp_set:Nn \exp_not:N \l_@@_ratio_fp { \fp_eval:n {#1} } } + } +\cs_new_protected_nopar:Npn \@@_save_main_setting_aux: + { + \exp_args:Nno + \keys_precompile:nnN + { wrapstuff } + { \l_@@_main_kv_tl } \l_@@_main_kv_tl + \tl_gconcat:NNN \g_@@_main_setting_tl + \g_@@_main_setting_tl \l_@@_main_kv_tl + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_set_top_line:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_set_top_line: + { + \int_compare:nNnF \l_@@_top_int < \c_zero_int + { + \tl_gput_right:Nx \g_@@_main_setting_tl + { + \int_set:Nn \l_@@_top_int + { \int_use:N \l_@@_top_int } + } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_swap_ratio:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_swap_ratio: + { + \fp_compare:nF + { \c_zero_fp < \l_@@_ratio_fp < \c_one_fp } + { \fp_zero:N \l_@@_ratio_fp } + \int_if_odd:nTF + { + \exp_args:Ne \cs_if_exist_use:cF + { \c_@@_label_tl } + { \@@_counter:n { page } } + } + { \bool_if:NTF \l_@@_inner_bool } + { \bool_if:NTF \l_@@_outer_bool } + { \@@_set_ratio:N \l_@@_ratio_fp } + { \@@_set_ratio:n { \c_one_fp - \l_@@_ratio_fp } } + } +\bool_new:N \l_@@_swap_bool +\bool_new:N \l_@@_inner_bool +\bool_new:N \l_@@_outer_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_gadd_ht:Nn,\@@_gsub_ht:Nn} +% \begin{macrocode} +\cs_new_protected:Npn \@@_gadd_ht:Nn #1#2 + { \box_gset_ht:Nn #1 { \box_ht:N #1 + \dim_eval:n {#2} } } +\cs_new_protected:Npn \@@_gsub_ht:Nn #1#2 + { \box_gset_ht:Nn #1 { \box_ht:N #1 - \dim_eval:n {#2} } } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_clear:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_clear: + { + \@@_clear_para_hook: + \@@_clear_kludge: + \@@_clear_variable: + } +\cs_new_protected_nopar:Npn \@@_clear_variable: + { + \int_gset:Nn \g_@@_top_int { -1 } + \int_gzero:N \g_@@_window_int + \dim_gzero:N \g_@@_total_ht_dim + \dim_gzero:N \g_@@_column_left_dim + \tl_gclear:N \g_@@_main_setting_tl + \bool_gset_false:N \g_@@_next_bool + \bool_gset_false:N \g_@@_hoffset_bool + \bool_gset_false:N \g_@@_next_hang_bool + \bool_gset_false:N \g_@@_first_save_bool + \bool_gset_false:N \g_@@_right_move_bool + \bool_gset_false:N \g_@@_column_right_bool + } +\cs_new_protected_nopar:Npn \@@_clear_kludge: + { + \bool_if:NTF \g_@@_next_bool + { + \box_gclear:N \g_@@_stuff_box + \skip_vertical:n + { \tex_baselineskip:D * \g_@@_window_int } + } + { + \box_if_empty:NF \g_@@_stuff_box + { \@@_clear_stuff_box: } + } + } +\cs_new_protected_nopar:Npn \@@_clear_stuff_box: + { + \@@_ignore_depth: + \skip_set:Nn \l_@@_last_skip + { \box_dp:N \strutbox } + \skip_vertical:N \l_@@_last_skip + \box_use_drop:N \g_@@_stuff_box + \skip_vertical:N \l_@@_last_skip + \@@_ignore_depth: + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_next_para:} +% 将 \env{wrapstuff} 环境之后的段落放入内部环境 \env{wrapstuff@par} 中。 +% 为了控制钩子执行顺序,需要使用 |wrapstuff| 标签, +% 而不用更为方便的 \cs{hook_gput_next_code:nn} 实现。 +% \begin{macrocode} +\@@_gadd_hook:nn { para/before } { \@@_para_before: } +\@@_gadd_hook:nn { para/begin } { \@@_para_begin: } +\@@_gadd_hook:nn { para/end } { \@@_para_end: } +\cs_new_protected_nopar:Npn \@@_next_para: + { + \cs_gset_eq:NN \@@_para_before: \@@_env_before: + \cs_gset_eq:NN \@@_para_begin: \@@_env_begin: + \cs_gset_eq:NN \@@_para_end: \@@_env_end: + } +\cs_new_protected_nopar:Npn \@@_env_before: + { \dim_gset_eq:NN \g_@@_prevdepth_dim \tex_prevdepth:D } +\cs_new_protected_nopar:Npn \@@_env_begin: + { \begin { wrapstuff@par } } +\cs_new_protected_nopar:Npn \@@_env_end: + { \end { wrapstuff@par } } +\cs_new_protected_nopar:Npn \@@_clear_para_hook: + { + \cs_gset_eq:NN \@@_para_before: \@@_empty: + \cs_gset_eq:NN \@@_para_begin: \@@_empty: + \cs_gset_eq:NN \@@_para_end: \@@_empty: + } +\cs_new_protected_nopar:Npn \@@_empty: + { } +\cs_new_eq:NN \@@_para_before: \@@_empty: +\cs_new_eq:NN \@@_para_begin: \@@_empty: +\cs_new_eq:NN \@@_para_end: \@@_empty: +% \end{macrocode} +% \end{macro} +% +% \begin{macro}[int]{wrapstuff@par} +% 内部环境,实现主要功能。 +% \begin{macrocode} +\NewDocumentEnvironment { wrapstuff@par } { } + { + \tl_use:N \g_@@_main_setting_tl + \dim_set:Nn \l_@@_leftsep_dim { \l_@@_leftsep_tl } + \dim_set:Nn \l_@@_rightsep_dim { \l_@@_rightsep_tl } + \dim_set:Nn \l_@@_voffset_dim { \l_@@_voffset_tl } + \dim_set:Nn \l_@@_line_dim { \l_@@_linewidth_tl } + \dim_set:Nn \l_@@_min_dim { \box_dp:N \strutbox } + \dim_set_eq:NN \l_@@_main_width_dim \l_@@_line_dim + \dim_sub:Nn \l_@@_line_dim + { \tex_leftskip:D + \tex_rightskip:D } + \dim_set:Nn \l_@@_window_dim + { \l_@@_line_dim - \g_@@_stuff_wd_dim } + \fp_compare:nNnTF \l_@@_ratio_fp > \c_zero_fp + { + \fp_compare:nNnTF \l_@@_ratio_fp < \c_one_fp + { \@@_set_window: } + { \@@_set_hang_right: } + } + { \@@_set_hang_left: } + \int_compare:nNnTF \g_@@_window_int > \c_zero_int + { + \int_set_eq:NN \l_@@_window_int \g_@@_window_int + \int_zero:N \l_@@_top_int + } + { \@@_set_lines: } + \bool_if:NTF \l_@@_hang_bool + { + \dim_set_eq:NN \l_@@_display_dim \l_@@_window_dim + \int_set_eq:NN \l_@@_window_line_int \l_@@_window_int + } + { + \dim_set_eq:NN \l_@@_display_dim \l_@@_l_dim + \int_set:Nn \l_@@_window_int { \l_@@_window_int * 2 } + \int_set:Nn \l_@@_window_line_int + { + \bool_if:NTF \g_@@_column_right_bool + { \l_@@_window_int / 2 + \g_@@_column_window_int } + { \l_@@_window_int } + } + } + \cs_gset_eq:NN \@@_para_before: \@@_empty: + \cs_gset_eq:NN \@@_para_begin: \@@_empty: + \@@_save_parshape: + \vbox_set:Nw \l_@@_body_box + \@@_set_prevdepth:N \g_@@_prevdepth_dim + \@@_save_tex_skip: + \@@_tex_parameter: + \@@_restore_parshape: + \@@_display_parameter: + \@@_make_main_parshape: + \para_raw_noindent: + } + { + \@@_save_hangfrom: + \@@_save_tex_skip: + \@@_group_kludge: + \@@_tex_parameter: + \@@_make_main_parshape: + \para_raw_end: + \int_gset_eq:NN \g_@@_line_int \tex_prevgraf:D + \vbox_set_end: + \@@_adjust_tex_skip: + \cs_gset_eq:NN \@@_para_end: \@@_empty: + \int_compare:nNnTF \g_@@_line_int > \l_@@_top_int + { \@@_build_par: } + { \@@_put_par: } + } +\box_new:N \l_@@_body_box +\box_new:N \l_@@_window_box +\int_new:N \l_@@_window_int +\int_new:N \g_@@_window_int +\int_new:N \g_@@_line_int +\int_new:N \l_@@_window_line_int +\int_new:N \g_@@_column_window_int +\dim_new:N \l_@@_l_dim +\dim_new:N \l_@@_r_dim +\dim_new:N \l_@@_min_dim +\dim_new:N \l_@@_line_dim +\dim_new:N \l_@@_window_dim +\dim_new:N \l_@@_display_dim +\dim_new:N \l_@@_voffset_dim +\dim_new:N \l_@@_leftsep_dim +\dim_new:N \l_@@_rightsep_dim +\dim_new:N \g_@@_window_ht_dim +\dim_new:N \l_@@_main_width_dim +\int_new:N \g_@@_top_int +\int_gdecr:N \g_@@_top_int +\bool_new:N \l_@@_hang_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_set_hang_left:, \@@_set_hang_right:, \@@_set_window:,} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_set_hang_left: + { + \bool_set_true:N \l_@@_hang_bool + \bool_if:NF \g_@@_hoffset_bool + { \@@_set_hoffset:NN \l_@@_rightsep_dim \use:nn } + \dim_sub:Nn \l_@@_window_dim { \l_@@_rightsep_dim } + \dim_zero:N \l_@@_l_dim + \dim_set_eq:NN \l_@@_r_dim \l_@@_window_dim + \cs_set_eq:NN \@@_build_box: \@@_build_hang: + } +\cs_new_protected_nopar:Npn \@@_set_hang_right: + { + \bool_set_true:N \l_@@_hang_bool + \bool_if:NF \g_@@_hoffset_bool + { \@@_set_hoffset:NN \l_@@_leftsep_dim \use_ii_i:nn } + \dim_sub:Nn \l_@@_window_dim { \l_@@_leftsep_dim } + \dim_zero:N \l_@@_r_dim + \dim_set_eq:NN \l_@@_l_dim \l_@@_window_dim + \cs_set_eq:NN \@@_build_box: \@@_build_hang: + } +\cs_new_protected_nopar:Npn \@@_set_window: + { + \bool_set_false:N \l_@@_hang_bool + \dim_sub:Nn \l_@@_window_dim + { \l_@@_leftsep_dim + \l_@@_rightsep_dim } + \dim_set:Nn \l_@@_l_dim + { \@@_ratio:Nn \l_@@_ratio_fp { \l_@@_window_dim } } + \dim_set:Nn \l_@@_r_dim + { \l_@@_window_dim - \l_@@_l_dim } + \bool_if:NTF \l_@@_column_bool + { \cs_set_eq:NN \@@_build_box: \@@_build_column: } + { \cs_set_eq:NN \@@_build_box: \@@_build_block: } + } +\cs_new_protected:Npn \@@_set_hoffset:NN #1#2 + { + \bool_gset_true:N \g_@@_hoffset_bool + \dim_set:Nn \l_@@_hoffset_width_dim + { #1 + \g_@@_stuff_wd_dim } + \group_begin: + \cs_set_eq:NN \width \l_@@_hoffset_width_dim + \dim_gset:Nn \g_@@_hoffset_dim { \l_@@_hoffset_tl } + \group_end: + \int_compare:nNnF \g_@@_hoffset_dim = \c_zero_dim + { + \hbox_gset:Nn \g_@@_stuff_box + { + #2 { \tex_kern:D - \g_@@_hoffset_dim } + { \box_use_drop:N \g_@@_stuff_box } + } + \dim_add:Nn \l_@@_window_dim { \g_@@_hoffset_dim } + } + } +\dim_new:N \g_@@_hoffset_dim +\dim_new:N \l_@@_hoffset_width_dim +\bool_new:N \g_@@_hoffset_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_set_lines:, \@@_window_init:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_set_lines: + { + \bool_if:NTF \g_@@_next_bool + { \tl_clear:N \l_@@_lines_tl } + { \tl_set:Nx \l_@@_lines_tl { \l_@@_lines_tl } } + \int_set:Nn \l_@@_window_int + { + \tl_if_empty:NTF \l_@@_lines_tl + { \@@_unit:n { \g_@@_remaining_dim + \l_@@_min_dim } } + { \l_@@_lines_tl } + } + \bool_if:NF \g_@@_next_bool + { \@@_window_init: } + \int_compare:nNnTF \g_@@_top_int < \c_zero_int + { + \int_compare:nNnT \l_@@_top_int < \c_zero_int + { \int_zero:N \l_@@_top_int } + } + { \int_set_eq:NN \l_@@_top_int \g_@@_top_int } + } +\cs_new_protected_nopar:Npn \@@_window_init: + { + \int_gset_eq:NN \g_@@_column_window_int \l_@@_window_int + \dim_gset:Nn \g_@@_window_ht_dim + { \tex_baselineskip:D * \g_@@_column_window_int } + \tl_if_empty:NF \l_@@_lines_tl + { + \dim_gset:Nn \g_@@_remaining_dim + { \g_@@_window_ht_dim - \box_ht:N \strutbox } + \dim_gset_eq:NN \g_@@_stuff_ht_dim \g_@@_remaining_dim + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_make_main_parshape:} +% 主要处理用于标题悬挂的 \tn{@hangfrom} 和用于列表环境的 \tn{parshape}。 +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_make_main_parshape: + { + \dim_compare:nNnTF \g_@@_hangindent_dim > \c_zero_dim + { + \int_compare:nNnTF \g_@@_hangafter_int = \c_one_int + { \@@_make_hangfrom: } + { \@@_make_main_parshape_aux: } + } + { \@@_make_main_parshape_aux: } + } +\cs_new_protected_nopar:Npn \@@_make_main_parshape_aux: + { + \bool_gset_false:N \g_@@_hangfrom_bool + \tex_parshape:D + \int_eval:n { \l_@@_top_int + 1 } ~ + \prg_replicate:nn + { \l_@@_top_int } + { \g_@@_parshape_indent_dim \g_@@_parshape_length_dim } + \c_zero_dim \c_max_dim + } +\cs_new_protected_nopar:Npn \@@_save_parshape: + { + \int_gset_eq:NN \g_@@_parshape_int \tex_parshape:D + \int_compare:nNnTF \g_@@_parshape_int = \c_one_int + { + \dim_gset:Nn \g_@@_parshape_indent_dim + { \tex_parshapeindent:D \c_one_int } + \dim_gset:Nn \g_@@_parshape_length_dim + { \tex_parshapelength:D \c_one_int } + } + { + \int_gzero:N \g_@@_parshape_int + \dim_gzero:N \g_@@_parshape_indent_dim + \dim_gset_eq:NN \g_@@_parshape_length_dim \l_@@_main_width_dim + \int_gset_eq:NN \g_@@_hangafter_int \tex_hangafter:D + \dim_gset_eq:NN \g_@@_hangindent_dim \tex_hangindent:D + } + } +\cs_new_protected_nopar:Npn \@@_restore_parshape: + { + \int_compare:nNnTF \g_@@_parshape_int = \c_one_int + { + \tex_parshape:D \g_@@_parshape_int + \g_@@_parshape_indent_dim \g_@@_parshape_length_dim + } + { \@@_restore_hangfrom: } + } +\cs_new_protected_nopar:Npn \@@_parshape_kern: + { + \dim_compare:nNnT \l_@@_l_dim = \c_zero_dim + { + \dim_compare:nNnF \g_@@_parshape_indent_dim = \c_zero_dim + { \tex_kern:D - \g_@@_parshape_indent_dim } + } + } +\cs_new_protected_nopar:Npn \@@_make_hangfrom: + { + \bool_if:NTF \l_@@_hang_bool + { \@@_make_hangfrom_aux: } + { \@@_make_main_parshape_aux: } + } +\cs_new_protected_nopar:Npn \@@_make_hangfrom_aux: + { + \@@_restore_hangfrom: + \int_zero:N \tex_parshape:D + \bool_gset_true:N \g_@@_hangfrom_bool + \dim_set_eq:NN \tex_hsize:D \l_@@_window_dim + } +\cs_new_protected_nopar:Npn \@@_save_hangfrom: + { + \int_gset_eq:NN \g_@@_hangafter_int \tex_hangafter:D + \dim_gset_eq:NN \g_@@_hangindent_dim \tex_hangindent:D + } +\cs_new_protected_nopar:Npn \@@_restore_hangfrom: + { + \int_set_eq:NN \tex_hangafter:D \g_@@_hangafter_int + \dim_set_eq:NN \tex_hangindent:D \g_@@_hangindent_dim + } +\bool_new:N \g_@@_hangfrom_bool +\int_new:N \g_@@_parshape_int +\int_new:N \g_@@_hangafter_int +\dim_new:N \g_@@_hangindent_dim +\dim_new:N \g_@@_parshape_indent_dim +\dim_new:N \g_@@_parshape_length_dim +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_group_kludge:} +% \LaTeX\ 的 \tn{list} 环境中,为了保持 \tn{parshape},\tn{par} 被重定义为 |{\@@par}|。 +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_group_kludge: + { + \scan_stop: + \int_compare:nNnTF \tex_currentgrouptype:D = \c_one_int + { + \c_group_end_token + \cs_gset_eq:NN \@@_group_begin: \c_group_begin_token + } + { \cs_gset_eq:NN \@@_group_begin: \@@_empty: } + \legacy_if:nTF { @noitemarg } + { \cs_gset_eq:NN \@@_set_itemarg: \@noitemargtrue } + { \cs_gset_eq:NN \@@_set_itemarg: \@@_empty: } + } +\cs_new_eq:NN \@@_set_itemarg: \@@_empty: +\cs_new_eq:NN \@@_group_begin: \@@_empty: +\@@_gadd_hook:nn { env/wrapstuff@par/after } + { + \@@_set_itemarg: + \@@_group_begin: + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_ratio:Nn, \@@_unit:n} +% \begin{macrocode} +\cs_new:Npn \@@_ratio:Nn #1#2 + { \fp_to_dim:n { #1 \dim_to_fp:n {#2} } } +\cs_new:Npn \@@_unit:n #1 + { + \fp_eval:n + { + ceil + ( + \dim_to_decimal_in_unit:nn + {#1} + { \tex_baselineskip:D } + ) + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_save_tex_skip:,\@@_tex_parameter:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_save_tex_skip: + { + \skip_gset_eq:NN \g_@@_left_skip \tex_leftskip:D + \skip_gset_eq:NN \g_@@_right_skip \tex_rightskip:D + \skip_gset_eq:NN \g_@@_parfill_skip \tex_parfillskip:D + \skip_gset_eq:NN \g_@@_baseline_skip \tex_baselineskip:D + \skip_gset:Nn \g_@@_main_left_skip { - \tex_leftskip:D } + } +\cs_new_protected_nopar:Npn \@@_adjust_tex_skip: + { + \@@_adjust_skip:N \g_@@_left_skip + \@@_adjust_skip:N \g_@@_right_skip + \@@_adjust_skip:N \g_@@_parfill_skip + } +\cs_new_protected:Npn \@@_adjust_skip:N #1 + { \skip_gsub:Nn #1 { \dim_eval:n {#1} } } +\cs_new_protected_nopar:Npn \@@_tex_parameter: + { + \int_zero:N \tex_clubpenalty:D + \int_zero:N \tex_widowpenalty:D + \int_zero:N \tex_interlinepenalty:D + \int_zero:N \tex_displaywidowpenalty:D + \int_zero:N \tex_clubpenalties:D + \int_zero:N \tex_widowpenalties:D + \int_zero:N \tex_interlinepenalties:D + \int_zero:N \tex_displaywidowpenalties:D + \skip_set_eq:NN \tex_leftskip:D \g_@@_left_skip + \skip_set_eq:NN \tex_rightskip:D \g_@@_right_skip + \skip_set_eq:NN \tex_parfillskip:D \g_@@_parfill_skip + } +\skip_new:N \g_@@_left_skip +\skip_new:N \g_@@_right_skip +\skip_new:N \g_@@_parfill_skip +\skip_new:N \g_@@_baseline_skip +\skip_new:N \g_@@_main_left_skip +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_display_parameter:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_display_parameter: + { + \bool_gset_false:N \g_@@_display_bool + \tex_everydisplay:D \exp_after:wN + { + \tex_the:D \tex_everydisplay:D + \@@_test_leqno: + \dim_compare:nNnF \tex_displaywidth:D < \c_max_dim + { + \bool_gset_true:N \g_@@_display_bool + \dim_set_eq:NN \tex_displaywidth:D \l_@@_display_dim + } + } + } +\cs_new_eq:NN \@@_test_leqno: \@@_empty: +\bool_new:N \g_@@_display_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_par:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_par: + { + \bool_if:NTF \g_@@_hangfrom_bool + { \@@_build_box: } + { \@@_build_par_aux: } + \box_if_empty:NTF \l_@@_window_box + { \@@_put_next_par: } + { \@@_put_box: } + } +\cs_new_protected_nopar:Npn \@@_build_par_aux: + { + \@@_extract_display_hbox:NN \l_@@_body_box \l_@@_bottom_box + \int_compare:nNnT \l_@@_top_int > \c_zero_int + { \@@_put_body_box: } + \box_if_empty:NTF \l_@@_bottom_box + { + \box_if_empty:NF \g_@@_display_box + { \@@_build_display_box: } + } + { \@@_build_body_box: } + } +\box_new:N \l_@@_bottom_box +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_put_par:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_put_par: + { + \int_gset:Nn \g_@@_top_int + { \l_@@_top_int - \g_@@_line_int } + \int_gzero:N \g_@@_window_int + \@@_put_body_box: + \skip_zero:N \tex_parskip:D + \para_raw_noindent: + \@@_next_para: + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_put_body_box:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_put_body_box: + { + \para_raw_end: + \dim_compare:nNnTF { \box_wd:N \l_@@_body_box } < \c_max_dim + { \@@_put_body_aux:N \l_@@_body_box } + { + \@@_extract_hbox:NN \l_@@_body_box \l_@@_bottom_box + \@@_put_body_aux:N \l_@@_body_box + \box_set_eq_drop:NN \l_@@_body_box \l_@@_bottom_box + } + \para_raw_end: + } +\cs_new_protected_nopar:Npn \@@_put_body_aux:N #1 + { + \dim_gset:Nn \g_@@_prevdepth_dim { \box_dp:N #1 } + \vbox_unpack_drop:N #1 + \@@_set_prevdepth:N \g_@@_prevdepth_dim + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_put_next_par:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_put_next_par: + { + \int_gzero:N \g_@@_top_int + \int_gzero:N \g_@@_window_int + \skip_zero:N \tex_parskip:D + \para_raw_noindent: + \@@_next_para: + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_display_box:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_display_box: + { + \bool_set_true:N \l_@@_display_bool + \bool_if:NTF \g_@@_amsmath_bool + { \@@_build_display_amsmath: } + { \@@_build_display_normal: } + \box_if_empty:NTF \l_@@_body_box + { \@@_build_display_auxi: } + { \@@_build_display_auxii: } + } +\cs_new_protected_nopar:Npn \@@_build_display_amsmath: + { + \vbox_gset:Nn \g_@@_equation_box + { + \skip_vertical:n { - \g_@@_display_pre_skip } + \vbox_unpack_drop:N \g_@@_display_box + \skip_gset_eq:NN \g_@@_pos_skip \tex_lastskip:D + \tex_unskip:D + \int_gset_eq:NN \g_@@_pos_int \tex_lastpenalty:D + \tex_unpenalty:D + \skip_gadd:Nn \g_@@_pos_skip { \tex_lastskip:D } + \tex_unskip:D + \tex_unpenalty:D + } + \box_gset_wd:Nn \g_@@_equation_box + { \l_@@_display_dim } + \vbox_gset:Nn \g_@@_display_box + { + \tex_penalty:D \g_@@_display_pre_int + \skip_vertical:N \g_@@_display_pre_skip + } + \skip_gset_eq:NN \g_@@_pre_skip \g_@@_display_pre_skip + } +\cs_new_protected_nopar:Npn \@@_build_display_normal: + { + \vbox_gset:Nn \g_@@_display_box + { + \vbox_unpack_drop:N \g_@@_display_box + \skip_gset_eq:NN \g_@@_pos_skip \tex_lastskip:D + \tex_unskip:D + \int_gset_eq:NN \g_@@_pos_int \tex_lastpenalty:D + \tex_unpenalty:D + \box_gset_to_last:N \g_@@_equation_box + \skip_gset_eq:NN \g_@@_pre_skip \tex_lastskip:D + \tex_unskip:D + \skip_gadd:Nn \g_@@_pre_skip { \tex_lastskip:D } + \tex_unskip:D + \skip_vertical:N \g_@@_pre_skip + } + } +\cs_new_protected_nopar:Npn \@@_build_display_auxi: + { + \bool_if:NTF \g_@@_amsmath_bool + { \box_set_eq_drop:NN \l_@@_window_box \g_@@_equation_box } + { + \hbox_set_to_wd:Nnn \l_@@_window_box + { \l_@@_display_dim } + { + \tex_hss:D + \@@_adjust_equation: + \box_use_drop:N \g_@@_equation_box + \tex_hss:D + } + } + \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_window_box } + \dim_add:Nn \l_@@_voffset_dim + { \box_ht:N \g_@@_display_box / 2 } + } +\cs_new_protected_nopar:Npn \@@_build_display_auxii: + { + \box_if_horizontal:NTF \l_@@_body_box + { + \box_set_eq:NN \l_@@_bottom_box \l_@@_body_box + \@@_build_display_auxiii: + } + { + \@@_extract_hbox:NN \l_@@_body_box \l_@@_bottom_box + \str_if_eq:eeTF + { + \dim_eval:n { \box_ht:N \l_@@_body_box } + \dim_eval:n { \box_dp:N \l_@@_body_box } + \dim_eval:n { \box_ht:N \l_@@_bottom_box } + \dim_eval:n { \box_dp:N \l_@@_bottom_box } + } + { \c_@@_zero_pt_str } + { + \vbox_unpack_drop:N \l_@@_body_box + \box_clear:N \l_@@_bottom_box + \@@_build_display_auxi: + } + { \@@_build_display_auxiii: } + } + } +\str_const:Nx \c_@@_zero_pt_str + { + \dim_use:N \c_zero_dim + \dim_use:N \c_zero_dim + \dim_use:N \c_zero_dim + \dim_use:N \c_zero_dim + } +\cs_new_protected_nopar:Npn \@@_build_display_auxiii: + { + \bool_set_true:N \l_@@_attach_equation_bool + \bool_if:NTF \g_@@_amsmath_bool + { \box_set_eq_drop:NN \l_@@_display_box \g_@@_display_box } + { + \box_gclear:N \g_@@_display_box + \@@_adjust_equation: + } + \@@_build_body_box: + } +\cs_new_protected_nopar:Npn \@@_attach_equation:N + { + \bool_if:NTF \g_@@_amsmath_bool + { \@@_attach_equation_amsmath:N } + { \@@_attach_equation_normal:N } + } +\cs_new_protected:Npn \@@_attach_equation_amsmath:N #1 + { + \vbox_set:Nn #1 + { + \box_use:N #1 + \@@_ignore_depth: + \vbox_unpack_drop:N \l_@@_display_box + \skip_vertical:n + { \g_@@_display_pre_dim - \box_dp:N #1 } + \box_use_drop:N \g_@@_equation_box + } + } +\cs_new_protected:Npn \@@_attach_equation_normal:N #1 + { + \vbox_set:Nn #1 + { + \@@_tex_parameter: + \dim_set_eq:NN \tex_hsize:D \l_@@_display_dim + \para_raw_noindent: + \hbox_unpack_drop:N #1 \tex_unskip:D + \@@_insert_equation: + \para_raw_end: + \skip_gset_eq:NN \g_@@_pos_skip \tex_lastskip:D + \tex_unskip:D + \int_gset_eq:NN \g_@@_pos_int \tex_lastpenalty:D + \tex_unpenalty:D + } + } +\cs_new_protected_nopar:Npn \@@_insert_equation: + { + \c_math_toggle_token \c_math_toggle_token + \dim_compare:nNnTF \tex_displaywidth:D = \l_@@_display_dim + { \box_use_drop:N \g_@@_equation_box } + { + \bool_if:NTF \g_@@_eqnum_bool + { \@@_repack_equation: } + { \box_use_drop:N \g_@@_equation_box } + } + \c_math_toggle_token \c_math_toggle_token + } +\cs_new_protected_nopar:Npn \@@_repack_equation: + { + \box_gclear:N \g_@@_equation_box + \box_use_drop:N \g_@@_eqbody_box + \bool_if:NTF \g_@@_leqno_bool + { \tex_leqno:D } + { \tex_eqno:D } + \box_use_drop:N \g_@@_eqnum_box + } +\cs_new_protected_nopar:Npn \@@_adjust_equation: + { + \@@_test_eqnum: + \bool_if:NT \g_@@_eqnum_bool + { \@@_adjust_equation_width: } + } +\cs_new_protected_nopar:Npn \@@_test_eqnum: + { + \hbox_set:Nn \l_@@_last_box + { + \bool_gset_false:N \g_@@_eqnum_bool + \hbox_unpack:N \g_@@_equation_box + \@@_if_last_hlist:F { \use_none_delimit_by_q_stop:w } + \box_gset_to_last:N \g_@@_eqnum_box + \@@_if_last_kern:F { \use_none_delimit_by_q_stop:w } + \tex_unkern:D + \@@_if_last_hlist:F { \use_none_delimit_by_q_stop:w } + \box_gset_to_last:N \g_@@_eqbody_box + \@@_if_last_none:F { \use_none_delimit_by_q_stop:w } + \bool_gset_true:N \g_@@_eqnum_bool + \use_none_delimit_by_q_stop:w \q_stop + } + } +\cs_new_protected_nopar:Npn \@@_adjust_equation_width: + { + \bool_if:NTF \g_@@_leqno_bool + { \@@_adjust_leqno: } + { + \box_gset_wd:Nn \g_@@_equation_box + { \box_wd:N \g_@@_eqbody_box } + } + } +\cs_new_protected_nopar:Npn \@@_adjust_leqno: + { + \box_set_eq_drop:NN \l_@@_last_box \g_@@_eqnum_box + \box_gset_eq_drop:NN \g_@@_eqnum_box \g_@@_eqbody_box + \box_gset_eq_drop:NN \g_@@_eqbody_box \l_@@_last_box + \hbox_gset:Nn \g_@@_equation_box + { + \skip_horizontal:n + { + \box_wd:N \g_@@_eqbody_box + - \box_wd:N \g_@@_equation_box + } + \box_use_drop:N \g_@@_equation_box + } + } +\box_new:N \g_@@_eqbody_box +\box_new:N \g_@@_eqnum_box +\box_new:N \g_@@_equation_box +\box_new:N \l_@@_display_box +\int_new:N \g_@@_pos_int +\skip_new:N \g_@@_pos_skip +\bool_new:N \g_@@_eqnum_bool +\bool_new:N \g_@@_leqno_bool +\bool_new:N \l_@@_display_bool +\bool_new:N \l_@@_attach_equation_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_pos_skip:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_pos_skip: + { + \bool_lazy_or:nnTF + { \g_@@_right_move_bool } + { \int_compare_p:nNn \g_@@_window_int > \c_zero_int } + { + \tex_vadjust:D + { + \tex_penalty:D \c_@@_nobreak_int + \bool_if:NT \l_@@_display_bool + { \skip_vertical:N \g_@@_pos_skip } + } + } + { + \bool_if:NT \l_@@_display_bool + { + \tex_vadjust:D + { + \tex_penalty:D \g_@@_pos_int + \skip_vertical:N \g_@@_pos_skip + } + } + } + \int_gzero:N \g_@@_pos_int + \skip_gzero:N \g_@@_pos_skip + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_body_box:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_body_box: + { + \box_set_eq:NN \l_@@_save_body_box \l_@@_bottom_box + \@@_build_window: + \int_compare:nNnTF \g_@@_line_int > \l_@@_window_line_int + { \@@_extract_hbox:NN \l_@@_body_box \l_@@_bottom_box } + { \box_clear:N \l_@@_bottom_box } + \box_if_empty:NF \l_@@_bottom_box + { \bool_set_false:N \l_@@_attach_equation_bool } + \box_clear:N \l_@@_window_box + \@@_build_box: + } +\box_new:N \l_@@_save_body_box +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_body_box:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_window: + { + \vbox_set:Nn \l_@@_body_box + { + \@@_tex_parameter: + \@@_make_parshape: + \@@_column_penalties: + \dim_zero:N \tex_emergencystretch:D + \dim_set_eq:NN \tex_hfuzz:D \c_max_dim + \dim_set_eq:NN \tex_vfuzz:D \c_max_dim + \int_set_eq:NN \tex_hbadness:D \c_max_int + \int_set_eq:NN \tex_vbadness:D \c_max_int + \int_set:Nn \tex_tolerance:D { 1000 } + \para_raw_noindent: + \hbox_unpack_drop:N \l_@@_bottom_box + \para_raw_end: + \int_gset_eq:NN \g_@@_line_int \tex_prevgraf:D + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_make_parshape:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_make_parshape: + { + \tex_parshape:D + \int_eval:n { \l_@@_window_line_int + 1 } ~ + \bool_if:NTF \l_@@_hang_bool + { + \prg_replicate:nn + { \l_@@_window_int } + { \c_zero_dim \l_@@_window_dim } + } + { + \bool_if:NTF \l_@@_column_bool + { + \prg_replicate:nn + { \l_@@_window_int / 2 } + { \c_zero_dim \l_@@_l_dim } + \prg_replicate:nn + { + \bool_if:NTF \g_@@_column_right_bool + { \g_@@_column_window_int } + { \l_@@_window_int / 2 } + } + { \c_zero_dim \l_@@_r_dim } + } + { + \prg_replicate:nn + { \l_@@_window_int / 2 } + { + \c_zero_dim \l_@@_l_dim + \c_zero_dim \l_@@_r_dim + } + } + } + \c_zero_dim \c_max_dim + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_column_penalties:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_column_penalties: + { + \bool_if:NF \l_@@_hang_bool + { + \bool_if:NT \l_@@_column_bool + { \@@_column_penalties_aux: } + } + } +\cs_new_protected_nopar:Npn \@@_column_penalties_aux: + { + \tex_interlinepenalties:D + \int_eval:n { \l_@@_window_int / 2 + \c_one_int } ~ + \prg_replicate:nn + { \l_@@_window_int / 2 - \c_one_int } + { \c_@@_nobreak_int } + \c_@@_break_int + \c_zero_int + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_box:, \@@_build_block:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_block: + { + \@@_build_block_auxi: + \vbox_set:Nn \l_@@_window_box + { + \@@_tex_parameter: + \dim_set_eq:NN \tex_hsize:D \l_@@_line_dim + \para_raw_noindent: + \hbox_unpack_drop:N \g_@@_line_box + \para_raw_end: + } + \bool_if:NT \l_@@_attach_equation_bool + { + \box_set_ht:Nn \l_@@_window_box + { \box_ht_plus_dp:N \l_@@_window_box - \g_@@_dp_dim } + \box_set_dp:Nn \l_@@_window_box { \g_@@_dp_dim } + } + } +\cs_new_protected_nopar:Npn \@@_build_block_auxi: + { + \vbox_set:Nn \l_@@_body_box + { + \vbox_unpack_drop:N \l_@@_body_box + \bool_lazy_and:nnTF + { \box_if_empty_p:N \l_@@_bottom_box } + { \int_if_odd_p:n { \g_@@_line_int } } + { \box_set_eq:NN \l_@@_r_box \l_@@_empty_box } + { + \box_set_to_last:N \l_@@_r_box + \tex_unskip:D \tex_unpenalty:D + } + \box_set_to_last:N \l_@@_l_box + \tex_unskip:D \tex_unpenalty:D + \hbox_gset:Nn \g_@@_line_box + { + \bool_if:NT \l_@@_attach_equation_bool + { \@@_build_block_attach: } + \box_use:N \l_@@_l_box + \tex_hfill:D + \box_use:N \l_@@_r_box + } + \@@_build_block_auxii: + } + } +\cs_new_protected_nopar:Npn \@@_build_block_auxii: + { + \int_case:nnTF + { \tex_lastnodetype:D } + { + { \c_@@_none_node } { } + { \c_@@_whatsit_node } { } + } + { \@@_build_block_finalise: } + { \@@_build_block_auxiii: } + } +\cs_new_protected_nopar:Npn \@@_build_block_auxiii: + { + \box_set_to_last:N \l_@@_r_box + \tex_unskip:D \tex_unpenalty:D + \box_set_to_last:N \l_@@_l_box + \tex_unskip:D \tex_unpenalty:D + \hbox_gset:Nn \g_@@_line_box + { + \box_use:N \l_@@_l_box + \tex_hfill:D + \box_use:N \l_@@_r_box + \tex_penalty:D \c_@@_break_int + \hbox_unpack_drop:N \g_@@_line_box + } + \@@_build_block_auxii: + } +\cs_new_protected_nopar:Npn \@@_build_block_attach: + { + \box_set_eq:NN \l_@@_last_box \l_@@_l_box + \@@_attach_equation:N \l_@@_last_box + \dim_gset:Nn \g_@@_dp_dim { \box_dp:N \l_@@_last_box } + \hbox_set:Nn \l_@@_l_box + { + \box_move_down:nn + { \box_ht:N \l_@@_last_box - \box_ht:N \l_@@_l_box } + { \box_use_drop:N \l_@@_last_box } + } + } +\cs_new_protected_nopar:Npn \@@_build_block_finalise: + { + \dim_gset:Nn \g_@@_ht_dim + { + \dim_max:nn + { \box_ht:N \l_@@_l_box } + { \box_ht:N \l_@@_r_box } + } + } +\dim_new:N \g_@@_dp_dim +\dim_new:N \g_@@_ht_dim +\box_new:N \l_@@_l_box +\box_new:N \l_@@_r_box +\box_new:N \g_@@_line_box +\box_new:N \l_@@_empty_box +\hbox_set:Nn \l_@@_empty_box { } +\int_const:Nn \c_@@_break_int { -10000 } +\int_const:Nn \c_@@_nobreak_int { 10000 } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_column_fuzzy:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_column_fuzzy: + { + \hbox_set_to_wd:Nnn \l_@@_window_box + { \l_@@_line_dim } + { + \skip_zero:N \tex_splittopskip:D + \dim_set_eq:NN \tex_vfuzz:D \c_max_dim + \int_set_eq:NN \tex_vbadness:D \c_max_int + \@@_build_column_aux: + \box_if_empty:NT \l_@@_bottom_box + { \@@_build_column_fuzzy_aux: } + \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_l_box } + \vbox_set:Nn \l_@@_l_box + { + \vbox_unpack_drop:N \l_@@_l_box + \bool_if:NT \l_@@_attach_equation_bool + { + \box_set_to_last:N \l_@@_last_box + \@@_attach_equation:N \l_@@_last_box + \vbox_unpack_drop:N \l_@@_last_box + } + } + \box_use:N \l_@@_l_box + \tex_hfil:D + \box_move_up:nn + { \box_ht:N \l_@@_l_box - \box_ht:N \l_@@_r_box } + { \box_use_drop:N \l_@@_r_box } + } + } +\cs_new_protected_nopar:Npn \@@_build_column_aux: + { + \vbox_set_split_to_ht:NNn \l_@@_l_box \l_@@_body_box + { \c_zero_dim } + \vbox_set_top:Nn \l_@@_l_box + { \vbox_unpack_drop:N \l_@@_l_box } + \box_set_eq_drop:NN \l_@@_r_box \l_@@_body_box + } +\cs_new_protected_nopar:Npn \@@_build_column_fuzzy_aux: + { + \dim_compare:nNnTF + { + \box_ht_plus_dp:N \l_@@_r_box - + \box_ht_plus_dp:N \l_@@_l_box + } + > + { \l_@@_min_dim } + { + \box_if_empty:NF \l_@@_last_l_box + { + \box_set_eq_drop:NN \l_@@_l_box \l_@@_last_l_box + \box_set_eq_drop:NN \l_@@_r_box \l_@@_last_r_box + } + } + { \@@_rebuild_window: } + } +\cs_new_protected_nopar:Npn \@@_rebuild_window: + { + \int_compare:nNnT \l_@@_window_int > { 2 } + { + \int_sub:Nn \l_@@_window_int { 2 } + \box_set_eq_drop:NN \l_@@_last_l_box \l_@@_l_box + \box_set_eq_drop:NN \l_@@_last_r_box \l_@@_r_box + \box_set_eq:NN \l_@@_bottom_box \l_@@_save_body_box + \int_set_eq:NN \l_@@_window_line_int \l_@@_window_int + \@@_build_window: + \@@_build_column_aux: + \@@_build_column_fuzzy_aux: + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_column_strict:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_column_strict: + { + \group_begin: + \skip_zero:N \tex_splittopskip:D + \dim_set_eq:NN \tex_vfuzz:D \c_max_dim + \int_set_eq:NN \tex_vbadness:D \c_max_int + \@@_build_column_aux: + \box_if_empty:NTF \l_@@_r_box + { \@@_build_column_strict_auxi: } + { + \box_if_empty:NTF \l_@@_bottom_box + { \@@_build_column_strict_auxii: } + { + \bool_if:NTF \g_@@_column_right_bool + { \@@_build_column_strict_auxiii: } + { \@@_build_column_strict_auxiv: } + } + } + \group_end: + \box_set_eq_drop:NN \l_@@_window_box \g_@@_window_box + } +\cs_new_protected_nopar:Npn \@@_build_column_strict_auxi: + { + \@@_repack_left_box: + \bool_if:NT \l_@@_attach_equation_bool + { \@@_column_attach:N \l_@@_l_box } + \box_gset_eq_drop:NN \g_@@_window_box \l_@@_l_box + \bool_gset_true:N \g_@@_column_right_bool + \bool_if:NF \g_@@_first_save_bool + { + \bool_gset_true:N \g_@@_first_save_bool + \dim_gset:Nn \g_@@_first_sep_dim + { \tex_baselineskip:D - \g_@@_ht_dim } + \dim_gset_eq:NN \g_@@_first_dp_dim \g_@@_prevdepth_dim + } + \int_case:nnT { \g_@@_window_int } + { + { \c_zero_int } { } + { \g_@@_line_int } { } + } + { \@@_column_move_entire_aux: } + } +\cs_new_protected_nopar:Npn \@@_column_move_entire_aux: + { + \bool_gset_true:N \g_@@_entire_bool + \bool_gset_true:N \g_@@_next_hang_bool + } +\cs_new_protected_nopar:Npn \@@_column_move_entire: + { + \dim_gsub:Nn \g_@@_first_sep_dim + { \box_dp:N \l_@@_window_box } + \bool_gset_false:N \g_@@_entire_bool + \dim_gzero:N \g_@@_column_right_ht_dim + \dim_gset_eq:NN \g_@@_prevdepth_dim \g_@@_first_dp_dim + \@@_column_right_move_set:nn + { \g_@@_stuff_ht_dim } + { \g_@@_window_ht_dim } + \int_gset_eq:NN \g_@@_window_int \g_@@_column_window_int + } +\cs_new_protected:Npn \@@_column_right_move_set:nn #1#2 + { + \bool_gset_true:N \g_@@_right_move_bool + \bool_gset_true:N \g_@@_first_set_bool + \tl_gput_right:Nn \g_@@_main_setting_tl + { + \bool_if:NTF \g_@@_first_set_bool + { + \bool_gset_false:N \g_@@_first_set_bool + \bool_set_true:N \l_@@_first_move_bool + } + { \bool_set_false:N \l_@@_first_move_bool } + \fp_zero:N \l_@@_ratio_fp + } + \@@_make_next_stuff:nn + { \l_@@_line_dim - \l_@@_r_dim - \l_@@_rightsep_dim } + {#1} + \dim_gset:Nn \g_@@_column_left_dim {#2} + \int_gzero:N \g_@@_top_int + } +\cs_new_protected_nopar:Npn \@@_build_column_strict_auxii: + { + \bool_gset_false:N \g_@@_entire_bool + \@@_repack_left_box: + \bool_if:NT \l_@@_attach_equation_bool + { \@@_column_attach:N \l_@@_r_box } + \dim_gset:Nn \g_@@_hang_ht_dim + { + \g_@@_stuff_ht_dim - \tex_baselineskip:D * + \@@_unit:n { \box_ht_plus_dp:N \l_@@_r_box } + - \g_@@_pos_skip + } + \dim_compare:nNnTF \g_@@_hang_ht_dim > \c_zero_dim + { \@@_column_move_right: } + { \@@_column_put_right: } + \box_gset_ht:Nn \g_@@_window_box { \box_ht:N \l_@@_l_box } + \box_gset_dp:Nn \g_@@_window_box { \box_dp:N \l_@@_l_box } + } +\cs_new_protected_nopar:Npn \@@_column_move_right: + { + \int_compare:nNnTF \g_@@_window_int > \c_zero_int + { + \dim_gset:Nn \g_@@_column_left_dim + { + \g_@@_window_ht_dim + - \g_@@_first_sep_dim + - \box_ht:N \l_@@_r_box + } + \@@_next_hang_para: + } + { + \dim_gset:Nn \g_@@_column_left_dim + { + \box_ht:N \l_@@_l_box + - \box_ht:N \l_@@_r_box + } + \dim_gset:Nn \g_@@_first_sep_dim + { \tex_baselineskip:D - \g_@@_ht_dim } + \bool_gset_true:N \g_@@_right_move_bool + \bool_gset_true:N \g_@@_next_hang_bool + } + \hbox_gset_to_wd:Nnn \g_@@_window_box + { \l_@@_line_dim } + { + \box_use:N \l_@@_l_box + \tex_hfil:D + \box_move_up:nn + { \g_@@_column_left_dim } + { \box_use:N \l_@@_r_box } + } + \dim_gset:Nn \g_@@_column_right_ht_dim + { \box_ht:N \l_@@_r_box + \g_@@_pos_skip } + } +\cs_new_protected_nopar:Npn \@@_column_put_right: + { + \hbox_gset_to_wd:Nnn \g_@@_window_box + { \l_@@_line_dim } + { + \box_use:N \l_@@_l_box + \tex_hfil:D + \box_move_up:nn + { + \int_compare:nNnTF \g_@@_window_int > \c_zero_int + { \g_@@_window_ht_dim - \g_@@_first_sep_dim } + { \box_ht:N \l_@@_l_box } + - \box_ht:N \l_@@_r_box + } + { \box_use:N \l_@@_r_box } + } + \skip_gzero:N \g_@@_pos_skip + } +\cs_new_protected_nopar:Npn \@@_next_hang_para: + { + \bool_if:NTF \g_@@_entire_bool + { \@@_column_move_entire: } + { + \@@_column_right_move_set:nn + { \g_@@_hang_ht_dim } + { \g_@@_column_left_dim } + \int_gzero:N \g_@@_window_int + } + \bool_gset_false:N \g_@@_next_hang_bool + } +\cs_new_protected_nopar:Npn \@@_build_column_strict_auxiii: + { + \bool_gset_false:N \g_@@_column_right_bool + \@@_repack_left_box: + \hbox_gset_to_wd:Nnn \g_@@_window_box + { \l_@@_line_dim } + { + \box_use:N \l_@@_l_box + \tex_hfil:D + \box_use:N \l_@@_r_box + } + \box_gset_ht:Nn \g_@@_window_box + { \box_ht:N \l_@@_l_box } + } +\cs_new_protected_nopar:Npn \@@_build_column_strict_auxiv: + { + \@@_repack_left_box: + \hbox_gset_to_wd:Nnn \g_@@_window_box + { \l_@@_line_dim } + { + \box_use:N \l_@@_l_box + \tex_hfil:D + \box_move_up:nn + { \box_ht:N \l_@@_l_box - \box_ht:N \l_@@_r_box } + { \box_use_drop:N \l_@@_r_box } + } + } +\cs_new_protected_nopar:Npn \@@_repack_left_box: + { + \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_l_box } + \vbox_set:Nn \l_@@_l_box + { \vbox_unpack_drop:N \l_@@_l_box } + } +\cs_new_protected_nopar:Npn \@@_column_attach:N #1 + { + \vbox_set:Nn #1 + { + \vbox_unpack_drop:N #1 + \box_set_to_last:N \l_@@_last_box + \@@_attach_equation:N \l_@@_last_box + \vbox_unpack_drop:N \l_@@_last_box + } + } +\box_new:N \l_@@_last_l_box +\box_new:N \l_@@_last_r_box +\box_new:N \g_@@_window_box +\dim_new:N \g_@@_fake_wd_dim +\dim_new:N \g_@@_first_dp_dim +\dim_new:N \g_@@_first_sep_dim +\dim_new:N \g_@@_column_left_dim +\dim_new:N \g_@@_column_right_ht_dim +\bool_new:N \g_@@_entire_bool +\bool_new:N \g_@@_next_hang_bool +\bool_new:N \g_@@_first_save_bool +\bool_new:N \g_@@_column_right_bool +\bool_new:N \l_@@_column_strict_bool +\bool_new:N \g_@@_first_set_bool +\bool_new:N \l_@@_first_move_bool +\bool_new:N \g_@@_right_move_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_box:,\@@_build_column:} +% \begin{macrocode} +\bool_new:N \l_@@_column_bool +\cs_new_eq:NN \@@_build_column: \@@_build_column_strict: +\cs_new_eq:NN \@@_build_box: \@@_build_column: +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_hang:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_hang: + { + \bool_if:NTF \g_@@_hangfrom_bool + { \@@_build_hangfrom: } + { + \vbox_set_top:Nn \l_@@_window_box + { \vbox_unpack:N \l_@@_body_box } + \dim_gset:Nn \g_@@_ht_dim { \box_ht:N \l_@@_window_box } + } + \bool_if:NTF \l_@@_attach_equation_bool + { + \vbox_set:Nn \l_@@_window_box + { + \vbox_unpack_drop:N \l_@@_window_box + \box_set_to_last:N \l_@@_last_box + \@@_attach_equation:N \l_@@_last_box + \vbox_unpack_drop:N \l_@@_last_box + } + } + { \box_set_eq_drop:NN \l_@@_window_box \l_@@_body_box } + \dim_compare:nNnTF \g_@@_column_left_dim > \c_zero_dim + { \@@_build_hang_aux: } + { \bool_gset_false:N \g_@@_move_hang_bool } + } +\cs_new_protected_nopar:Npn \@@_build_hang_aux: + { + \dim_set:Nn \l_@@_shift_dim + { + \dim_max:nn + { \box_ht:N \l_@@_window_box } + { \tex_baselineskip:D * \g_@@_line_int } + + \tex_parskip:D + } + \dim_gsub:Nn \g_@@_column_left_dim { \l_@@_shift_dim } + \dim_compare:nNnTF \g_@@_column_left_dim > \c_zero_dim + { + \box_if_empty:NTF \l_@@_bottom_box + { \bool_if:NT \g_@@_right_move_bool { \@@_set_next_hang: } } + { \bool_gset_false:N \g_@@_move_hang_bool } + } + { \bool_gset_false:N \g_@@_move_hang_bool } + } +\cs_new_protected_nopar:Npn \@@_set_next_hang: + { + \bool_if:NF \g_@@_move_hang_bool + { + \bool_gset_true:N \g_@@_move_hang_bool + \dim_gset_eq:NN \g_@@_hang_ht_dim \g_@@_remaining_dim + } + \dim_gsub:Nn \g_@@_hang_ht_dim { \l_@@_shift_dim } + \dim_gset:Nn \g_@@_dp_dim { \box_dp:N \l_@@_window_box } + \@@_column_right_move_set:nn + { \g_@@_hang_ht_dim } + { \g_@@_column_left_dim } + \int_gzero:N \g_@@_window_int + } +\dim_new:N \g_@@_hang_ht_dim +\bool_new:N \g_@@_move_hang_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_build_hangfrom:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_build_hangfrom: + { + \dim_compare:nNnTF \g_@@_prevdepth_dim > \c_@@_ignore_depth_dim + { \@@_build_hangfrom_aux: } + { \dim_gzero:N \g_@@_ht_dim } + } +\cs_new_protected_nopar:Npn \@@_build_hangfrom_aux: + { + \group_begin: + \skip_zero:N \tex_splittopskip:D + \vbox_gset:Nn \g_@@_line_box + { + \tex_penalty:D \c_@@_break_int + \vbox_unpack:N \l_@@_body_box + } + \vbox_set_split_to_ht:NNn \l_@@_last_box \g_@@_line_box + { \c_zero_dim } + \dim_gset:Nn \g_@@_ht_dim + { + \g_@@_baseline_skip + - \g_@@_prevdepth_dim + - \l_@@_shift_dim + - \box_ht:N \l_@@_body_box + + \box_ht:N \g_@@_line_box + } + \group_end: + \box_set_eq_drop:NN \l_@@_body_box \g_@@_line_box + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_put_box:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_put_box: + { + \para_raw_end: + \dim_compare:nNnTF \g_@@_prevdepth_dim > \c_@@_ignore_depth_dim + { \@@_add_vskip: } + { \skip_gzero:N \g_@@_pre_skip } + \skip_set_eq:NN \l_@@_par_skip \tex_parskip:D + \skip_zero:N \tex_parskip:D + \bool_if:NTF \g_@@_right_move_bool + { \@@_put_box_aux: } + { + \box_if_empty:NTF \l_@@_bottom_box + { + \dim_compare:nNnTF + { \g_@@_remaining_dim } + > + { \box_ht_plus_dp:N \l_@@_window_box } + { \@@_set_next: } + { \@@_put_box_aux: } + } + { \@@_put_box_aux: } + } + } +\skip_new:N \l_@@_par_skip +\cs_new_protected_nopar:Npn \@@_put_box_aux: + { + \int_gzero:N \g_@@_window_int + \@@_hbox:n + { + \@@_put_window_box: + \bool_if:NF \g_@@_next_bool + { \@@_put_stuff_box: } + } + \box_if_empty:NTF \l_@@_bottom_box + { \@@_put_trailer_box: } + { \@@_put_bottom_box: } + } +\cs_new_protected_nopar:Npn \@@_put_trailer_box: + { + \bool_if:NTF \g_@@_next_hang_bool + { + \@@_next_hang_para: + \@@_next_para_trailer: + } + { + \bool_if:NTF \g_@@_right_move_bool + { \@@_next_para_trailer: } + { + \@@_add_pos_skip: + \box_if_empty:NF \g_@@_pos_box + { + \@@_newline: + \hbox_unpack_drop:N \g_@@_pos_box + } + } + } + } +\cs_new_protected_nopar:Npn \@@_put_bottom_box: + { + \@@_newline: + \hbox_unpack_drop:N \l_@@_bottom_box + \box_if_empty:NF \g_@@_equation_box + { \@@_insert_equation: } + \box_if_empty:NF \g_@@_pos_box + { \hbox_unpack_drop:N \g_@@_pos_box } + \bool_gset_false:N \g_@@_right_move_bool + \bool_gset_false:N \g_@@_first_save_bool + } +\cs_new_protected_nopar:Npn \@@_newline: + { + \tex_penalty:D \c_@@_nobreak_int + \tex_hfil:D + \tex_penalty:D \c_@@_break_int + } +\cs_new_protected:Npn \@@_hbox:n #1 + { + \para_raw_noindent: + \hbox_gset:Nn \g_@@_last_box {#1} + \box_gset_wd:Nn \g_@@_last_box { \l_@@_line_dim } + \box_use_drop:N \g_@@_last_box + } +\cs_new_protected_nopar:Npn \@@_put_window_box: + { + \dim_compare:nNnF \l_@@_l_dim > \c_zero_dim + { \skip_horizontal:n { \l_@@_line_dim - \l_@@_r_dim } } + \box_use:N \l_@@_window_box + } +\cs_new_protected_nopar:Npn \@@_put_stuff_box: + { + \@@_move_stuff_box:nn { up } + { + \l_@@_voffset_dim + + ( \box_dp:N \g_@@_stuff_box - + \box_dp:N \l_@@_window_box ) + + ( \box_ht_plus_dp:N \l_@@_window_box - + \g_@@_stuff_ht_dim ) / 2 + \box_if_empty:NT \l_@@_bottom_box + { - \g_@@_pos_skip / 2 } + } + \@@_output_stuff_box: + } +\cs_new_protected_nopar:Npn \@@_output_stuff_box: + { + \skip_horizontal:n + { + \dim_compare:nNnTF \l_@@_r_dim > \c_zero_dim + { + \dim_compare:nNnTF + { \box_wd:N \l_@@_window_box } + < + { \l_@@_window_dim } + { \l_@@_leftsep_dim } + { + - \l_@@_r_dim + - \l_@@_rightsep_dim + - \g_@@_stuff_wd_dim + } + } + { \l_@@_leftsep_dim } + } + \box_use_drop:N \g_@@_stuff_box + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_move_stuff_box:n} +% \begin{macrocode} +\cs_new_protected:Npn \@@_move_stuff_box:nn #1#2 + { + \hbox_gset:Nn \g_@@_stuff_box + { + \@@_parshape_kern: + \use:c { box_move_ #1 :nn } + {#2} + { \box_use_drop:N \g_@@_stuff_box } + } + \box_gset_ht:Nn \g_@@_stuff_box { \c_zero_dim } + \box_gset_dp:Nn \g_@@_stuff_box { \c_zero_dim } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_vskip:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_vskip: + { + \box_if_empty:NTF \g_@@_display_box + { \@@_add_vskip_auxi: } + { \@@_add_vskip_display: } + } +\cs_new_protected_nopar:Npn \@@_add_vskip_display: + { + \vbox_unpack_drop:N \g_@@_display_box + \@@_ignore_depth: + } +\cs_new_protected_nopar:Npn \@@_add_vskip_auxi: + { + \dim_compare:nNnTF \tex_pagegoal:D < \c_max_dim + { \@@_add_vskip_auxii: } + { \@@_add_vskip_auxiii: } + } +\cs_new_protected_nopar:Npn \@@_add_vskip_auxii: + { + \skip_gset:Nn \g_@@_pre_skip + { + \g_@@_baseline_skip + - \g_@@_prevdepth_dim + - \g_@@_ht_dim + } + \dim_compare:nNnT \g_@@_pre_skip < \tex_lineskiplimit:D + { \skip_gset_eq:NN \g_@@_pre_skip \tex_lineskip:D } + \bool_if:NTF \l_@@_first_move_bool + { \@@_first_move_skip: } + { \skip_vertical:N \g_@@_pre_skip } + \@@_ignore_depth: + } +\cs_new_protected_nopar:Npn \@@_add_vskip_auxiii: + { + \dim_compare:nNnTF \tex_topskip:D > \g_@@_ht_dim + { + \tex_hrule:D height \c_zero_dim \scan_stop: + \skip_gset:Nn \g_@@_pre_skip + { \tex_topskip:D - \g_@@_ht_dim } + \skip_vertical:n { \g_@@_pre_skip - \tex_topskip:D } + } + { \skip_gzero:N \g_@@_pre_skip } + } +\cs_new_protected_nopar:Npn \@@_first_move_skip: + { + \skip_vertical:n + { + \g_@@_first_sep_dim + - \g_@@_window_ht_dim + - \tex_parskip:D + \dim_compare:nNnT \g_@@_column_right_ht_dim > \c_zero_dim + { + \g_@@_column_right_ht_dim + \g_@@_pre_skip } + } + } +\skip_new:N \g_@@_pre_skip +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_ignore_depth:,\@@_set_prevdepth:N} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_ignore_depth: + { \dim_set_eq:NN \tex_prevdepth:D \c_@@_ignore_depth_dim } +\cs_new_protected_nopar:Npn \@@_set_prevdepth:N + { \dim_set_eq:NN \tex_prevdepth:D } +\dim_const:Nn \c_@@_ignore_depth_dim { -1000pt } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_set_next:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_set_next: + { + \dim_set:Nn \l_@@_height_dim + { + \g_@@_pre_skip + + \g_@@_pos_skip + + \box_ht_plus_dp:N \l_@@_window_box + } + \dim_gadd:Nn \g_@@_total_ht_dim { \l_@@_height_dim } + \dim_set:Nn \l_@@_shift_dim + { \g_@@_remaining_dim - \l_@@_height_dim } + \dim_compare:nNnTF \l_@@_shift_dim > \c_zero_dim + { \@@_set_next_auxi: } + { + \dim_compare:nNnTF + { - \l_@@_shift_dim } > \l_@@_min_dim + { \@@_set_next_auxii: } + { \@@_set_next_auxi: } + } + } +\dim_new:N \g_@@_total_ht_dim +\cs_new_protected_nopar:Npn \@@_set_next_auxi: + { + \int_gset:Nn \g_@@_window_int + { + \dim_compare:nNnTF \l_@@_shift_dim > \c_zero_dim + { \@@_unit:n { \l_@@_shift_dim } } + { \c_one_int } + } + \@@_set_next_verify: + \bool_if:NF \g_@@_next_bool + { \@@_move_next_stuff_box: } + \@@_set_next_output: + \@@_make_next_stuff:nn + { \g_@@_stuff_wd_dim } + { \l_@@_shift_dim } + \int_gzero:N \g_@@_top_int + \@@_next_para_trailer: + } +\cs_new_protected_nopar:Npn \@@_move_next_stuff_box: + { + \@@_move_stuff_box:nn { down } + { + \box_ht:N \g_@@_stuff_box + - \box_ht:N \l_@@_window_box + + ( \g_@@_window_ht_dim + - \g_@@_stuff_ht_dim + - \g_@@_pre_skip + + \g_@@_pos_skip + + \l_@@_par_skip ) / 2 + - \l_@@_voffset_dim + } + } +\cs_new_protected_nopar:Npn \@@_set_next_auxii: + { + \int_gzero:N \g_@@_window_int + \bool_if:NF \g_@@_next_bool + { + \@@_move_stuff_box:nn { down } + { + \box_ht:N \g_@@_stuff_box + - \box_ht:N \l_@@_window_box + - \l_@@_voffset_dim + } + } + \@@_set_next_output: + \@@_add_pos_skip: + } +\cs_new_protected_nopar:Npn \@@_set_next_output: + { + \@@_hbox:n + { + \@@_put_window_box: + \bool_if:NF \g_@@_next_bool + { \@@_output_stuff_box: } + } + } +\cs_new_protected_nopar:Npn \@@_set_next_verify: + { + \dim_set:Nn \l_@@_height_dim + { \g_@@_window_ht_dim - \g_@@_total_ht_dim } + \dim_until_do:nNnn + { \tex_baselineskip:D * \g_@@_window_int + \l_@@_par_skip } + > + { \l_@@_height_dim } + { \int_gincr:N \g_@@_window_int } + \dim_gadd:Nn \g_@@_total_ht_dim + { \tex_baselineskip:D * \g_@@_window_int + \l_@@_par_skip } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_next_para_trailer:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_next_para_trailer: + { + \@@_add_pos_skip: + \box_if_empty:NTF \g_@@_pos_box + { \@@_next_para: } + { + \@@_env_begin: + \hbox_unpack_drop:N \g_@@_pos_box + \@@_env_end: + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_make_next_stuff:nn} +% \begin{macrocode} +\cs_new_protected:Npn \@@_make_next_stuff:nn #1#2 + { + \bool_gset_true:N \g_@@_next_bool + \dim_gset:Nn \g_@@_stuff_wd_dim {#1} + \dim_gset:Nn \g_@@_remaining_dim {#2} + } +\bool_new:N \g_@@_next_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_extract_hbox:NN} +% \begin{macrocode} +\cs_new_protected:Npn \@@_extract_display_hbox:NN #1 + { + \box_gclear:N \g_@@_pos_box + \vbox_set:Nn #1 + { + \vbox_unpack_drop:N #1 + \bool_if:NTF \g_@@_display_bool + { \@@_test_display_math: } + { \box_gclear:N \g_@@_display_box } + \box_if_empty:NTF \g_@@_display_box + { + \bool_gset_false:N \g_@@_amsmath_bool + \@@_extract_last_hbox:N \g_@@_last_box + } + { \box_gclear:N \g_@@_last_box } + } + \box_if_empty:NF \g_@@_display_box + { \dim_gset:Nn \g_@@_display_pre_dim { \box_dp:N #1 } } + \@@_extract_hbox_aux:N + } +\cs_new_protected:Npn \@@_extract_hbox:NN #1 + { + \vbox_set:Nn #1 + { + \vbox_unpack_drop:N #1 + \@@_extract_last_hbox:N \g_@@_last_box + } + \@@_extract_hbox_aux:N + } +\cs_new_protected:Npn \@@_extract_hbox_aux:N #1 + { + \box_if_empty:NTF \g_@@_last_box + { \box_clear:N #1 } + { \@@_repack_hbox:N #1 } + } +\cs_new_protected:Npn \@@_repack_hbox:N #1 + { + \hbox_set:Nn #1 + { + \skip_if_eq:nnF + { \g_@@_main_left_skip } { \c_zero_skip } + { \skip_horizontal:N \g_@@_main_left_skip } + \hbox_unpack_drop:N \g_@@_last_box + \tex_unskip:D \tex_unskip:D \tex_unpenalty:D + } + } +\cs_new_protected:Npn \@@_extract_last_hbox:N #1 + { + \@@_if_last_hlist:TF + { + \box_gset_to_last:N #1 + \tex_unskip:D + } + { \box_gclear:N #1 } + } +\box_new:N \g_@@_last_box +\box_new:N \g_@@_display_box +\dim_new:N \g_@@_display_pre_dim +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_test_display_math:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_test_display_math: + { + \@@_if_last_hlist:T + { + \box_gset_to_last:N \g_@@_pos_box + \tex_unskip:D + } + \box_clear:N \l_@@_add_box + \box_gclear:N \g_@@_display_box + \skip_gzero:N \g_@@_last_skip + \skip_gzero:N \g_@@_display_pre_skip + \bool_gset_false:N \g_@@_amsmath_bool + \@@_add_last_skip:w + \@@_add_last_penalty:w + \@@_add_last_box:w + \@@_add_last_skip:w + \@@_add_last_skip:w + \@@_add_last_penalty:w + \@@_add_last_finalise:w \q_stop + } +\box_new:N \l_@@_add_box +\box_new:N \g_@@_pos_box +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_last_stop:w} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_last_stop:w + { + \vbox_unpack_drop:N \l_@@_add_box + \use_none_delimit_by_q_stop:w + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_last_skip:w} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_last_skip:w + { + \@@_if_last_glue:TF + { + \skip_set_eq:NN \l_@@_last_skip \tex_lastskip:D + \vbox_set:Nn \l_@@_add_box + { + \skip_vertical:N \l_@@_last_skip + \vbox_unpack_drop:N \l_@@_add_box + } + \tex_unskip:D + \skip_gadd:Nn \g_@@_last_skip { \l_@@_last_skip } + } + { \@@_skip_stop:w } + } +\skip_new:N \l_@@_last_skip +\skip_new:N \g_@@_last_skip +\cs_new_eq:NN \@@_skip_stop:w \@@_add_last_stop:w +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_last_penalty:w} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_last_penalty:w + { + \@@_if_last_penalty:TF + { + \int_set_eq:NN \l_@@_last_int \tex_lastpenalty:D + \vbox_set:Nn \l_@@_add_box + { + \tex_penalty:D \l_@@_last_int + \vbox_unpack_drop:N \l_@@_add_box + } + \tex_unpenalty:D + \skip_gset_eq:NN \g_@@_pre_skip \g_@@_last_skip + \skip_gzero:N \g_@@_last_skip + } + { \@@_penalty_stop:w } + } +\int_new:N \l_@@_last_int +\cs_new_eq:NN \@@_penalty_stop:w \@@_add_last_stop:w +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_last_box:w} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_last_box:w + { + \@@_if_last_hlist:TF + { + \skip_gzero:N \g_@@_last_skip + \box_set_to_last:N \l_@@_last_box + \vbox_set:Nn \l_@@_add_box + { + \box_use_drop:N \l_@@_last_box + \vbox_unpack_drop:N \l_@@_add_box + } + } + { \@@_box_stop:w } + } +\box_new:N \l_@@_last_box +\cs_new_eq:NN \@@_box_stop:w \@@_add_last_stop:w +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_add_last_finalise:w} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_add_last_finalise:w + { + \int_gset_eq:NN \g_@@_display_pre_int \l_@@_last_int + \skip_gadd:Nn \g_@@_display_pre_skip { \g_@@_pre_skip } + \int_case:nnTF { \tex_lastnodetype:D } + { + { \c_@@_hlist_node } { } + { \c_@@_none_node } { } + { \c_@@_whatsit_node } { } + } + { \box_gset_eq_drop:NN \g_@@_display_box \l_@@_add_box } + { \vbox_unpack_drop:N \l_@@_add_box } + \use_none_delimit_by_q_stop:w + } +\int_new:N \g_@@_display_pre_int +\skip_new:N \g_@@_display_pre_skip +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_amsmath_boot:w,\@@_amsmath_recursion:w,\@@_amsmath_multline:w} +% \pkg{amsmath} 的 \env{align} 等数学环境内部是一个 \tn{halign} 环境,结构不一样,需要另外处理。 +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_amsmath_boot:w + { + \@@_add_last_skip:w + \@@_add_last_penalty:w + \cs_set_eq:NN \@@_box_stop:w \@@_add_last_stop:w + \@@_add_last_box:w + \bool_gset_true:N \g_@@_amsmath_bool + \cs_set_eq:NN \@@_skip_stop:w \@@_amsmath_multline:w + \cs_set_eq:NN \@@_penalty_stop:w \@@_amsmath_stop:NN + \@@_amsmath_recursion:w + } +\cs_new_protected_nopar:Npn \@@_amsmath_recursion:w + { + \@@_add_last_skip:w + \@@_add_last_skip:w + \@@_add_last_penalty:w + \@@_add_last_box:w + \@@_amsmath_recursion:w + } +\cs_new_protected:Npn \@@_amsmath_stop:NN #1#2 + { + \cs_set_eq:NN \@@_skip_stop:w \@@_add_last_stop:w + \cs_set_eq:NN \@@_penalty_stop:w \@@_add_last_stop:w + } +\bool_new:N \g_@@_amsmath_bool +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_amsmath_multline:w} +% \env{multline} 环境的结构与其他环境不一样。\pkg{amsmath} 的 \tn{@display@init} 定义为 +% \begin{verbatim} +% \def\@display@init#1{% +% \global\dt@ptrue \spread@equation +% \everycr{% +% \noalign{% +% #1% +% \ifdt@p +% \global\dt@pfalse +% \vskip-\lineskiplimit +% \vskip\normallineskiplimit +% \else +% \penalty\@eqpen \global\dspbrk@lvl\m@ne +% \fi +% }% +% }% +% } +% \end{verbatim} +% \env{align} 等环境的开头 \tn{ifdt@p} 为真,会插入两个 \tn{vskip}, +% 但是 \env{multline} 定义中的 \tn{mmeasure@} 没有重定义 \tn{everycr}, +% 上述定义中的 \tn{dt@pfalse} 被执行,导致环境开头被加入了 \tn{penalty}, +% 不确定是有意为之还是疏忽。 +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_amsmath_multline:w + { + \@@_amsmath_stop:NN ? ? + \@@_add_last_penalty:w + \skip_gset_eq:NN \g_@@_display_pre_skip + \g_@@_pre_skip + \@@_add_last_skip:w + \@@_add_last_penalty:w + \@@_add_last_finalise:w + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_amsmath_leqno:} +% \pkg{amsmath} 的 \opt{leqno} 是直接用 \cs{tex_leqno:D} 实现的,与 \LaTeX\ 的实现不一样。 +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_amsmath_leqno: + { + \legacy_if:nTF { tagsleft@ } + { \bool_gset_true:N \g_@@_leqno_bool } + { \bool_gset_false:N \g_@@_leqno_bool } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\@@_package_hook:nn { amsmath } + { + \cs_gset_eq:NN \@@_box_stop:w + \@@_amsmath_boot:w + \cs_gset_eq:NN \@@_test_leqno: + \@@_amsmath_leqno: + } +% \end{macrocode} +% +% \begin{macro}{\@@_set_float:} +% \begin{macrocode} +\cs_new_protected_nopar:Npn \@@_set_float: + { + \cs_set_eq:NN \@captype \l_@@_type_tl + \@@_float_pre_hook: + \@@_caption_hook: + \@floatboxreset + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_float_pre_hook:, \@@_float_pos_hook:} +% \begin{macrocode} +\cs_new_eq:NN \@@_float_pre_hook: \@@_empty: +\cs_new_eq:NN \@@_float_pos_hook: \@@_empty: +\@@_package_hook:nn { float } + { + \bool_new:N \g_@@_float_pos_bool + \cs_gset_protected_nopar:Npn \@@_float_pre_hook: + { \exp_args:No \@@_float_pre_aux:n { \l_@@_type_tl } } + \cs_new_protected:Npn \@@_float_pre_aux:n #1 + { + \cs_if_exist_use:cTF { fst@ #1 } + { + \@float@setevery {#1} + \bool_gset_true:N \g_@@_float_pos_bool + } + { \bool_gset_false:N \g_@@_float_pos_bool } + } + \cs_gset_protected_nopar:Npn \@@_float_pos_hook: + { + \bool_if:NT \g_@@_float_pos_bool + { \exp_args:No \@@_float_pos_aux:n { \l_@@_type_tl } } + } + \cs_new_protected:Npn \@@_float_pos_aux:n #1 + { + \hbox_gset:Nn \g_@@_stuff_box + { + \use:c { fst@ #1 } + \cs_set_eq:NN \@currbox \g_@@_stuff_box + \vbox_gset:Nn \g_@@_stuff_box + { \box_use_drop:N \g_@@_stuff_box } + \exp_args:Ne \float@makebox + { \dim_eval:n { \box_wd:N \g_@@_stuff_box } } + } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_floatrow_hook:} +% \begin{macrocode} +\cs_new_eq:NN \@@_floatrow_hook: \@@_empty: +\@@_package_hook:nn { floatrow } + { + \cs_gset_protected_nopar:Npn \@@_floatrow_hook: + { + \cs_set_eq:NN \@captype \l_@@_type_tl + \killfloatstyle + \FR@redefs + \dim_zero:N \FBc@wd + \exp_args:Ne \flrow@setlist + { + { \l_@@_type_tl } + { wrapfloat } + { wrap \l_@@_type_tl } + } + \FRifFBOX \@@@@setframe \relax \@@@@FStrue + \hbox_gset:Nw \g_@@_stuff_box + \tl_set:Nx \FBB@wd { \dim_use:N \l_@@_width_dim } + \FB@fs@wd + \dim_set:Nn \l_@@_width_dim { \FBo@wd } + } + \cs_gset_protected_nopar:Npn \@@_float_pre_hook: + { \the \FR@everyfloat } + \cs_gset_protected_nopar:Npn \@@_float_pos_hook: + { + \legacy_if:nTF { FBbuild } + { + \cs_set_eq:NN \@currbox \g_@@_stuff_box + \vbox_gset:Nn \g_@@_stuff_box + { \box_use_drop:N \g_@@_stuff_box } + \flrow@FB { \l_@@_width_dim } + } + { + \cs_undefine:N \flrow@typ@tmpset + \box_use_drop:N \g_@@_stuff_box + } + \hbox_gset_end: + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_caption_hook:} +% \begin{macrocode} +\cs_new_eq:NN \@@_caption_hook: \@@_empty: +\@@_package_hook:nn { caption } + { + \cs_gset_protected_nopar:Npn \@@_caption_hook: + { \exp_args:No \@@_caption_aux:n { \l_@@_type_tl } } + \cs_new_protected:Npn \@@_caption_aux:n #1 + { + \caption@settype {#1} + \caption@clearmargin + \caption@setoptions { wrap #1 } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{top} +% \begin{macrocode} +\keys_define:nn { wrapstuff } + { + abovesep .tl_set:N = \l_@@_abovesep_tl , + belowsep .tl_set:N = \l_@@_belowsep_tl , + leftsep .tl_set:N = \l_@@_leftsep_tl , + rightsep .tl_set:N = \l_@@_rightsep_tl , + linewidth .tl_set:N = \l_@@_linewidth_tl , + lines .tl_set:N = \l_@@_lines_tl , + width .tl_set:N = \l_@@_width_tl , + height .tl_set:N = \l_@@_height_tl , + hoffset .tl_set:N = \l_@@_hoffset_tl , + voffset .tl_set:N = \l_@@_voffset_tl , + type .tl_set:N = \l_@@_type_tl , + ratio .fp_set:N = \l_@@_ratio_fp , + top .int_set:N = \l_@@_top_int , + i .code:n = \@@_swap_true:N \c_true_bool , + o .code:n = \@@_swap_true:N \c_false_bool , + l .code:n = \@@_swap_false:N \c_zero_fp , + r .code:n = \@@_swap_false:N \c_one_fp , + c .code:n = \@@_swap_false:N \c_@@_c_fp , + column .choice: , + column/true .code:n = + { + \bool_set_true:N \l_@@_column_bool + \cs_set_eq:NN \@@_build_column: + \@@_build_column_strict: + } , + column/par .code:n = + { + \bool_set_true:N \l_@@_column_bool + \cs_set_eq:NN \@@_build_column: + \@@_build_column_fuzzy: + } , + column/false .code:n = + { \bool_set_false:N \l_@@_column_bool } , + hsep .code:n = + { + \tl_set:Nn \l_@@_leftsep_tl {#1} + \tl_set_eq:NN \l_@@_rightsep_tl + \l_@@_leftsep_tl + } , + vsep .code:n = + { + \tl_set:Nn \l_@@_abovesep_tl {#1} + \tl_set_eq:NN \l_@@_belowsep_tl + \l_@@_abovesep_tl + } , + unknown .code:n = + { \exp_args:No \@@_unknown_key:n { \l_keys_key_str } } , + leftsep .groups:n = main , + rightsep .groups:n = main , + hsep .groups:n = main , + linewidth .groups:n = main , + lines .groups:n = main , + column .groups:n = main , + hoffset .groups:n = main , + voffset .groups:n = main , + top .groups:n = stuff , + abovesep .groups:n = stuff , + belowsep .groups:n = stuff , + vsep .groups:n = stuff , + width .groups:n = stuff , + height .groups:n = stuff , + float .groups:n = stuff , + ratio .groups:n = ratio , + l .groups:n = ratio , + r .groups:n = ratio , + c .groups:n = ratio , + i .groups:n = ratio , + o .groups:n = ratio , + column .default:n = true , + column .initial:n = true , + abovesep .initial:n = \c_zero_dim , + belowsep .initial:n = \c_zero_dim , + leftsep .initial:n = 1em , + rightsep .initial:n = 1em , + linewidth .initial:n = \linewidth , + hoffset .initial:n = \c_zero_dim , + voffset .initial:n = \c_zero_dim , + width .initial:n = \c_zero_dim , + height .initial:n = \c_zero_dim , + ratio .initial:n = \c_one_fp , + abovesep .value_required:n = true , + belowsep .value_required:n = true , + leftsep .value_required:n = true , + rightsep .value_required:n = true , + linewidth .value_required:n = true , + width .value_required:n = true , + height .value_required:n = true , + hoffset .value_required:n = true , + voffset .value_required:n = true , + hsep .value_required:n = true , + vsep .value_required:n = true , + l .value_forbidden:n = true , + r .value_forbidden:n = true , + c .value_forbidden:n = true , + i .value_forbidden:n = true , + o .value_forbidden:n = true + } +\fp_const:Nn \c_@@_c_fp { 0.5 } +\cs_new_protected:Npn \@@_swap_true:N #1 + { + \bool_set_true:N \l_@@_swap_bool + \bool_set_eq:NN \l_@@_inner_bool #1 + \bool_if:NTF \l_@@_inner_bool + { \bool_set_false:N \l_@@_outer_bool } + { \bool_set_true:N \l_@@_outer_bool } + } +\cs_new_protected_nopar:Npn \@@_swap_false:N + { + \bool_set_false:N \l_@@_swap_bool + \fp_set_eq:NN \l_@@_ratio_fp + } +\cs_new_protected:Npn \@@_unknown_key:n #1 + { + \regex_match:NnTF \c_@@_integer_regex {#1} + { \int_set:Nn \l_@@_top_int } + { \@@_unknown_key_error:n } + {#1} + } +\regex_const:Nn \c_@@_integer_regex { \A \d+ \Z } +\cs_new_protected_nopar:Npn \@@_unknown_key_error:n + { \msg_error:nnn { wrapstuff } { unknown-key } } +\msg_new:nnnn { wrapstuff } { unknown-key } + { The~key~'#1'~is~unknown~and~is~being~ignored. } + { + The~package~wrapstuff~does~not~have~a~key~called~'#1'.\\ + Check~that~you~have~spelled~the~key~name~correctly. + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\wrapstuffset} +% \begin{macrocode} +\NewDocumentCommand \wrapstuffset { m } + { \keys_set:nn { wrapstuff } {#1} } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\wrapstuffclear} +% 保险起见,加入 \tn{par} 结束段落,同时结束 \env{wrapstuff@par} 环境。 +% \begin{macrocode} +\NewDocumentCommand \wrapstuffclear { } + { + \par + \@@_clear: + } +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\cs_if_exist:NTF \ProcessKeyOptions + { \ProcessKeyOptions [ wrapstuff ] } + { + \RequirePackage { l3keys2e } + \ProcessKeysOptions { wrapstuff } + } +% \end{macrocode} +% +% \begin{macrocode} +%</package> +% \end{macrocode} +% +% \end{implementation} +% +% \Finale +% +\endinput diff --git a/macros/latex/contrib/wrapstuff/wrapstuff.pdf b/macros/latex/contrib/wrapstuff/wrapstuff.pdf Binary files differnew file mode 100644 index 0000000000..c9cd89da98 --- /dev/null +++ b/macros/latex/contrib/wrapstuff/wrapstuff.pdf |