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