My MWE below should not be simplified anymore to avoid breaking my real scenario. The settings are tightly coupled.
\documentclass{article}
\usepackage[a6paper,vmargin=15mm,hmargin=5mm]{geometry}
\usepackage{times}
\usepackage{helvet}
\usepackage{courier}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\allowdisplaybreaks
\usepackage{amssymb}% for \mathbb
\usepackage{tcolorbox}
\usepackage{cancel}
\usepackage{microtype}
\tcbuselibrary{breakable}
\newcounter{exercise}[subsection]
\makeatletter
\@addtoreset{exercise}{section}
\renewcommand{\theexercise}{%
\ifnum\value{subsection}>0\relax
\thesubsection
\else
\thesection
\fi
.\arabic{exercise}%
}
\newenvironment{exercise}
{\par\smallskip\refstepcounter{exercise}
\begin{tcolorbox}[breakable,title=Exercise \theexercise,left=0mm,lefttitle=2mm,shrink break goal=18pt]\ignorespaces}
{\end{tcolorbox}\par\smallskip\ignorespacesafterend}
\makeatother
\def\IncludeGraphics{\rule{4cm}{1.5cm}}
\begin{document}
\begin{exercise}
xxxxxxxx xxxxxxxxx xxxxxxx.
\begin{enumerate}
\item $-2x>4$
\item $7x-1<13$
\item $\tfrac{x-1}{2}\leq\tfrac{x+1}{3}$
\item $x^2 -5x +6 \geq 0$
\item $x^2 < 16$
\item $(x-1)^2(x+2)^3 > 0$
\item $\frac{(x-1)^2}{(x+2)^3} \geq 0$
\end{enumerate}
\tcblower
\begin{enumerate}
\item
$\!
\begin{aligned}[t]
-2x &>4\\
x &< \frac{4}{-2} &&\text{\parbox{5cm}{\color{red}\scriptsize xxxx xxxxx xxxx xxxxxx $-2$. xxxxx xxxxxxxxxxxxxx xxxxx xxxxxxx xxxx xxxxxxx xxxx xxxxxxx xxxxxx xxxxxxxx xxxxxxx}}\\
x &< -2
\end{aligned}
$
\item
$\!
\begin{aligned}[t]
7x -1 &< 13\\
7x &< 13 +1\\
7x &< 14\\
x &< \frac{14}{7}\\
x &< 2
\end{aligned}
$
\item
$\!
\begin{aligned}[t]
\frac{x-1}{2} &\leq \frac{x+1}{3}\\
\frac{x-1}{2} \times 2 \times 3 &\leq \frac{x+1}{3} \times 2 \times 3\\
\frac{x-1}{\bcancel{2}} \times \bcancel{2} \times 3 &\leq \frac{x+1}{\bcancel{3}} \times 2 \times \bcancel{3}\\
3(x-1) &\leq 2(x+1) \\
3x-3 &\leq 2x +2\\
3x-2x &\leq 2 +3\\
x &\leq 5
\end{aligned}
$
\item
xxxxxxxx xxxx xxxxx xxxx xxxxxx xxx xxx xxxxxxxxx xxxxxxxx xx xxxx xxxx.
\begin{align*}
x^2 -5x +6 &\geq 0\\
x^2 -3x -2x +6 &\geq 0\\
x(x-3) -2(x-3) &\geq 0\\
(x-3)(x-2) &\geq 0
\end{align*}
{\color{red}xxxxxx xxxxxxx xxxxxxx xxx!
\begin{align*}
x-3&\geq 0 &&\text{or} & x-2&\geq 0\\
x&\geq 3 && \text{or} & x&\geq 2
\end{align*}\par}
xxxxxxxxxxx xxxxx xxxxxxxx~\ref{enum:xxxxxxx-xxxxxxxxxxxxxx}. xxxxxxx xxx xxxxxx xxxxxxxxxx.
\begin{center}
\IncludeGraphics
\end{center}
xxxxxxx xxxxxxxx xxxxxx $\{\, x\in \mathbb{R} \mid x\leq 2\vee x\geq 3\,\}$ xxxxxx xxxxxx $\vee$ xxxxxx ``xxxx''.
\item
xxxxxxxx xxxx xxxxx xxxx xxxxxx xxx xxxxxxxx xxxxxxxxx xxxx xxxx.
\begin{align*}
x^2 &< 16\\
x^2 -16 &< 0\\
x^2 -4x +4x -16 &< 0\\
x(x-4) +4(x-4) &< 0\\
(x-4)(x+4) &< 0
\end{align*}
{\color{red}xxxxxx xxxxxxxxx xxxxxxx xxxxxxxxxxx
\begin{align*}
x-4 &<0 &&\text{or} & x+4 &< 0\\
x &<4 &&\text{or} & x &<-4
\end{align*}\par}
xxxxxxxxxxxxx xxxxxxxxx xxxxxxxx~\ref{enum:xxxxxxx-xxxxxxxxxxx}. xxxxxxxxx xxxxxxxx xxxxxx xxxxxxxxxx.
\begin{center}
\IncludeGraphics
\end{center}
xxxxxxx xxxxxx xxxxxxx $\{\, x\in \mathbb{R} \mid x > -4 \wedge x < 4\,\}$ xxxxxxx xxxxxxxx $\wedge$ xxxx ``xxx''. xxxxxxxxx $\{\, x\in \mathbb{R} \mid x > -4 \wedge x < 4\,\}$ xxxxxx xxxxxxxxxx xxxxxxxxxx $\{\, x\in \mathbb{R} \mid -4 < x < 4\,\}$.
\item
xxxxxxxx xxxxx xxxxxxx xxxxxx xxxxxxxxxx xxx xxx xxxxx xxxxx xxxxxxx xxxxxxx xxxxxxx xxxxx xxxxx xxxx xxxxxxxxxx xx xxxxxxxx.
\begin{align*}
(x-1)^2(x+2)^3 > 0
\end{align*}
xxxxxxxxxxxxx xxxxxxxxx xxxxxxxx~\ref{enum:xxxxxxx-xxxxxxxxxxx}. xxxxxxxxx xxxxxxxx xxxxxx xxxxxxxxxx.
\begin{center}
\IncludeGraphics
\end{center}
xxxxxxxxx xxxxxxx xxxxxxxx $\{\, x\in \mathbb{R} \mid x > -2 \wedge x \ne 1\,\}$ xxxxx xxx $\wedge$ xxxxxxx ``xxxx''.
%
\item
xxxxxxxxx xxxx xxxxx xxxxx xxxxxx xxx xxx xxxxxxx xxxx xxxxx. xxxxx xx xxxx xxxxx xxxxxxx xxxxx xxx xxxxx xxxxx xxx.
\begin{align*}
\frac{(x-1)^2}{(x+2)^3} \geq 0\\
(x-1)^2(x+2)^3 \geq 0 && \text{xxxx $x\ne -2$}
\end{align*}
xxxxxxxxxxxxx xxxxxxxxx xxxxxxxx~\ref{enum:xxxxxxx-xxxxxxxxxxx}. xxxxxxxxx xxxxxxxx xxxxxx xxxxxxxxxx.
\begin{center}
\IncludeGraphics
\end{center}
xxxxxxx xxxxxx xxxxxx $\{\, x\in \mathbb{R} \mid x > -2 \,\}$.
\end{enumerate}
\end{exercise}
\end{document}
Problems:
- There are unwanted blank pages.
- The inconsistent color scope occurs. The continued parts in different broken page loses the color scope of the previous pages.
- There is an unwanted orphan/widow effect.
- The last
\item
cannot be removed without affecting the color scoping.
How to fix these issues?
Edit:
The problem fixed! I am trying to find another bug. :-)
\ignorespaces
at end. – Click Me May 9 at 22:18\makeatletter...\makaatother
, the code snippet above was extracted from my own package. How does he fix it? Will you inform him about this issue? – Click Me May 9 at 22:22