使用 tcolorbox 的不良空间因素

使用 tcolorbox 的不良空间因素

我正在尝试了解 tcolorbox 包的工作原理,但我从手册中复制/粘贴的一些代码有问题……老实说,我不明白哪里出了问题。你能帮帮我吗?

这是我的代码:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xargs}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage[french]{babel}
\usepackage{keyval,xparse}
\usepackage{amsmath}
\usepackage{amssymb}

\newcounter{theoreme}
\makeatletter
\define@key{th}{titre}{\def\mm@titre{#1}}
\define@key{th}{nom}{\def\mm@nom{#1}}
\DeclareDocumentEnvironment{th}{m}
{\begingroup%
  % ========= KEY DEFAULTS + new ones =========
  \setkeys{th}{titre={Théorème},nom={},#1}
  \stepcounter{theoreme}
  \begin{tcolorbox}[title={\mm@titre{} \thechapter .\thetheoreme{} : \mm@nom},enhanced,
attach boxed title to top left=
{xshift=-2mm,yshift=-2mm},
boxed title style={size=small,colback=gray}]
}
{\end{tcolorbox}
\endgroup}
\makeatother

\tcbuselibrary{skins,xparse,listings,theorems}
\makeatletter
\NewTColorBox
[auto counter,number within=section]{exercise}{+O{}}{
%
enhanced,colframe=green!20!black,colback=yellow!10!white,coltitle=green!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
\shade[inner color=green!80!yellow,outer color=yellow!10!white]
(interior.north west) circle (2cm);
\draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
(interior.south west) grid (interior.north east);
\end{tcbclipinterior}},
title={Exercice~
\thetcbcounter
:},
label={exercise@
\thetcbcounter
},
attach title to upper=\quad,
after upper={\par\hfill\textcolor{green!40!black}
%
{\itshape Solution à la page~\pageref{solution@
\thetcbcounter
}}},
lowerbox=ignored,
savelowerto=solutions/exercise-
\thetcbcounter
.tex,
record={\string\solution{
\thetcbcounter
}{solutions/exercise-
\thetcbcounter
.tex}},
#1
}
\NewTotalTColorBox
{\solution}{mm}{
%
enhanced,colframe=red!20!black,colback=yellow!10!white,coltitle=red!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
\shade[inner color=red!50!yellow,outer color=yellow!10!white]
(interior.north west) circle (2cm);
\draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
(interior.south west) grid (interior.north east);
\end{tcbclipinterior}},
title={Solution of Exercise~\ref{exercise@#1} on page~\pageref{exercise@#1}:},
phantomlabel={solution@#1},
attach title to upper=\par,
}{\input{#2}}
\tcbset
{no solution/.style={no recording,after upper=}}
\makeatother


\begin{document}
\chapter{test}
\begin{th}{}
Lorem
\end{th}
\section{re}
\begin{exercise}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
\tcblower
The derivative is:
\begin{align*}
f
'
(x) &= \left( \sin((\sin x)^2) \right)
'
=\cos((\sin x)^2) 2\sin x \cos x.
\end{align*}
\end{exercise}

\end{document}

这会导致编译时出现错误行 106,原因如下:!错误的空间因子 (0)。 \@savsf \end{exercise} 如果我不使用以下行,错误就会消失 \tcblower......

答案1

复制和粘贴时出现错误的换行符,例如在savelowerto键的值中。

还要确保该solutions文件夹存在。

相关内容