13

I'm creating some graphs for my thesis in a single .tex file using the TikZ package in LaTeX.
I'm using the standalone document class so that my graphs are generated without whitespaces.

How can I export every graph in a separate PDF file so I can load them individually in another project?

3 Answers 3

15

The tikz library external does just what you want:

\usetikzlibrary{external}
\tikzexternalize

It will generate one PDF per tikzpicture. You can define an output directory with:

\tikzexternalize[prefix=./dir/]

(Without / at the end it simply appends "dir" to the beginning of the output filenames)

1
  • 1
    Note that you may need to add the -shell-escape flag when compiling. E.g. pdflatex -shell-escape main.tex.
    – drumath
    Jun 1, 2022 at 9:08
2

When you compile generate1.tex file, it will produce generate1.pdf file. When you rename the .tex file (f.e. generate2.tex), new pdf will also have different name (generate2.pdf), thus the old pdf won't be deleted.

If you want to display TikZ images only, use \PreviewEnvironment{tikzpicture}. If you are interested, you can find the sample code here.

If you want to load them, use includepdf.

1
  • Instead of renaming the .tex file for every image, you could use the -jobname=... option when compiling. You can include the pdf files just like other images - no need for the includepdf package unless you want them as fullpaper images. Mar 15, 2023 at 20:12
0

How can I export every graph in a separate PDF file so I can load them individually in another project?

You don't need to have them as separate PDF files, you can use the page=... to select the page with the image you would like to include:

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}[htbp]
\centering
\includegraphics[page=42]{example-image-duck}
\caption{cute duck}
\end{figure}

\begin{figure}[htbp]
\centering
\includegraphics[page=99]{example-image-duck}
\caption{even cuter}
\end{figure}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.