2

Im stuck with a color issue inside a tcolorbox. I have two versions of a document : one for students, the other one for me.

The student version have blanks, which are filled in mine. In fact, those blanks are written but in white in the students version. My problem is the following : all those blanks are in a tcolorbox, which sometimes breaks page, and when this happen, the white color is lost and the text becomes visible. I've had a look at the documentation - which is so huge ! - but couldn't find any help.

Edit : a quick sample up to date

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[most]{tcolorbox}
\usepackage{ifthen}
\usepackage{enumitem}
\usepackage{array}

\newcounter{current}
\setcounter{current}{1}
\newcommand{\module}[1]{\lvert#1\rvert}
\newcommand{\exemples}[1]{
    \begin{tcolorbox}[breakable,colframe=gray!10,colback=gray!10]
        \textbf{Exemples \thechapter.\thecurrent}
            \begin{enumerate}[label=(\arabic*),wide]
            #1
            \end{enumerate}
    \end{tcolorbox}
    \stepcounter{current}
}
\newcommand{\hide}[1]{
    \ifthenelse{\equal{\edition}{E}}{
        \color{gray!10}
        %here is the fontspec code I should include
        #1
        \color{black}
    }
    {
    }
}

\begin{document}

\sffamily

\exemples{
\item Résoudre l'équation $z^2+(4+7i)\cdot z-31-i=0$
\def\edition{E}
\hide{On a : $\begin{array}[t]{ccl}\Delta&=&(4+7i)^2-4\cdot1\cdot(-31-i)\\
&=&16-49+56i+124+4i\\
&=&91+60i \\
\end{array}$

On doit donc chercher les $w$ tels que $w^2=\Delta$. On pose $w=a+b\cdot i$. On a alors le système d'équations suivant : 
\begin{center}
\begin{tabular}{cl}
&$\left\{\begin{array}{l}
\module{w}^2=\module{\Delta} \\
w^2=\Delta \\
\end{array}\right.$\\
$\Leftrightarrow$ &$\left\{\begin{array}{l}
a^2+b^2=\sqrt{91^2+60^2} \\
(a^2-b^2)+2abi=91+60i \\
\end{array}\right.$\\
$\Leftrightarrow$ &$\left\{\begin{array}{l}
a^2+b^2=109 \\
(a^2-b^2)=91 \\
2ab=60 \\
\end{array}\right.$\\
$\Leftrightarrow$ &$\left\{\begin{array}{l}
2a^2=200 \\
2b^2=18 \\
2ab=60 \\
\end{array}\right.$\\
\end{tabular}
\end{center}
qui donne les deux solutions $w_0=10+3i$ et $w_1=-10-3i$.
Ceci fournit les deux solutions de notre équation de départ 
$$z_0=\frac{-(4+7i)+10+3i}2=3-2i$$ et
$$z_1=\frac{-(4+7i)-10-3i}2=-7-5i$$}

\item Résoudre l'équation $2iz^2+(1+5i)\cdot z-1+13i=0$
\def\edition{E}
\hide{On a : $\begin{array}[t]{ccl}\Delta&=&(1+5i)^2-4\cdot2i        \cdot(-1+13i)\\
&=&1-25+10i+8i+104\\
&=&80+18i \\
\end{array}$

On doit donc chercher les $w$ tels que $w^2=\Delta$. On pose $w=a+b\cdot     i$. On a alors le système d'équations suivant : 
\begin{center}
\begin{tabular}{cl}
&$\left\{\begin{array}{l}
\module{w}^2=\module{\Delta} \\
w^2=\Delta \\
\end{array}\right.$\\
$\Leftrightarrow$ &$\left\{\begin{array}{l}

a^2+b^2=\sqrt{80^2+18^2} \\

(a^2-b^2)+2abi=80+18i \\

\end{array}\right.$\\

$\Leftrightarrow$ &$\left\{\begin{array}{l}

a^2+b^2=82 \\

(a^2-b^2)=80 \\

2ab=18 \\

\end{array}\right.$\\

$\Leftrightarrow$ &$\left\{\begin{array}{l}

2a^2=2 \\

2b^2=162 \\

2ab=18 \\

\end{array}\right.$\\

\end{tabular}

\end{center}


qui donne les deux solutions $w_0=9+i$ et $w_1=-9-i$.


Ceci fournit les deux solutions de notre équation de départ 
$$z_0=\frac{-(1+5i)+9+i}{4i}=-1-2i$$ et
$$z_1=\frac{-(1+5i)-9-i}{4i}=\frac{-3+5i}2$$
}
}

\end{document}

A quick sample of what I am doing :

\documentclass[a4paper,11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{ifthen}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}


\newcommand{\exemple}[1]{
    \begin{tcolorbox}[breakable,colframe=gray!10,colback=gray!10]
        \textbf{Exemple}
            #1
    \end{tcolorbox}
}

\begin{document}

\exemple{
\color{gray!10}
\lipsum
}

\end{document}

The result is that the first page is empty - which is expected - but the second comes in black ;-(

Any advice ? Thanks a lot in advance !

  • 2
    Maybe you can find some useful information here: Maintaining text colour change in a breakable tcolorbox. Also see section '17.2 Limitations and Known Bugs' (page 364) of the tcolorbox manual. – leandriis Apr 05 '18 at 17:39
  • I read that post. Unfortunately, you have to change the colour to the whole tcolorbox. I would like to have something more flexible. And I don't want to compile in Lulua or XeTeX. – HerculePoivrot Apr 05 '18 at 17:59
  • 2
    As the documentation explicitly lists this issue with other limitations and known bugs, I unfortunately doubt that there is much you can do about it besides the already mentioned work-around. – leandriis Apr 05 '18 at 18:35
  • 3
    if you distribute the pdfs rather than printing, white colour isn't a very effective way of removing text (answers?) since the text can easily be extracted from the pdf. – David Carlisle Apr 06 '18 at 00:10
  • I do print the pdf, no student gets the pdf. I have tried with LuluaTex as advised, but I cannot make it work. I find the fontspec documentation so complicated, cannot understand how to make it work the way I like. Will probably ask in the appropriate section. – HerculePoivrot Apr 06 '18 at 06:49

1 Answers1

4

David Carlisle is right about the possibility to extract the text even when printed in white (or better: the font color is the same one as for the background)

However, if this is no issue, here is the quick way to achieve the 'censoring': extras={colupper=tcbcol@back} such that the font color is the background color for every box of the break sequence.

\documentclass[a4paper,11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{ifthen}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}


\newcommand{\exemple}[1]{%
  \begin{tcolorbox}[breakable,enhanced,frame hidden,colback=gray!10,extras={colupper={tcbcol@back}}]
    #1%
  \end{tcolorbox}
}

\begin{document}

\exemple{%
\lipsum
}
  • Thank you for the answer. This is a pretty nice solution, however it doesn't quite fit what I want to do. I want to hide only part of the box (I usually state the problem and leave a blank for its resolution, but some examples have 2 or 3 items in them). Your solution will empty the following boxes completely. – HerculePoivrot Apr 06 '18 at 07:44
  • @HerculePoivrot: That wasn't clear from your description, in my point of view, but replace extras by extras middle and last, this should work for the broken parts. But can you be sure that the breaking point is exactly at the part that should be displayed and the rest, that should be hidden? –  Apr 06 '18 at 07:45
  • I edited my question with a new sample. I usually want to hide the resolutions of the problems. But some examples have a few items, and one item can be on 2 separate pages and therefore creating an issue. I am trying to solve this using fontspec now, but cannot work it out either. Latex is hard sometimes. – HerculePoivrot Apr 06 '18 at 07:56
  • @HerculePoivrot: You're using the wrong approach, in my point of view. –  Apr 06 '18 at 07:57
  • Im not an expert sadly, what should be a better approach ? – HerculePoivrot Apr 06 '18 at 07:58
  • @HerculePoivrot: See my answer to this other tcolorbox problem: https://tex.stackexchange.com/questions/402102/help-for-a-variant-of-exercises-for-textbooks-with-tcolorbox –  Apr 06 '18 at 08:06
  • Thanks very much Christian for taking time for my problem. I did try to read your solution, but well I guess my level is just not good enough to understand all of it. Just to clarify matters or try to I would like : exercice number and question (both version) - resolution (teacher version) and blank (student version) of the very same length (might be a blank after the resolution in teacher version), second item of the examples with same setup. Problem is if an item is in between two pages, the colour switches back to black. Hope it's clearer. – HerculePoivrot Apr 06 '18 at 08:19
  • Thanks Christian, in the end I managed to make things work using the solution your provided. Just needed a bit of thinking but you had done most of the job. It's probably quite unclean but it's doing what I want. I had struggling for 3 days with this problem so you are my savior. I look good in TeX coding when I compare to m colleague, on here I feel much weaker :-) – HerculePoivrot Apr 06 '18 at 13:28