7

I try to maintain the current text colour in breakable boxes from tcolorbox, but the manual clearly states (see manual of the current version, section 15.2, page 292, version 3.34)

• If your text content contains some text color changing commands, your color will not survive the break to the next box.

So, this has to fail (right now). However, colour changes are maintained in explicit TeX boxes, being split using \vsplit.

Is there a way (i.e. hack/patch) to force tcolorbox to maintain the current text colour from one part of the broken box to the next one?

A grouping with { \color{....}...} or \begingroup \color{...}...\endgroup or \textcolor{...}{...} does not work neither.

\documentclass{article}

\usepackage{blindtext}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\begin{document}

\begin{tcolorbox}[breakable]
  \blindtext[3]
  \color{blue}  % To 'force' color change 
  \blindtext[3]
  \color{red}
  \blindtext
  \color{brown}
  \blindtext
\end{tcolorbox}


\end{document}

The colour should be blue on the upper half of the second box if it would work ;-)

enter image description here

10
  • 2
    It would be nice to have a good answer to this question, but, obviously, I do not have one. \vsplit is used internally, but coloring is not really supported for this command, see tex.stackexchange.com/questions/150780/… and David Carlisles answer to this. Changing color setting for the current tcolorbox implementation is very touchy since I put in a great deal of time to get it like it is now. It is not perfect and has same drawbacks, but it circumvents a lot of problems. Dec 31, 2014 at 10:14
  • 1
    Nevertheless, if there are new insights in how to enhance the current implementation (for all use cases, for pdflatex, for xelatex, ... ) I'm willing to give it a new try :-) Dec 31, 2014 at 10:16
  • 1
    xelatex also has a special color bug which I cannot test on my system, but is circumvented currently, see tex.stackexchange.com/questions/186139/… Dec 31, 2014 at 10:19
  • 1
    @ThomasF.Sturm: I've read your question from your link above and this is, what I feared ;-) Interestingly I need color bleeding where you want to prevent it ... The double grouping is new to me. I will ask David if he has some clue anyway.
    – user31729
    Dec 31, 2014 at 10:36
  • 1
    I don't have much hope in the moment, but you never know ;-) Dec 31, 2014 at 10:42

1 Answer 1

12

With xelatex or lualatex you could color the font instead of using the color commands. This would survive a box break:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\usepackage{blindtext}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\begin{document}

\begin{tcolorbox}[breakable]
  \blindtext[3]
  \addfontfeatures{Color=blue}
  \blindtext[3]
  \addfontfeatures{Color=red}
  \blindtext
  \addfontfeatures{Color=brown}
  \blindtext
\end{tcolorbox}


\end{document}

enter image description here

4
  • Thanks, this is a new idea... I am currently not using xelatex nor lualatex... I'll give it a try!
    – user31729
    Dec 31, 2014 at 11:45
  • 1
    Be aware that the font color always wins. You can't use something like \textcolor{yellow}{yellow} with it. Dec 31, 2014 at 11:51
  • 2
    @UlrikeFischer do you think it would make sense to have an option to color package so it used the font attribute as well as (or instead of?) the color special, so that \textcolor{yellow}{...} would combine with this? Dec 31, 2014 at 12:24
  • 2
    @DavidCarlisle It would certainly worth consideration. But as I wrote such font colors wins but they don't affect all fonts - only the one loaded with \setmainfont etc (and so no rules and without unicode-math no math). And the combination with color commands can lead to curious effects. E.g. after adding colors to the fonts the math will be red with \textcolor{red}{$a=b$}, but \textcolor{red}{blbla $a=b$} it will be black (with luatex, with xetex is is red again). So imho some careful investigations are needed. Jan 2, 2015 at 9:36

You must log in to answer this question.