12

I am writing a book which will contain a lot of TikZ figures and tcolorboxes. To speed things up I want to use the TikZ external library. However, I have run into some problems that I would like to understand. Perhaps this is a bug? The problem is that even if I use \tcbset{shield externalize}, some keys for the tcolorbox seems to cause problems.

One minimal example I can give is the following:

\documentclass[a4paper]{book} 
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tcbset{shield externalize} 

\begin{document}

\chapter{First Chapter}     

\begin{tcolorbox}[enhanced, attach boxed title to top left, title=Title]
    Hello
\end{tcolorbox}

\end{document}

This gives errors that hint at problems with TikZ trying to externalize the title box. Removing either \tikzexternalize or attach boxed title to top left will make the problem go away.

I cannot find anything in the (otherwise very excellent) manual for tcolorbox about this being a problem. Can anyone explain what is going on here or is this perhaps a bug with shield externalize?

In this particular case, my workaround is using \tikzexternalenable and \tikzexternaldisable around each tikzpicture, however, I would very much like to avoid that. So, perhaps someone can also give me some alternative method to externalize tikz figures, e.g. using latexmk?

For completenes: I am using "pgf 2019/02/02 v3.1.1 (3.1.1)" and "tcolorbox 2018/12/07 version 4.15 text color boxes".

3
  • As a workaround you could disable externalization for the box explicitly: \tikzexternaldisable \begin{tcolorbox}[enhanced, attach boxed title to top left, title=Title] Hello \end{tcolorbox} \tikzexternalenable
    – user121799
    Commented Apr 23, 2019 at 5:28
  • Yes, that also works. However, that prevents any TikZ image inside of the box to not be externalized. But in the end, I think I will have to use the same number of enable/disable. I would very much prefer an automatic approach if possible. Commented Apr 23, 2019 at 6:52
  • Did you try with external tcolorbox library instead of TikZ externalization. It's more limited than TikZ one but, may be, it avoids your problems. It's documented in section 24 (v4.20 tcolorbox).
    – Ignasi
    Commented Apr 23, 2019 at 8:33

1 Answer 1

11

The reason for the problem is that the boxed title is a tcolorbox itself, but with a higher layer number. For this higher layer, the global setting of shield externalize is reset to the default, i.e. to be false.

For almost all options this reset is useful (documented in section 4.16). But, I think, for shield externalize this is not true. Also, the documentation claims that \tcbset{shield externalize} in the preamble shields any tcolorbox inside the document.

The problem should vanish, if you replace \tcbset{shield externalize} by \tcbsetforeverylayer{shield externalize}, because this is applied to all boxed on all layers:

\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
%\tcbset{shield externalize}
\tcbsetforeverylayer{shield externalize}% <--- interim solution before bug fix


\begin{document}

\begin{tcolorbox}[enhanced, attach boxed title to top left, title=Title]
    Test
\end{tcolorbox}

\end{document}

Since I cannot imagine a use case, where one does not want to apply this for all layers, I will change the implementation for the next version of tcolorbox. The future change will remove shield externalize from the reset operation. After that, \tcbset{shield externalize} will be adequate as claimed by the documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .