# Bad Space Factor using tcolorbox

I'm trying to understand how the package tcolorbox works, and I have an issue with some code I just copied/pasted from the manual.... And I frankly don't understand where it went wrong. Could you help me please ?

This is my code :

\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}
(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
},
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}
(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}


This leads to an error line 106 when compiling, given by : ! Bad space factor (0). \@savsf \end{exercise} The error disapears if I don't use the \tcblower line...

• You have faulty line breaks, e.g. in the value for the savelowerto keys. Also ensure that the solutions folder exists. – Ulrike Fischer May 11 '18 at 13:41
• Being the proof that ; one, copy/pasting is not a panacea, and second, I am an idiot. Thanks a lot ! – T. Gaspard May 11 '18 at 13:52
• @UlrikeFischer Would you like to add an answer? – CarLaTeX May 11 '18 at 19:03

You have faulty line breaks from the copy&paste, e.g. in the value for the savelowerto keys.
Also ensure that the solutions folder exists.