1 % framed.sty v 0.3 29-Jul-2001
2 % Copyright (C) 1992-2001 by Donald Arseneau
3 % These macros may be freely transmitted, reproduced, or modified
4 % provided that this notice is left intact.
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 % Create framed or shaded regions that can break across pages using
8 % \begin{framed} ... \end{framed} -- ordinary frame box (box at margin)
9 % \begin{shaded} ... \end{shaded} -- shaded background (into margin)
11 % The "framed" environment puts the text into "\fbox" with the
12 % settings "\fboxrule=\FrameRule" and "\fboxsep=\FrameSep".
13 % You can change these lengths (using "\setlength") and you
14 % can even change the definition of "\FrameCommand" to use
17 % In fact, the "shaded" environment just redefines "\FrameCommand"
18 % to use "\colorbox{shadecolor}" (and you have to define the
19 % color "shadecolor").
21 % The contents of the framed regions are restricted:
22 % Floats, footnotes, marginpars and head-line entries will be lost.
23 % (Some of these may be handled in a later version.)
24 % This package will not work with the page breaking of multicol.sty,
25 % or other systems that perform column-balancing.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 \ProvidesPackage{framed
}[2001/
07/
29 v
0.3: framed text with page breaks
]
30 \newenvironment{framed
}% using default \FrameCommand
31 {\fram@d
{\advance\hsize-
\width}}%
34 \newenvironment{shaded
}{%
35 \def\FrameCommand{\colorbox{shadecolor
}}%
39 \chardef\FrameRule=
\catcode`\|
% for debug
40 \catcode`\|=
\catcode`\
% %
45 \penalty\@M
% updates \page parameters
46 \ifdim\pagefilstretch=
\z@
\ifdim\pagefillstretch=
\z@
\if@nobreak
\else
47 \vskip-
\skip@
\penalty-
30 \vskip\skip@
51 % measure added width and height; call result \width and \height
52 \setbox\z@
\vbox{\vskip-
1in
\hbox{\hskip-
1in
53 \FrameCommand{\hbox{\vrule \@height
1in \@width
1in
}}}\vskip\z@skip
}%
54 \def\width{\wd\z@
}\def\height{\ht\z@
}%
55 \edef\fb@frw
{\the\width}\edef\fb@frh
{\the\height}%
56 \penalty\@M
\vskip 2\baselineskip \vskip\height % clear out pending page break
57 \penalty\@M
\vskip -
2\baselineskip \vskip-
\height
58 \penalty\@M
% updates \pagetotal
60 \setbox\@tempboxa
\vbox\bgroup
61 #1% Modifications to \hsize (can use \width and \height)
62 \textwidth\hsize \columnwidth\hsize \@parboxrestore
66 \kern\z@
\penalty-
100 % put depth into height
68 \begingroup \put@frame
\endgroup
71 % \put@frame takes the contents of \@tempboxa and puts all, or a piece,
72 % of it on the page with a frame (\FrameCommand). It recurses until
73 % all of \@tempboxa has been used up. (\@tempboxa must have zero depth.)
76 |
\message{=============== Entering putframe ====================
}%
77 \ifdim\pagegoal=
\maxdimen \pagegoal\vsize \fi
78 \dimen@
\pagegoal \advance\dimen@-
\pagetotal % natural space left on page
79 \ifdim\dimen@>
2\baselineskip % there's appreciable room left on the page
81 \advance\dimen@
.8\pageshrink\relax % maximum space available on page
83 \ifdim\dimen@>
\ht\@tempboxa
% whole box does fit
84 |
\message{Box of size
\the\ht\@tempboxa
\space fits in
\the\dimen@:
85 |
\string\pagetotal=
\the\pagetotal,
86 |
\string\pagegoal=
\the\pagegoal,
87 |
\string\pagestretch=
\the\pagestretch,
88 |
\string\pageshrink=
\the\pageshrink.
}%
89 \else % box must be split
90 |
\message{Box of size
\the\ht\@tempboxa
\space
91 | must be split to fit in
\the\dimen@:
}%
92 |
\message{\string\pagetotal=
\the\pagetotal,
93 |
\string\pagegoal=
\the\pagegoal,
94 |
\string\pagestretch=
\the\pagestretch,
95 |
\string\pageshrink=
\the\pageshrink,
96 |
\string\fb@frh=
\fb@frh.
\space}
97 \setbox\@tempboxa
\vbox{% simulate frame and flexiblity of the page:
98 \vskip \fb@frh \@plus
\pagestretch \@minus
.8\pageshrink
99 \kern137sp\kern-
137sp
\penalty-
30
101 \boxmaxdepth\z@
\splittopskip\z@
102 |
\message{Box of size
\the\ht\@tempboxa
\space is split to
\the\dimen@.
}%
103 \setbox\tw@
\vsplit\@tempboxa to
\dimen@
104 \setbox\tw@
\vbox{\unvbox\tw@
}% natural-sized
105 |
\message{Natural height of split box is
\the\ht\tw@.
}%
106 % If the split-to size > (\vsize-\topskip), then set box to full size
108 \advance\dimen@
\topskip
109 \expandafter\endgroup
110 \ifdim\dimen@>
\pagegoal
111 |
\message{Frame is big -- Use up the full column.
}%
113 \advance\dimen@ii -
\topskip
114 \advance\dimen@ii
\FrameHeightAdjust\relax
116 \advance\dimen@
.8\pageshrink
117 \ifdim\ht\tw@>
\dimen@ii
118 |
\message{Box too tall; rebox it to
\the\dimen@.
}%
120 \else % use natural size
124 \advance\dimen@ii -
\fb@frh
125 \setbox\tw@
\vbox to
\dimen@ii
\bgroup
126 \vskip -
\fb@frh \@plus-
\pagestretch \@minus-
.8\pageshrink
128 \ifdim\lastkern=-
137sp
% whole box went to next page
129 |
\message{box split at beginning!
}%
130 \egroup \eject % (\vskip for frame size was discarded)
134 \ifvoid\@tempboxa
% it all fit after all
135 |
\message{box split at end!
}%
136 \setbox\@tempboxa
\box\tw@
137 \else % it really did split
138 |
\message{box split as expected. Its reboxed height is
\the\ht\tw@.
}%
139 \centerline{\FrameCommand{\box\tw@
}}%
145 \ifvoid\@tempboxa
\else
146 \centerline{\FrameCommand{\box\@tempboxa
}}%
147 \nointerlineskip \null
148 \penalty-
30 \vskip\topsep
152 \vbox to
\FrameHeightAdjust{}% get proper baseline skip from above.
153 \penalty\@M
\nointerlineskip
154 \vskip-
\FrameHeightAdjust
155 \penalty\@M
} % useful for tops of pages
157 \catcode`\|=
\FrameRule
158 \providecommand\FrameCommand{\fboxrule=
\FrameRule \fboxsep=
\FrameSep \fbox}
159 \newdimen\FrameRule \FrameRule=
\fboxrule
160 \newdimen\FrameSep \FrameSep =
3\fboxsep
162 % Height of frame above first baseline when frame starts a page:
163 \providecommand\FrameHeightAdjust{6pt
}
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%