4

I have a paper that I wrote with a lot of figures generated with tikz, but I've been asked to supply a version that doesn't use any "nonstandard tricks", i.e. with the images included with \includegraphics instead.

Of course I can go through and generate a separate pdf of each tikz image, then include them in my LaTeX document and fiddle around getting the layout the same - but I was wondering if there is a way to automate some or all of this process.

So is there an existing way to automatically go through every tikz picture in a LaTeX document and create a pdf image, with the appropriate dimensions so that it will be the same size when inserted with \includegraphics?

3
  • I use \tikzexternalize for all my tikzfiles which generates a nice pdf with proper dimensions for all figures. Having this pdfs, you could just once search and replace throughout your document and everything would be alright. I could give you my code in case you are interested.
    – bene
    Commented Oct 17, 2014 at 8:41
  • @bene thanks, \tikzexternalize is exactly what I was looking for. Please post it as an answer so I can accept. (Unfortunately in my case it fails for all but one of my images with some mysterious font-related error, so I suspect this job is going to be a bit of a headache.)
    – N. Virgo
    Commented Oct 17, 2014 at 8:53
  • Huh. When I used \tikzexternaldisable and \tikzexternalenable to cut out the first figure (the one that was working), all the rest started working. I've no idea why, maybe it's because that one used circuitikz. But in any case I've got pdfs for all my plots now, which is great. (Just posting this in case someone has the same issue in the future.)
    – N. Virgo
    Commented Oct 17, 2014 at 9:19

1 Answer 1

5

You can use the externalization library. I added an automatic regeneration feature which fits better for me than the one which is implemented in the pgf-package.

in your header:

\usepackage{filemod}             % needed for tikz externalization automation
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/figure list=true}
\tikzset{external/up to date check=simple} % manual up to date check with filemod
%%% tikz include command
\newcommand{\tikzcustomremake}[2]{%
  \tikzset{external/remake next}%
  \message{figure #2 was automatically rebuilt}%
}
\newcommand{\includetikz}[2]{%
  \tikzsetnextfilename{#1tikz_external/#2}%
  \filemodCmp{#1#2.tikz}{#1tikz_external/#2.pdf}%
    {\tikzcustomremake{#1}{#2}}% tikz is newer => remake
    {}%
  \input{#1#2.tikz}%
}

in your document:

%\tikzset{external/export=false}
\begin{figure}[htbp]
  \centering
  \small\includetikz{fig/matlab/}{plot5}
  \caption{title}
  \label{fig:tikz5}
\end{figure}

You must log in to answer this question.

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