5

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

  • 4
    Also, I have asked you multiple times at other occasions to remove those special font settings since most of us do not have such fonts installed. Neither polyglossia nor xelatex settings are needed here –  Feb 25 '18 at 22:29
  • 3
    The manual of tcolorbox clearly states that nesting a breakable box in a breakable box will be automatically ignored, so the inner box won't be breakable any longer –  Feb 25 '18 at 22:41
  • 1
    @ChristianHupfer That sounds like an answer, doesn't it? 'Can't be done' is perfectly legitimate, if true - indeed, the best answer possible. – cfr Feb 26 '18 at 00:43
  • @cfr: It's would be a very, very, very (repeat 100 times ;-)) disappointing answer, however... –  Feb 26 '18 at 00:48
  • @ChristianHupfer You're reason. I'm sorry but I always forget this question of font. I do it in order to put the question in real conditions because the right to left languages can reserve some surprises ! ok Neither polyglossia nor xelatex settings are not needed here but it's available for all the users, and the problem is for the arabic font, which is not available, so I had to choose a useful font for all users. – Faouzi Bellalouna Feb 26 '18 at 02:44
  • For the statement that a breakable box can't be used inside another breakable box I really did not know that, even that I have read some parts of the manual several times, and I'll search for another solution for my macro inside the box. Any idea for that? Thanks – Faouzi Bellalouna Feb 26 '18 at 02:50
  • 2
    I agree with @cfr. I think that your comment is an answer for my problem, because it's useful for me, the author of the question, and it solves my problem, even if it seems to be a simple or disappointing answer, because repeated several times. It's the first time that I know this information, and your help is welcome for me. Many thanks – Faouzi Bellalouna Feb 26 '18 at 03:00
  • @ChristianHupfer ^^ I thought and think it is a worthwhile answer because 'can't work this way' is really useful: it tells me something is a dead end and I should not waste my energies on it, but better rethink what I want to do or how I want to do it. – cfr Feb 26 '18 at 03:28
  • @FaouziBellalouna It is not just the Arabic font. Not everyone has Arial, Times New Roman and Courier New. Windows users, sure, but that leaves a lot of people unable to compile your code, especially on a site like this. Not one of your font settings works for me, for example, because I don't have any of those fonts and LuaTeX, say, gives me an error for every single one of your configuration lines. – cfr Feb 26 '18 at 03:32
  • @cfr ok Many thanks. can you tell me a "universal" fonts, what I can use for my MWE ? – Faouzi Bellalouna Feb 26 '18 at 05:55
  • @FaouziBellalouna: Just omit any specific font settings -- it's not relevant for such questions. No \setmainfont etc. stuff. Just remove them –  Feb 26 '18 at 09:57

1 Answers1

9

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.