Skip to content
cfr42 edited this page Mar 9, 2025 · 2 revisions

Externalization shield

How to prevent memoization of a tcolorbox while allowing memoization inside the box contents, e.g. automatically memoizing tikzpictures as if they were not inside a tcolorbox?

Tcolorbox provides a mechanism which does this for TikZ external library, see section 4.24 of tcolorbox manual. The mechanism is activated by executing key shield externalize:

\tcbset{shield externalize}

The following code hacks this key to provide the same service to Memoize: because tcolorbox executes \tcb@shield@@externalize after processing the box contents but before typeseting the box, \memoizefalse (which disables memoization) is in effect only during the latter process.

\makeatletter
\csappto{tcb@shield@@externalize}{\ifdefined\memoizefalse\memoizefalse\fi}
\makeatother

Due to \ifdefined\memoizefalse, this code is safe to use even when Memoize is not loaded.

To disable memoization of all tcolorbox environments (while allowing it for any tikzpictures inside them, for example),

\makeatletter
\csappto{tcb@shield@@externalize}{\ifdefined\memoizefalse\memoizefalse\fi}
\tcbset{shield externalize}
\makeatother
Clone this wiki locally