Page-breakable Box in TeX

引入

尽管常见的 tcolorbox, framed, boites 等宏包提供了一个可跨页的盒子,但是这个跨页的原理是什么? 到底怎么实现的? TeX SE 上的如下问题: breakable box 有一个关于“可跨页盒子” 的实现代码(这里是简化后代码):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\pagestyle{empty}

\newbox\boxhead
\newbox\boxtail
\newbox\boxtemp

\newdimen\dimtemp

\def\boxsplit{%
% total height of original box
\dimtemp\ht\boxtail
\advance\dimtemp\dp\boxtail
% split original box in order to retrieve its first line
\setbox\boxhead\vsplit\boxtail to 0pt
% fix the height of the first line
\setbox\boxhead\vbox{\unvbox\boxhead}%
% restore original size
\setbox\boxtemp\vbox{\copy\boxhead\copy\boxtail}%
\advance\dimtemp-\ht\boxtemp
\advance\dimtemp-\dp\boxtemp
\advance\dimtemp\dp\boxhead
\dp\boxhead\dimtemp
}

\newenvironment{mybox}{%
\ifhmode\par\fi
\setbox\boxtail\vbox\bgroup
}{%
\egroup
{%
\noindent
\fboxsep 0pt
\splittopskip 0pt
\baselineskip 0pt
\lineskiplimit 0pt
\lineskip 0pt
\vfuzz\maxdimen
\leavevmode
\loop
\ifvoid\boxtail
\else
\boxsplit
\hbox to \linewidth{\box\boxhead}\hfil%
\hfil
\repeat
}%
}

\begin{document}

\begin{mybox}
\lipsum[1-5]
\end{mybox}

\end{document}

目标

我想要根据上述的原理,自己定义一个对应的可跨页的盒子,然后把这个盒子的声明封装为一个命令,方便在之后的模板 zlatex 中调用.


Page-breakable Box in TeX
https://zongpingding.github.io/2024/06/15/breakable_box/
Author
Eureka
Posted on
June 15, 2024
Licensed under