[Tex/LaTex] Breakable box in breakable box with tcolorbox

tcolorbox

Defining exercises and using some macros with tcolorbox, I noted that, if I insert the macro including tcolorbox inside the exercise produced with tcolorbox too, the breakable option has not effect so the boxes doesn't break. How can I make this option effective for this case of "box-in-box" ?

I give an MWE, of my .tex file, where one can see that the boxes break, in the pages 1,2,3, and when the box refuses to break, in the page 4:

\documentclass{book}

\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,breakable}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
\newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}

\usepackage{polyglossia}
\setdefaultlanguage{arabic}

\newcounter{example}[section]
\renewcommand{\theexample}{\arabic{example}}
\newcommand{\examplelabel}{%
{\bfseries\large
Ex.
\LR{\theexample}
}}

\newtcolorbox[use counter=example]{example}[1][]{enhanced jigsaw,breakable,
  colback=white, colframe=red, arc=0mm,
  rightrule=0mm, leftrule=0mm,toprule=0mm,
  top=1mm, bottom=1mm, left=0mm, right=0mm,
  colbacktitle=green, coltitle=black,
  title=#1,
  extrude right by=-5.5mm,
  before upper={\parshape 4
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize},
  code={\ifstrempty{#1}{}{%
    \tcbset{
      before upper={\parshape 3
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize},
    }}},
  underlay unbroken and first={%
  \node[fill=yellow, draw=red, line width=1.5pt, below right, minimum height=3em, text width=.8cm, align=center] at ([xshift=-.1mm]frame.north east) {\examplelabel};
  \draw [red,line width=.5mm]([yshift=.25mm]frame.north west)--+(\linewidth,0);
  },
  underlay unbroken and last={%
  \draw [red,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
  },
}

\tikzstyle{titlewhite} =
    [draw=black, thick, scale=.9, fill=white,% 
        line width=0.3pt, text=black, rectangle,
        font=\normalsize,
        left, minimum height=.5cm]

\newenvironment{blankbox}[2][]{%
\begin{tcolorbox}[enhanced jigsaw,breakable,
colback=white, colframe=white, arc=0mm,
  top=0mm, bottom=0mm, left=2mm, right=2mm,
colframe=black,
top=5mm,
%bottom=6mm,
enlarge top by=\baselineskip/2+1mm,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,
overlay unbroken and first={%
\node[titlewhite]
at ([xshift=-1cm]frame.north east)
{\large \RL{#2}};},
before=\par\smallskip\centering,
coltitle=black, 
  fonttitle=\large,%%fontupper=\large,
rightrule=0mm, 
borderline east={0pt}{0pt}{white},
leftrule=0.2mm,toprule=0.2mm,bottomrule=0.2mm,
]}{%
\end{tcolorbox}}

\begin{document}
\noindent
\LR{
In this document, the text would be written in arabic, a right-to-left language
}

\begin{example}[\hspace*{2.5mm}\LR{A broken example}]
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
%%\vspace*{10cm}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\end{example}



\begin{blankbox}{\LR{A broken box}}
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
%%\vspace*{10cm}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\end{blankbox}

\begin{example}[\hspace*{2.5mm}\LR{A non-broken example}]
\vspace*{5mm}
\begin{blankbox}{Title}
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
%%\vspace*{10cm}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\end{blankbox}
\end{example}


\end{document}

and it's compilation with xelatex:

enter image description here
enter image description here
enter image description here

enter image description here

Best Answer

Citing the tcolorbox manual (page 365 of current version 4.15):

You can nest an unbreakable tcolorbox inside another tcolorbox, even inside a breakable one. But you cannot not nest a breakable box inside a breakable box. The /tcb/breakable key for a nested box is ignored automatically, i. e. inner boxes are always unbreakable.

After all, in the unlikely case you really want to have the nested box to be breakable, use /tcb/enforce breakable for the nested box. But, a breakable box inside a breakable box will usually give a mess.

So even if there is a enforce breakable option, this is not advisable. (I've tried on other occasions and the result is really messy)

Update 2019/02/15

The (most likely) wrong wording 'cannot not' is still in the text.

Related Question