| 1 |
% !TeX root = tcolorbox.tex |
| 2 |
% include file of tcolorbox.tex (manual of the LaTeX package tcolorbox) |
| 3 |
\clearpage |
| 4 |
\section{Library \mylib{external}}\label{sec:external}% |
| 5 |
\tcbset{external/prefix=external/external_}% |
| 6 |
The library is loaded by a package option or inside the preamble by: |
| 7 |
\begin{dispListing} |
| 8 |
\tcbuselibrary{external} |
| 9 |
\end{dispListing} |
| 10 |
|
| 11 |
The purpose of this library is to support externalization of document |
| 12 |
snippets like graphics or boxes which can be compiled stand-alone. |
| 13 |
These snippets are written to external files, compiled and the resulting |
| 14 |
pdf files are included to the main document as images. |
| 15 |
The whole procedure saves compilation time, if such a snippet is costly to |
| 16 |
compile but needs to compile just once or very seldom. |
| 17 |
|
| 18 |
There are very good alternatives to this library. One should consider |
| 19 |
the \refPkg{standalone} package, |
| 20 |
the \refPkg{memoize} package, |
| 21 |
the \refPkg{robust-externalize} package, |
| 22 |
or the \tikzname\ externalization library (currently unmaintained) |
| 23 |
instead. |
| 24 |
The \mylib{external} library is something in between and can be seen as |
| 25 |
poor man variant of the \tikzname\ externalization library. |
| 26 |
|
| 27 |
The main differences between \tikzname\ externalization and \mylib{external} are: |
| 28 |
\begin{itemize} |
| 29 |
\item\tikzname\ |external| compiles the whole original document in a sophisticated |
| 30 |
way while \mylib{external} uses only the preamble or a part of the preamble |
| 31 |
of the original document. |
| 32 |
\item\tikzname\ |external| can automatically externalize all |tikzpicture| |
| 33 |
environments while \mylib{external} externalizes marked snippets only. |
| 34 |
\item Code snippets to be externalized by \mylib{external} are not restricted to |
| 35 |
|tikzpicture| environments. But these snippets have to be stand-alone without |
| 36 |
dependencies to the rest of the document. |
| 37 |
\end{itemize} |
| 38 |
Why should somebody use \mylib{external} instead of the more powerful \tikzname\ |external|? |
| 39 |
One reason could be compilation speed, but the main reason for creating the |
| 40 |
library at all was that \tikzname\ |external| tends to choke on complicated |
| 41 |
documents where the sophisticated mechanism stumbles. Since \mylib{external} does |
| 42 |
not use the original document body for compilation, this cannot happen. |
| 43 |
|
| 44 |
\begin{marker} |
| 45 |
Source snippets are compiled, if their |md5| checksum has changed. |
| 46 |
They are not compiled automatically, if option settings are changed or |
| 47 |
anything outside the snippet is changed. |
| 48 |
Use \refKey{/tcb/external/force remake} to force compilation in this case |
| 49 |
or simply delete the externalized pdf oder md5 files. |
| 50 |
\end{marker} |
| 51 |
|
| 52 |
\begin{marker} |
| 53 |
To use the externalization options, the compiler has to be called with the |
| 54 |
|-shell-escape| permission to authorize potentially dangerous system calls. |
| 55 |
Be warned that this is a security risk. |
| 56 |
\end{marker} |
| 57 |
|
| 58 |
|
| 59 |
\clearpage |
| 60 |
\subsection{Preparation of a Document for Externalization}\label{subsec:external_preparation} |
| 61 |
|
| 62 |
The preamble of the main document has to contain the \refCom{tcbEXTERNALIZE} |
| 63 |
command. Without this command, no externalization operation will be |
| 64 |
executed. |
| 65 |
|
| 66 |
\begin{docCommand}[doc new=2015-03-11]{tcbEXTERNALIZE}{} |
| 67 |
It is mandatory for externalization that this command is used once |
| 68 |
in the preamble of the main document. Every setting \emph{before} |
| 69 |
\refCom{tcbEXTERNALIZE} will also be used for compiling an external |
| 70 |
snippet. Every setting \emph{after} \refCom{tcbEXTERNALIZE} will be |
| 71 |
ignored for compiling an external snippet. |
| 72 |
Place this command right before |\begin{document}|, if you are not |
| 73 |
absolutely sure about another place. |
| 74 |
|
| 75 |
The main document has to look like the following: |
| 76 |
|
| 77 |
\begin{dispListing} |
| 78 |
\documentclass[a4paper]{book}% for example |
| 79 |
\usepackage{...}% anything |
| 80 |
% ... |
| 81 |
% Typically, all or the very most settings for the document. |
| 82 |
|
| 83 |
\tcbEXTERNALIZE% Typically, just before \begin{document} |
| 84 |
|
| 85 |
% Additional settings which are ABSOLUTELY irrelevant for the |
| 86 |
% stand-alone snippets. |
| 87 |
% |
| 88 |
\begin{document} |
| 89 |
% The document. |
| 90 |
% This also contains the marked snippets for externalization. |
| 91 |
\end{document} |
| 92 |
\end{dispListing} |
| 93 |
\end{docCommand} |
| 94 |
|
| 95 |
During compilation, a \refKey{/tcb/external/runner} file |
| 96 |
is dynamically created (several times). This is the actual main file for |
| 97 |
compiling an externalized snippet. |
| 98 |
|
| 99 |
\begin{extTcbKey}[][doc new=2015-03-11]{runner}{=\meta{file name}}{no default, |
| 100 |
initially \texttt{\cs{jobname}\detokenize{_run.tex}}} |
| 101 |
Sets the \meta{file name} for dynamically created |runner| file. |
| 102 |
This is the actual main file for a document snippet. |
| 103 |
Typically, the initial setting is not needed to be changed. |
| 104 |
\begin{dispListing} |
| 105 |
\tcbset{external/runner=myrunner.tex} |
| 106 |
\end{dispListing} |
| 107 |
\end{extTcbKey} |
| 108 |
|
| 109 |
\begin{extTcbKey}[][doc new=2015-03-11]{prefix}{=\meta{text}}{no default, |
| 110 |
initially \texttt{external/}} |
| 111 |
The \meta{text} is prefixed to any \refKey{/tcb/external/name} for an |
| 112 |
externalization snippet. The initial setting implies saving all snippets |
| 113 |
into an |external/| subdirectory. Depending on the operation system, |
| 114 |
the subdirectory may have to be created manually once. |
| 115 |
\begin{dispListing} |
| 116 |
% Use a 'real' prefix instead of writing into a subdirectory: |
| 117 |
\tcbset{external/prefix=ext_} |
| 118 |
\end{dispListing} |
| 119 |
\end{extTcbKey} |
| 120 |
|
| 121 |
|
| 122 |
\begin{extTcbKey}[][doc new=2015-03-11]{externalize}{\colOpt{=true\textbar false}}{default |true|, |
| 123 |
initially |true|} |
| 124 |
If set to |true|, the marked snippets are compiled if necessary. |
| 125 |
If set to |false|, the marked snippets are not compiled but included as text. |
| 126 |
\refKey{/tcb/external/externalize} can only be used after \refCom{tcbEXTERNALIZE}. |
| 127 |
\end{extTcbKey} |
| 128 |
|
| 129 |
\begin{extTcbKey}[][doc new=2015-03-11]{force remake}{\colOpt{=true\textbar false}}{default |true|, |
| 130 |
initially |false|} |
| 131 |
If set to |true|, the marked snippets are always compiled. |
| 132 |
If set to |true|, the marked snippets are compiled only if necessary. |
| 133 |
The necessity is given, if a compiled pdf file is missing or the |
| 134 |
|md5| checksum of the source snippet has changed. |
| 135 |
\end{extTcbKey} |
| 136 |
|
| 137 |
\enlargethispage*{1cm} |
| 138 |
\begin{extTcbKey}[][doc new and updated={2015-03-11}{2017-02-24}]{\tcbexclamation}{}{style} |
| 139 |
Shortcut for setting \refKey{/tcb/external/force remake} to |true|. |
| 140 |
\end{extTcbKey} |
| 141 |
|
| 142 |
\begin{extTcbKey}[][doc new and updated={2015-06-12}{2017-02-24}]{-}{}{style} |
| 143 |
Shortcut for setting \refKey{/tcb/external/externalize} to |false|. |
| 144 |
\end{extTcbKey} |
| 145 |
|
| 146 |
|
| 147 |
\subsection{Marking Externalization Snippets}\label{subsec:external_marking} |
| 148 |
|
| 149 |
\begin{docEnvironment}[doc new=2015-03-11]{tcbexternal}{\oarg{options}\marg{name}} |
| 150 |
Marks the environment content as a snippet for externalization. |
| 151 |
Typically, the content is a |tikzpicture| or something similar. |
| 152 |
It is important to note that the snippet should not have any dependencies |
| 153 |
with the rest of the document, e.\,g.\ referencing counters or setting counters |
| 154 |
is not possible. |
| 155 |
The \meta{name} is automatically prefixed with \refKey{/tcb/external/prefix}. |
| 156 |
In combination, this has to be a unique file name. It is advised to not |
| 157 |
use spaces or umlauts for the name. |
| 158 |
The \meta{options} are keys from the |/tcb/external/| key tree. |
| 159 |
|
| 160 |
\begin{dispExample} |
| 161 |
\begin{tcbexternal}{example_tikzpicture} |
| 162 |
\begin{tikzpicture} |
| 163 |
\path[fill=yellow!50!white] (0,0) circle (11mm); |
| 164 |
\path[fill=white] (0,0) circle (9mm); |
| 165 |
\foreach \w/\c in {90/red,210/green,330/blue} |
| 166 |
{\path[shading=ball,ball color=\c] (\w:1cm) circle (7mm);} |
| 167 |
\end{tikzpicture} |
| 168 |
\end{tcbexternal} |
| 169 |
\end{dispExample} |
| 170 |
|
| 171 |
\medskip |
| 172 |
|
| 173 |
If a \refEnv{tcolorbox} is externalized, one should use |
| 174 |
\refKey{/tcb/nobeforeafter} for the box. Indention and distances to |
| 175 |
the text before and after have to be given separately outside the |
| 176 |
\refEnv{tcbexternal} environment. |
| 177 |
|
| 178 |
\begin{dispExample} |
| 179 |
\noindent% |
| 180 |
\begin{tcbexternal}[minipage]{example_tcolorbox} |
| 181 |
\begin{tcolorbox}[nobeforeafter,enhanced, |
| 182 |
fonttitle=\bfseries,title=Externalized Box, |
| 183 |
colframe=red!50!black,drop fuzzy shadow, |
| 184 |
interior style={fill overzoom image=goldshade.png}] |
| 185 |
This complete tcolorbox is externalized. One cannot use numbered |
| 186 |
boxes here. Note the \texttt{minipage} option which tells the |
| 187 |
current line width to the external snippet. |
| 188 |
\end{tcolorbox} |
| 189 |
\end{tcbexternal} |
| 190 |
\end{dispExample} |
| 191 |
|
| 192 |
\begin{dispExample} |
| 193 |
\begin{tcolorbox}[nobeforeafter,enhanced, |
| 194 |
fonttitle=\bfseries,title=Externalized Box, |
| 195 |
colframe=blue!50!black, |
| 196 |
interior style={fill overzoom image=blueshade.png}] |
| 197 |
\begin{tcbexternal}[minipage]{example_tcolorbox2} |
| 198 |
\color{white}% |
| 199 |
The interior of the tcolorbox is externalized. |
| 200 |
One can use numbered boxes without problems. |
| 201 |
Note that the text color has to be set for the text manually |
| 202 |
since it is converted into an image. |
| 203 |
\end{tcbexternal} |
| 204 |
\end{tcolorbox} |
| 205 |
\end{dispExample} |
| 206 |
|
| 207 |
\begin{dispExample} |
| 208 |
\begin{tcbexternal}[minipage]{example_tabularx} |
| 209 |
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% |
| 210 |
\begin{tabularx}{\linewidth}{|l||Y|Y|Y|Y||Y|}\hline |
| 211 |
Group & One & Two & Three & Four & Sum\\\hline\hline |
| 212 |
Red & 1000.00 & 2000.00 & 3000.00 & 4000.00 & 10000.00\\\hline |
| 213 |
Green & 2000.00 & 3000.00 & 4000.00 & 5000.00 & 14000.00\\\hline |
| 214 |
Blue & 3000.00 & 4000.00 & 5000.00 & 6000.00 & 18000.00\\\hline\hline |
| 215 |
Sum & 6000.00 & 9000.00 & 12000.00 & 15000.00 & 42000.00\\\hline |
| 216 |
\end{tabularx} |
| 217 |
\end{tcbexternal} |
| 218 |
\end{dispExample} |
| 219 |
|
| 220 |
|
| 221 |
\end{docEnvironment} |
| 222 |
|
| 223 |
\begin{extTcbKey}[][doc new=2015-03-11]{name}{=\meta{name}}{no default, |
| 224 |
initially \texttt{unnamed}} |
| 225 |
The \meta{name} is automatically prefixed with \refKey{/tcb/external/prefix}. |
| 226 |
In combination, this has to be a unique file name for externalization. |
| 227 |
Typically, this key is not used directly but is set indirectly as |
| 228 |
mandatory parameter, see \refEnv{tcbexternal}. |
| 229 |
\end{extTcbKey} |
| 230 |
|
| 231 |
|
| 232 |
\clearpage |
| 233 |
\begin{docEnvironment}[doc new=2015-03-11]{extcolorbox}{\oarg{options}\marg{name}\oarg{tcolorbox options}} |
| 234 |
This is an externalized version of \refEnv{tcolorbox} created |
| 235 |
using\\ \refCom{newtcbexternalizetcolorbox}: |
| 236 |
\begin{dispListing} |
| 237 |
\newtcbexternalizetcolorbox{extcolorbox}{tcolorbox}{}{} |
| 238 |
\end{dispListing} |
| 239 |
\meta{options} and \meta{name} are given to the underlying \refEnv{tcbexternal} |
| 240 |
environment, while \meta{tcolorbox options} are given to \refEnv{tcolorbox}. |
| 241 |
|
| 242 |
\begin{marker} |
| 243 |
Note that you should not redefine \refKey{/tcb/before} and \refKey{/tcb/after} |
| 244 |
inside the \meta{tcolorbox options}, since the |
| 245 |
externalized version would not be identical to the non-externalized |
| 246 |
otherwise. |
| 247 |
\end{marker} |
| 248 |
|
| 249 |
\begin{dispExample} |
| 250 |
\begin{extcolorbox}[minipage]{example_extcolorbox} |
| 251 |
[ enhanced,colframe=red!50!black,colback=yellow!10, |
| 252 |
fonttitle=\bfseries,drop fuzzy shadow, |
| 253 |
title=My external box ] |
| 254 |
|
| 255 |
This box is completely externalized. |
| 256 |
|
| 257 |
\begin{tcolorbox}[colframe=blue,colback=blue!5,before skip=6pt] |
| 258 |
Inner box. |
| 259 |
\end{tcolorbox} |
| 260 |
\end{extcolorbox} |
| 261 |
\end{dispExample} |
| 262 |
\end{docEnvironment} |
| 263 |
|
| 264 |
\begin{marker} |
| 265 |
\begin{itemize} |
| 266 |
\item\textbf{Never} externalize numbered boxes. |
| 267 |
\item\textbf{Never} externalize boxes which contain references to other |
| 268 |
things, e.\,g.\ using |\ref| or |\cite|. |
| 269 |
\item\textbf{Never} externalize breakable boxes. |
| 270 |
\end{itemize} |
| 271 |
\kern6pt |
| 272 |
\end{marker} |
| 273 |
|
| 274 |
\clearpage |
| 275 |
\begin{docEnvironment}[doc new=2015-03-11]{extikzpicture}{\oarg{options}\marg{name}\oarg{tikz options}} |
| 276 |
This is an externalized version of |tikzpicture| created |
| 277 |
using\\ \refCom{newtcbexternalizeenvironment}: |
| 278 |
\begin{dispListing} |
| 279 |
\newtcbexternalizeenvironment{extikzpicture}{tikzpicture}{}{}{} |
| 280 |
\end{dispListing} |
| 281 |
\meta{options} and \meta{name} are given to the underlying \refEnv{tcbexternal} |
| 282 |
environment, while \meta{tikz options} are given to |tikzpicture|. |
| 283 |
|
| 284 |
\tcbset{/tcb/external/externalize}%----- Do externalization even if switched off globally |
| 285 |
\begin{dispExample} |
| 286 |
\begin{center} |
| 287 |
\begin{extikzpicture}[ |
| 288 |
preamble={\usepackage{pgfplots}}, % add package for external graph |
| 289 |
input source on error=false, % do not load source on error |
| 290 |
]{example_pgfplots} |
| 291 |
\pgfplotsset{width=12cm} |
| 292 |
\begin{axis}[3d box=background,grid=major, |
| 293 |
xlabel=$x$, ylabel=$y$, zlabel=$z$, view/h=40, |
| 294 |
mesh/interior colormap name=hot, |
| 295 |
colormap/blackwhite, |
| 296 |
z buffer=sort,domain=0:90,y domain=0:60, |
| 297 |
zmin=0,zmax=2,z post scale=1.2, |
| 298 |
] |
| 299 |
\addplot3[surf,mesh/interior colormap name=blackwhite, |
| 300 |
colormap/hot,] ( {cos(x)},{sin(x)}, {2*sin(y)} ); |
| 301 |
\addplot3[surf] ( {2*cos(x)*cos(y)},{2*sin(x)*cos(y)}, {2*sin(y)} ); |
| 302 |
\end{axis} |
| 303 |
\end{extikzpicture} |
| 304 |
\end{center} |
| 305 |
\end{dispExample} |
| 306 |
|
| 307 |
\end{docEnvironment} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
\clearpage |
| 313 |
\begin{docTcbKey}[][doc new=2015-03-11]{externalize listing}{=\meta{name}}{style, no default} |
| 314 |
The text content of a \refEnv{tcblisting} is externalized with the |
| 315 |
given \meta{name}. Note that the listing part is not externalized. |
| 316 |
\end{docTcbKey} |
| 317 |
|
| 318 |
|
| 319 |
\begin{dispExample} |
| 320 |
\begin{tcblisting}{externalize listing=example_listing, |
| 321 |
bicolor,colback=yellow!10,colframe=yellow!50!black, |
| 322 |
colbacklower=white,center lower} |
| 323 |
\begin{tikzpicture} |
| 324 |
\path[fill=yellow!50!white] (0,0) circle (11mm); |
| 325 |
\path[fill=white] (0,0) circle (9mm); |
| 326 |
\foreach \w/\c in {90/red,210/green,330/blue} |
| 327 |
{\path[shading=ball,ball color=\c] (\w:1cm) circle (7mm);} |
| 328 |
\end{tikzpicture} |
| 329 |
\end{tcblisting} |
| 330 |
\end{dispExample} |
| 331 |
|
| 332 |
|
| 333 |
\begin{docTcbKey}[][doc new=2015-03-11]{externalize listing\tcbexclamation}{=\meta{name}}{style, no default} |
| 334 |
Combination of \refKey{/tcb/externalize listing} and \refKey{/tcb/external/force remake}. |
| 335 |
\end{docTcbKey} |
| 336 |
|
| 337 |
\begin{docTcbKey}[][doc new=2015-03-11]{externalize example}{=\meta{name}}{style, no default} |
| 338 |
The text content of a \refEnv{dispExample*} is externalized with the |
| 339 |
given \meta{name}. Note that the listing part is not externalized. |
| 340 |
|
| 341 |
\begin{dispExample} |
| 342 |
\begin{dispExample*}{sidebyside,externalize example=example_example} |
| 343 |
\tikz\path[shading=ball, |
| 344 |
ball color=red] circle (7mm); |
| 345 |
\end{dispExample*} |
| 346 |
\end{dispExample} |
| 347 |
\end{docTcbKey} |
| 348 |
|
| 349 |
\begin{docTcbKey}[][doc new=2015-03-11]{externalize example\tcbexclamation}{=\meta{name}}{style, no default} |
| 350 |
Combination of \refKey{/tcb/externalize example} and \refKey{/tcb/external/force remake}. |
| 351 |
\end{docTcbKey} |
| 352 |
|
| 353 |
\clearpage |
| 354 |
\subsection{Customization}\label{subsec:external_custom} |
| 355 |
|
| 356 |
\begin{extTcbKey}[][doc new=2015-03-11]{safety}{=\meta{length}}{no default, |
| 357 |
initially |2mm|} |
| 358 |
The snippet box is surrounded with a safety border with a thickness of |
| 359 |
\meta{length}. This border is automatically trimmed during picture inclusion. |
| 360 |
The reason for this mechanism is to catch box content which |
| 361 |
extrudes over the bounding box. For example, shadows of a |tcolorbox| are |
| 362 |
painted outside the bounding box and would be lost otherwise. |
| 363 |
\end{extTcbKey} |
| 364 |
|
| 365 |
\begin{extTcbKey}[][doc new=2015-03-11]{environment}{=\meta{env}}{no default, initially unset} |
| 366 |
Surrounds the exported snippet text with an environment \meta{env} without |
| 367 |
parameters. |
| 368 |
Note that this option is ignored for \refKey{/tcb/externalize listing}. |
| 369 |
\end{extTcbKey} |
| 370 |
|
| 371 |
\begin{extTcbKey}[][doc new=2015-05-05]{environment with percent}{\colOpt{=true\textbar false}}{default |true|, |
| 372 |
initially |true|} |
| 373 |
If set to |true|, the |\begin| and |\end| code of \refKey{/tcb/external/environment} |
| 374 |
is appended with a percent sign. For verbatim environments, this option |
| 375 |
typically has to be set to |false|. |
| 376 |
\end{extTcbKey} |
| 377 |
|
| 378 |
|
| 379 |
\begin{extTcbKey}[][doc new=2015-03-11]{minipage}{\colOpt{=\meta{length}}}{default \texttt{\cs{linewidth}}, |
| 380 |
initially unset} |
| 381 |
Surrounds the exported snippet text with a minipage. The optional \meta{length} |
| 382 |
parameter sets the width of the minipage. Note that the default width is the |
| 383 |
current line width of the main document. |
| 384 |
See \refEnv{tcbexternal} for examples. |
| 385 |
Note that this option is ignored for \refKey{/tcb/externalize listing}. |
| 386 |
\end{extTcbKey} |
| 387 |
|
| 388 |
|
| 389 |
\begin{extTcbKey}[][doc new=2015-03-11]{plain}{}{no value, initially set} |
| 390 |
Removes any text which was set to surround the snippet. |
| 391 |
This removes the setting of \refKey{/tcb/external/minipage}, but is |
| 392 |
independent of \refKey{/tcb/external/safety}. |
| 393 |
\end{extTcbKey} |
| 394 |
|
| 395 |
|
| 396 |
\begin{extTcbKey}[][doc new=2015-03-11]{compiler}{=\meta{text}}{no default, |
| 397 |
initially \texttt{pdflatex}} |
| 398 |
Sets the name of the compiler for the snippets. |
| 399 |
\end{extTcbKey} |
| 400 |
|
| 401 |
\begin{extTcbKey}[][doc new=2015-03-11]{runs}{=\meta{number}}{no default, |
| 402 |
initially |1|} |
| 403 |
Sets the number of compiler runs for the snippet. |
| 404 |
\begin{dispExample} |
| 405 |
\begin{tcbexternal}[minipage,runs=2]{example_raster} |
| 406 |
\begin{tcbitemize}[raster equal height, |
| 407 |
size=small,colframe=red!50!black,colback=red!10!white] |
| 408 |
\tcbitem One |
| 409 |
\tcbitem \Huge Two |
| 410 |
\tcbitem Three |
| 411 |
\tcbitem Four |
| 412 |
\end{tcbitemize} |
| 413 |
\end{tcbexternal} |
| 414 |
\end{dispExample} |
| 415 |
\end{extTcbKey} |
| 416 |
|
| 417 |
\enlargethispage*{1cm} |
| 418 |
\begin{extTcbKey}[][doc new=2015-03-11]{input source on error}{\colOpt{=true\textbar false}}{default |true|, |
| 419 |
initially |true|} |
| 420 |
If set to |true|, the source code of the snippet is loaded instead of |
| 421 |
the failed pdf picture. Typically, this will lead to an error stop at the |
| 422 |
faulty place of the source and such helps detecting the cause. |
| 423 |
If the source input compiles without error, the document setup |
| 424 |
may be incorrect, see \zvref{subsec:external_preparation}. |
| 425 |
Maybe, the |external/| subdirectory has to be created manually in this case, |
| 426 |
see \refKey{/tcb/external/prefix}.\par |
| 427 |
If the option is set to |false|, the compilation stops immediately on an error. |
| 428 |
The log file of the external snippet has to be consulted for error messages |
| 429 |
in this case. |
| 430 |
\end{extTcbKey} |
| 431 |
|
| 432 |
|
| 433 |
\clearpage |
| 434 |
|
| 435 |
\begin{extTcbKey}[][doc new=2015-05-05]{preclass}{=\meta{code}}{no default, |
| 436 |
initially unset} |
| 437 |
The given \meta{code} is added before the snippet document. |
| 438 |
Typically, this means before |\documentclass|. |
| 439 |
This is not used for compilation of the main document. |
| 440 |
\end{extTcbKey} |
| 441 |
|
| 442 |
|
| 443 |
\begin{extTcbKey}[][doc new=2015-05-05]{PassOptionsToPackage}{=\marg{options}\marg{package}}{no default, |
| 444 |
initially unset} |
| 445 |
The given \meta{options} are passed to the given \meta{package} for |
| 446 |
the snippet document. This is a shortcut for using \refKey{/tcb/external/preclass} |
| 447 |
with |\PassOptionsToPackage|. |
| 448 |
This not used for compilation of the main document. |
| 449 |
\end{extTcbKey} |
| 450 |
|
| 451 |
|
| 452 |
\begin{extTcbKey}[][doc new=2015-05-05]{PassOptionsToClass}{=\marg{options}\marg{class}}{no default, |
| 453 |
initially unset} |
| 454 |
The given \meta{options} are passed to the given \meta{class} for |
| 455 |
the snippet document. This is a shortcut for using \refKey{/tcb/external/preclass} |
| 456 |
with |\PassOptionsToClass|. |
| 457 |
This not used for compilation of the main document. |
| 458 |
\end{extTcbKey} |
| 459 |
|
| 460 |
|
| 461 |
\begin{extTcbKey}[][doc new=2015-05-05]{clear preclass}{}{no value} |
| 462 |
Removes all additional \refKey{/tcb/external/preclass} settings. |
| 463 |
\end{extTcbKey} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
\begin{extTcbKey}[][doc new=2015-03-11]{preamble}{=\meta{code}}{no default, |
| 468 |
initially unset} |
| 469 |
The given \meta{code} is added to the preamble of the snippet document. |
| 470 |
This is not used for compilation of the main document. |
| 471 |
\end{extTcbKey} |
| 472 |
|
| 473 |
|
| 474 |
\begin{extTcbKey}[][doc new=2015-05-05]{preamble tcbset}{=\meta{options}}{no default, |
| 475 |
initially unset} |
| 476 |
The given \meta{options} are added as parameter for \refCom{tcbset} |
| 477 |
to the preamble of the snippet document. |
| 478 |
This are not used for compilation of the main document. |
| 479 |
\end{extTcbKey} |
| 480 |
|
| 481 |
|
| 482 |
\begin{extTcbKey}[][doc new=2015-03-16]{clear preamble}{}{no value} |
| 483 |
Removes all additional \refKey{/tcb/external/preamble} settings. |
| 484 |
\end{extTcbKey} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
\begin{docCommand}[doc new=2015-03-11]{tcbifexternal}{\marg{true}\marg{false}} |
| 489 |
Expands to \meta{true}, if executed during snippet compilation, |
| 490 |
and to \meta{false}, if executed during main document compilation. |
| 491 |
This can be used \emph{before} \refCom{tcbEXTERNALIZE} to |
| 492 |
give different setting to snippet and main document. |
| 493 |
\begin{dispListing} |
| 494 |
\tcbifexternal{ |
| 495 |
\usepackage{onlyforexternal} |
| 496 |
}{ |
| 497 |
\usepackage{onlyformain} |
| 498 |
} |
| 499 |
\end{dispListing} |
| 500 |
\end{docCommand} |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
\clearpage |
| 505 |
\begin{docCommand}[doc new=2015-03-11]{newtcbexternalizeenvironment}{\marg{newenv}\marg{env}\marg{options}\marg{begin}\marg{end}} |
| 506 |
Creates a new environment \meta{newenv} which is based on |
| 507 |
\refEnv{tcbexternal}. This environment takes \emph{at least} |
| 508 |
one optional parameter and one mandatory parameter. |
| 509 |
These two parameters are passed to \refEnv{tcbexternal}. |
| 510 |
Further, the given \meta{options} are always added to the option list of \refEnv{tcbexternal}.\par |
| 511 |
The environment content is externalized and the external snippet is surrounded |
| 512 |
by an environment \meta{env}. All further parameters of \meta{newenv} |
| 513 |
are given to \meta{env} as parameters.\par |
| 514 |
The included image is prepended by \meta{begin} and appended by \meta{end}.\par |
| 515 |
\refEnv{extikzpicture} is an example application |
| 516 |
for \refCom{newtcbexternalizeenvironment}. |
| 517 |
|
| 518 |
\begin{dispExample} |
| 519 |
\newtcbexternalizeenvironment{extabular}{tabular}{}{\par\centering}{\par} |
| 520 |
|
| 521 |
\begin{extabular}{example_tabular}{|l|p{6cm}|r|}\hline |
| 522 |
A & B & C\\\hline |
| 523 |
a & This table is externalized as snippet. Obviously, |
| 524 |
this only makes sense for highly complex tables. |
| 525 |
& b\\\hline |
| 526 |
\end{extabular} |
| 527 |
\end{dispExample} |
| 528 |
\end{docCommand} |
| 529 |
|
| 530 |
|
| 531 |
\begin{docCommand}[doc new=2015-03-11]{renewtcbexternalizeenvironment}{\marg{newenv}\marg{env}\marg{options}\marg{begin}\marg{end}} |
| 532 |
Identical to \refCom{newtcbexternalizeenvironment}, but the environment \meta{newenv} |
| 533 |
is created by |\renewenvironment| instead of |\newenvironment|. |
| 534 |
\end{docCommand} |
| 535 |
|
| 536 |
|
| 537 |
\begin{docCommand}[doc new=2015-03-11]{newtcbexternalizetcolorbox}{\marg{newenv}\marg{env}\marg{options}\marg{begin end options}} |
| 538 |
Creates a new environment \meta{newenv} which is based on |
| 539 |
\refEnv{tcbexternal}. This environment takes \emph{at least} |
| 540 |
one optional parameter and one mandatory parameter. |
| 541 |
These two parameters are passed to \refEnv{tcbexternal}. |
| 542 |
Further, the given \meta{options} are always added to the option list of \refEnv{tcbexternal}.\par |
| 543 |
The environment content is externalized and the external snippet is surrounded |
| 544 |
by an environment \meta{env}. All further parameters of \meta{newenv} |
| 545 |
are given to \meta{env} as parameters. |
| 546 |
\textbf{In contrast to \refCom{newtcbexternalizeenvironment}, the |
| 547 |
environment \meta{env} is intended to be based on \refEnv{tcolorbox} |
| 548 |
or \refEnv{tcblisting}.}\par |
| 549 |
The \meta{begin end options} are options for settings the space before |
| 550 |
and after the included image using \refKey{/tcb/before}, \refKey{/tcb/before skip}, |
| 551 |
\refKey{/tcb/after}, or \refKey{/tcb/after skip}. |
| 552 |
\begin{marker} |
| 553 |
Use the exact identical values for \refKey{/tcb/before} and \refKey{/tcb/after} |
| 554 |
inside \meta{begin end options} as they where used for definition of |
| 555 |
\meta{env}! Otherwise, externalized and non-externalized version will have |
| 556 |
different spacings. |
| 557 |
\end{marker} |
| 558 |
\refEnv{extcolorbox} is an example application for \refCom{newtcbexternalizetcolorbox}. |
| 559 |
|
| 560 |
|
| 561 |
\inputpreamblelisting{M} |
| 562 |
|
| 563 |
{ |
| 564 |
\tcbset{external/preamble={\input{tcolorbox_preamble_M.tex}}} |
| 565 |
\begin{dispExample} |
| 566 |
\begin{exmyownlisting}{example_mylisting}% <- name for the external file |
| 567 |
{My externalized example box} |
| 568 |
This is my \LaTeX\ box. |
| 569 |
\end{exmyownlisting} |
| 570 |
\end{dispExample} |
| 571 |
} |
| 572 |
\end{docCommand} |
| 573 |
|
| 574 |
|
| 575 |
\begin{docCommand}[doc new=2015-03-11]{renewtcbexternalizetcolorbox}{\marg{newenv}\marg{env}\marg{options}\marg{begin end options}} |
| 576 |
Identical to \refCom{newtcbexternalizetcolorbox}, but the environment \meta{newenv} |
| 577 |
is created by |\renewenvironment| instead of |\newenvironment|. |
| 578 |
\end{docCommand} |
| 579 |
|
| 580 |
|
| 581 |
\begin{docCommand}[doc new=2016-07-14]{tcbiffileprocess}{\marg{condition}\marg{source}\marg{md5-file}\marg{target}\marg{true}\marg{false}} |
| 582 |
This is a low-level macro which is internally used. |
| 583 |
The MD5 digest of a \meta{source} file is compared with |
| 584 |
a stored MD5 digest from an auxiliary \meta{md5-file}. |
| 585 |
If they are not equal, the auxiliary \meta{md5-file} is updated to |
| 586 |
store the current MD5 digest. Further, |
| 587 |
\begin{itemize} |
| 588 |
\item if \meta{condition} equals |0|, \meta{true} is executed. |
| 589 |
\item if \meta{condition} equals |1|:\\ |
| 590 |
If the current and stored MD5 digests were different, \meta{true} is executed.\\ |
| 591 |
Otherwise, if the \meta{target} file is not existing, \meta{true} is executed.\\ |
| 592 |
Otherwise, if the \meta{target} file is older than the \meta{md5-file}, \meta{true} is executed.\\ |
| 593 |
Otherwise, \meta{false} is executed. |
| 594 |
\item if \meta{condition} equals |2|, \meta{false} is executed. |
| 595 |
\end{itemize} |
| 596 |
The intended processing purpose of the \meta{true} code is to produce a \meta{target} |
| 597 |
file from the given \meta{source} file. |
| 598 |
\end{docCommand} |
| 599 |
|
| 600 |
|
| 601 |
\clearpage |
| 602 |
\subsection{Troubleshooting and FAQ}\label{subsec:external_troubleshooting} |
| 603 |
|
| 604 |
\begin{itemize} |
| 605 |
|
| 606 |
\item\textbf{I use the default settings, but the |external| subdirectory is |
| 607 |
not created.}\\ |
| 608 |
Depending on operating system and compiler, an |external| subdirectory is |
| 609 |
automatically created or not. If not, create such a directory manually |
| 610 |
or add the following to your document: |
| 611 |
\begin{dispListing} |
| 612 |
\ExplSyntaxOn |
| 613 |
\sys_shell_now:n { mkdir~external } |
| 614 |
\ExplSyntaxOff |
| 615 |
\end{dispListing} |
| 616 |
or |
| 617 |
\begin{dispListing} |
| 618 |
\ExplSyntaxOn |
| 619 |
\sys_shell_now:n { mkdir~-p~external } |
| 620 |
\ExplSyntaxOff |
| 621 |
\end{dispListing} |
| 622 |
If the combination of \refKey{/tcb/external/prefix} and chosen snippet |
| 623 |
name points to another subdirectory than |external|, this has to be |
| 624 |
adapted. |
| 625 |
|
| 626 |
\item\textbf{I use the \refPkg{minted} package and I get a cache directory for |
| 627 |
every externalized snippet.}\\ |
| 628 |
To avoid this problem, there are several ways. |
| 629 |
\begin{itemize} |
| 630 |
\item If you do not need |minted| inside the snippet code, you may use |
| 631 |
|\usepackage{minted}| \emph{after} \refCom{tcbEXTERNALIZE} |
| 632 |
or use \refCom{tcbifexternal} to switch |minted| off for the external code. |
| 633 |
If \refPkg{minted} is already included by another package, add the following to |
| 634 |
your preamble: |
| 635 |
\begin{dispListing} |
| 636 |
\tcbset{external/PassOptionsToPackage={draft}{minted}} |
| 637 |
\end{dispListing} |
| 638 |
\item If |minted| is needed for the snippet code, caching can be switched |
| 639 |
off by adding the following to your preamble: |
| 640 |
\begin{dispListing} |
| 641 |
\tcbset{external/PassOptionsToPackage={cache=false}{minted}} |
| 642 |
\end{dispListing} |
| 643 |
Alternatively, the |cachedir| option of |minted| may be used to redirect |
| 644 |
the cache. |
| 645 |
\end{itemize} |
| 646 |
|
| 647 |
|
| 648 |
\end{itemize} |
| 649 |
|