%% test-basic.tex
%% ==============
%% Typesetting test for every engine: breakable boxes inside breakable
%% boxes.
%%
%%   pdflatex test-basic.tex   (or xelatex / lualatex)
%%   platex  test-basic.tex && dvipdfmx test-basic
%%   uplatex -jobname=test-basic "\def\CLS{ujarticle}\input test-basic"
%% The class is article by default; set \CLS for another one.  With
%% pTeX the class option dvipdfmx is given.
%%
%% What is covered:
%%   * a breakable box inside a breakable box, broken across several
%%     pages, with a list and a display inside;
%%   * a breakable box inside this one, also broken, with an ordinary
%%     box inside;
%%   * a small box with a title, a box of the enhanced skin;
%%   * a box that is the first thing in the outer box and has a text
%%     color of its own, a box right after it, a box in an item of a
%%     list, a box defined by \newtcolorbox;
%%   * a box in the lower part of the outer box;
%%   * a breakable box in a minipage and in an unbreakable box: these
%%     do not flow;
%%   * boxes in an outer box that is not broken, one with a lower part;
%%   * boxes with a lower part that are broken in the upper part and
%%     in the lower part, one of the bicolor skin and with a text color
%%     of the lower part;
%%   * a box that is the last thing in a box inside: of one line and
%%     of the enhanced skin with a borderline, broken across pages, at
%%     the end of the upper part and of the lower part, and four boxes
%%     inside each other that end together;
%%   * a box that is the first thing in a box inside, near the bottom
%%     of a page (at several distances from it, \TNBchain): the two
%%     boxes start on the same page.
%%
%% What to check:
%%   * TNB-RESULT OK, and no error, warning or overfull box;
%%   * in the PDF, the frames are behind their text and open where the
%%     outer box is broken; the segmentation line is between the upper
%%     and the lower part.
\ifdefined\CLS\else\def\CLS{article}\fi
\ifdefined\ptexversion\def\CLSOPT{dvipdfmx}\else\def\CLSOPT{}\fi
\expandafter\documentclass\expandafter[\CLSOPT]{\CLS}
\usepackage{tcbnestbreak}
\input{test-common}
\newtcolorbox{note}[2][]{breakable, colback=orange!10,
  colframe=orange!70!black, title={#2}, #1}
%% \TNBchain{<length>}: on a new page, an outer box whose text leaves
%% about <length> of the page, then a box with a box and another box
%% as the first things in it, the last one also at the start of the
%% lower part
\newcommand\TNBchain[1]{%
  \newpage
  \begin{tcolorbox}[breakable, title=Outer box: boxes that start together]
  \vspace*{\dimexpr\textheight-#1\relax}
  The bottom of the page is #1 away.
  \begin{note}{The box around}
  \begin{note}{A box, the first thing in it}
  \begin{tcolorbox}[breakable, colback=white]
  The innermost box. \TNBfiller{4}
  \end{tcolorbox}
  \TNBfiller{4}
  \end{note}
  \tcblower
  \begin{note}{A box, the first thing in the lower part}
  \TNBfiller{4}
  \end{note}
  \end{note}
  \TNBtogether{0,2,3}
  \end{tcolorbox}}
\begin{document}
\section*{Breakable boxes inside breakable boxes}

\TNBfiller{20}

\begin{tcolorbox}[breakable, title=Outer box 1]
\TNBfiller{8}
\begin{tcolorbox}[breakable, colback=yellow!20, colframe=blue!60!black,
  title=Box 1]
Start of box 1. \TNBfiller{20}
\begin{itemize}
\item An item. \TNBfiller{6}
\item Another item with a display
  \[ a^2 + b^2 = c^2 \]
  and text after it.
\end{itemize}
\begin{tcolorbox}[breakable, colback=red!10, colframe=red!60!black,
  title=Box 2 in box 1]
Start of box 2. \TNBfiller{60}
\begin{tcolorbox}[colback=white, title=An ordinary box in box 2]
\TNBfiller{4}
\end{tcolorbox}
\TNBfiller{60}
End of box 2.
\end{tcolorbox}
\TNBfiller{30}
End of box 1.
\end{tcolorbox}
\TNBfiller{8}
\begin{tcolorbox}[breakable, colback=green!10, title=Box 3]
A small box.
\end{tcolorbox}
\TNBfiller{30}
\begin{tcolorbox}[breakable, enhanced, colback=cyan!10,
  colframe=cyan!50!black]
Start of box 4, of the enhanced skin. \TNBfiller{120}
End of box 4.
\end{tcolorbox}
\TNBfiller{8}
\end{tcolorbox}

\begin{tcolorbox}[breakable, title=Outer box 2]
\begin{tcolorbox}[breakable, colback=yellow!20, coltext=red!70!black]
Start of box 5, the first thing in the outer box, with red text.
\TNBfiller{120}
End of box 5.
\end{tcolorbox}
\begin{note}{Box 6, right after box 5}
\TNBfiller{8}
\end{note}
\begin{enumerate}
\item In a list. \TNBfiller{4}
\begin{note}[coltext=blue!60!black]{Box 7, in an item}
Blue text. \TNBfiller{120}
End of box 7.
\end{note}
\item The second item.
\end{enumerate}
\begin{minipage}{\linewidth}
\begin{tcolorbox}[breakable, colback=gray!20,
  title=In a minipage: an ordinary box]
This box does not flow.
\end{tcolorbox}
\end{minipage}
\tcblower
The lower part of the outer box. \TNBfiller{8}
\begin{note}{Box 8, in the lower part}
\TNBfiller{120}
End of box 8.
\end{note}
\TNBfiller{8}
\end{tcolorbox}

\begin{tcolorbox}[title=An unbreakable outer box]
\begin{tcolorbox}[breakable, colback=gray!20,
  title=In an unbreakable box: an ordinary box]
This box does not flow.
\end{tcolorbox}
\end{tcolorbox}

\begin{tcolorbox}[breakable, title=Outer box 3 (not broken)]
\begin{note}{Box 9}
A small box.
\end{note}
\begin{tcolorbox}[breakable, colback=green!10, title=Box 10]
The upper part.
\tcblower
The lower part.
\end{tcolorbox}
\end{tcolorbox}

\begin{tcolorbox}[breakable, title=Outer box 4]
\TNBfiller{8}
\begin{tcolorbox}[breakable, colback=yellow!20, title=Box 11,
  collower=blue!60!black]
The upper part. \TNBfiller{120}
\tcblower
The lower part, with blue text. \TNBfiller{8}
\end{tcolorbox}
\TNBfiller{8}
\begin{tcolorbox}[breakable, bicolor, colback=red!10, colbacklower=cyan!15,
  title=Box 12, collower=red!60!black]
The upper part. \TNBfiller{8}
\tcblower
The lower part, with red text. \TNBfiller{120}
\end{tcolorbox}
\TNBfiller{8}
\end{tcolorbox}

\begin{tcolorbox}[breakable, title=Outer box 5: a box at the end of a box]
\TNBfiller{4}
\begin{note}{Box 14}
\TNBfiller{2}
\begin{tcolorbox}[breakable, enhanced, colback=white,
  colframe=blue!50!black, borderline west={6mm}{0pt}{blue!20}]
Box 13, of one line, the last thing in box 14.
\end{tcolorbox}
\end{note}
\TNBfiller{4}
\begin{note}{Box 16}
\TNBfiller{4}
\begin{tcolorbox}[breakable, colback=green!10, title=Box 15]
Start of box 15. \TNBfiller{120}
End of box 15, the last thing in box 16.
\end{tcolorbox}
\end{note}
\TNBfiller{4}
\begin{tcolorbox}[breakable, colback=yellow!20, title=Box 19]
The upper part.
\begin{note}{Box 17, the last thing in the upper part}
\TNBfiller{4}
\end{note}
\tcblower
The lower part.
\begin{note}{Box 18, the last thing in the lower part}
\TNBfiller{4}
\end{note}
\end{tcolorbox}
\begin{tcolorbox}[breakable, colback=red!10, title=Box 23]
\begin{note}{Box 22}
\begin{tcolorbox}[breakable, colback=cyan!10]
\begin{tcolorbox}[breakable, colback=white]
Box 20, of one line, in box 21: four boxes end here.
\end{tcolorbox}
\end{tcolorbox}
\end{note}
\end{tcolorbox}
\TNBfiller{4}
\end{tcolorbox}

\TNBchain{70pt}
\TNBchain{85pt}
\TNBchain{100pt}
\TNBchain{115pt}
\TNBchain{130pt}
\TNBchain{145pt}

\TNBexpect{47}{10}
\end{document}
