1

I am using this code

\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[prefix=figures/]

\usepackage[theorems,skins]{tcolorbox}
\tcbset{red eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
        left=0.1ex,right=0.1ex,
        overlay={\fill[red!10] (frame.south west) to[bend left] 
            (frame.north west) --  (frame.north east) to[bend left]
            (frame.south east) -- cycle;},
        boxrule=0pt},
    blue eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
        left=0.1ex,right=0.1ex,
        overlay={\fill[blue!10] (frame.south west) to[bend left] 
            (frame.north west) --  (frame.north east) to[bend left]
            (frame.south east) -- cycle;},
        boxrule=0pt},
    highlight math style=red eqbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{equation}
    \tcbhighmath{\int x \,e^{-x}\, x}
\end{equation}

\end{document}

And it produces such an error:

File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpicture.

However, if I comment \tikzexternalize[prefix=figures/] or \tcbset{...} command, the file compiles correctly.

Note: I've created figures folder beside my .tex file.

antshar
  • 4,238
  • 9
  • 30

1 Answers1

2

This is because if you want to use externalize with tcolorbox, you need to take special precautions. They are not really specific to tcolorbox, an overlay tikzpicture generally has the same problem. However, tcolorbox has a very nice fix in its external library (which you can read about in section 4.23 Externalization of tcolorbox manual v4.30):

\tcbset{shield externalize}

with which your code becomes

\documentclass{article}
\newcommand{\diff}{\mathop{}\!\mathrm{d}}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\usepackage[theorems,skins,external]{tcolorbox}
\tikzexternalize[prefix=figures/]

\tcbset{shield externalize}
\tcbset{red eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
        left=0.1ex,right=0.1ex,
        overlay={\fill[red!10] (frame.south west) to[bend left] 
            (frame.north west) --  (frame.north east) to[bend left]
            (frame.south east) -- cycle;},
        boxrule=0pt},
    blue eqbox/.style={enhanced,top=0.2ex, bottom=0.2ex, 
        left=0.1ex,right=0.1ex,
        overlay={\fill[blue!10] (frame.south west) to[bend left] 
            (frame.north west) --  (frame.north east) to[bend left]
            (frame.south east) -- cycle;},
        boxrule=0pt},
    highlight math style=red eqbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{equation}
    \tcbhighmath{\int x \,e^{-x}\,\diff x}
\end{equation}

\end{document}

enter image description here

  • 2
    @antshar Yes. I sometimes think that it might be a good idea if TikZ could spare all these overlay pictures automatically from externalize. Similar problems occur e.g. if you combine externalize with the tikzmark library, which is absolutely not the fault of tikzmark. –  May 14 '20 at 20:27