10

I am using \tikzexternalize to compile my pictures outside of the main document.

However, when I issue simple \tikz commands within the text, I'd like them to be compiled within the main document, to save some time.

Is there a way to turn externalization on/off, or to just limit it to the tikzpicture environment?

2 Answers 2

14

The global externalization setting can be temporary disabled/enabled (until the end of the TeX group) using \tikzexternaldisable and \tikzexternalenable. Another option is to set the /tikz/external/export={true/false} key; the variant /tikz/external/export next={true/false} applies only for a single picture.

All these are described in the chapter "Externalization Library" of the TikZ userguide.

2
  • Oops! I was using an older version of the manual :)
    – yannick
    Feb 19, 2013 at 22:38
  • Thanks! This answer explains it in a little more detail: tex.stackexchange.com/a/14573/84434 An important notice is that if externalization is disabled using \tikzset{external/export=false} then it cannot be turned back on for a single picture using \tikzset{external/export next=true}. For beamer I ended up with using \tikzset{external/only named=true} and \tikzsetnextfilename{myfigure}% on heavy images only.
    – F1iX
    Nov 10, 2020 at 7:40
3
  1. put this at the begin of your preamble

     \usepackage{etoolbox}
     \providetoggle{externalize}
     \settoggle{externalize}{true}
    
  2. put this at the end of your preamble, and most important, after \makeindex

     \newcommand{\notexternal}{%
       \iftoggle{externalize}{\tikzset{external/export next=false}}{}
     }
    
     \iftoggle{externalize}{\tikzexternalize[prefix=figures-compiled/]}{}
    
  3. put \notexternal before tikz environment/command you don't want to be externalized

In this way:

  • you have a short command to disable externalization for a single picture
  • you can disable externalization for the whole document by changing \settoggle{externalize}{true} to \settoggle{externalize}{false}, without having to change anything else

EDIT: Alternative version

Externalized pictures are named incrementally, and if you add/remove/swap pictures in your document you have to recompile them all, unless you specify the name for each picture, which can be done with this code:

  1. unchanged

  2. new code:

     \newcommand{\externalize}[1][]{%
       \iftoggle{externalize}{%
         \ifstrequal{#1}{false}{%
           \tikzset{external/export next=false}%
         }{%
           \ifstrempty{#1}{%
             \ifcurrfiledir{./figures/}{%
               \tikzsetnextfilename{\currfilebase}
             }{}
           }{%
             \tikzsetnextfilename{#1}
           }
         }
       }{}
     }
    
     \iftoggle{externalize}{\tikzexternalize[prefix=figures-compiled/]}{}
    
  3. three alternatives:

    • put \externalize[false] before tikz environment/command you don't want to be externalized
    • put \externalize[figure_a] if you want the external picture to be named figure_a.pdf
    • if the picture is included in your document with \include{./figures/figure_1.tex}, you can put \externalize with no argument if you want the external picture to be named figure_1.pdf (if the file is not in the figures folder, it will be named incrementally)
    • don't put anything if you want the figure to be externalized and named incrementally
2
  • 1
    I believe that you can disable externalization for the whole document by changing \settoggle{externalize}{true} to \settoggle{externalize}{true}, without having to change anything else should read you can disable externalization for the whole document by changing \settoggle{externalize}{true} to \settoggle{externalize}{false}, without having to change anything else Aug 13, 2021 at 9:47
  • 1
    @PjancMatuzl you're right, I corrected the answer Aug 13, 2021 at 13:23

You must log in to answer this question.

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