I want to \vsplit
a box with quite arbitrary content. If the content does some color changes, strange things happen.
The following MWE demonstrates the problem. The example text changes font and color of the second paragraph. When this paragraph is split, the red color bleeds outside the box, see inter text
while the font change is restricted to the box.
By the way: setting the color to black
before the inter text
worsen the problem, because then the third paragraph and everything after the second box is painted red.
How do I have to adapt the \splitmytext
macro (and maybe the \savemytext
macro) to avoid this color bleeding problem?
\documentclass{article}
\usepackage{xcolor,lipsum}
\newbox\mwebox
\newbox\firstbox
\newcommand{\savemytext}[2]{%
\setbox\mwebox\vbox{\hsize=#1\relax#2}}
\newcommand{\splitmytext}[1]{%
\setbox\firstbox\vsplit\mwebox to #1}
\begin{document}
\savemytext{10cm}{%
\lipsum[1]
{\itshape\bfseries\color{red}
\lipsum[2]
}
\lipsum[3]
}
\splitmytext{7cm}
\fbox{\box\firstbox}
inter text
\fbox{\box\mwebox}
after text
\end{document}
\egroup\endgroup
. i can't think, off hand, of a way of getting the end-grouping into the end of the top bit, and then add a colour command at the beginning of the bottom bit.