Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latex, TikZ and separate compilation of chapters and figures

I have fairly large Latex document with a lot of TikZ figures inside. I have a habit of frequent recompilation and it takes forever to compile it using pdflatex. Figures in TikZ take most of the time.

My question is what is the best way to split the document into separate tex files (figures/chapters) to achieve separate compilation of figures and chapters, separate chapter pdfs, and a whole document pdf file ?

like image 933
Łukasz Lew Avatar asked Jul 14 '10 17:07

Łukasz Lew


2 Answers

Have you tried compiling each picture on its own and then including them in your tex file as pdf rather than the tikz code? You can use the package standalone so that the picture will be the exact size you need. So :

\documentclass{standalone}

\usepackage{tikz,pgf} %and any other packages or tikzlibraries your picture needs

\begin{document}

\begin{tikzpicture}

%your tikz code here

\end{tikzpicture}

\end{document}

The good thing about this is that you can either include the compile this document directly to get a pdf figure to include in your document, or you can use the command \input to include it in your main document as a tikz code by adding

\usepackage{standalone}

in your main document (together with the tikz packages and libraries), and then

\begin{figure}
\input{tikzfile.tex}
\end{figure}
like image 188
Vivi Avatar answered Sep 23 '22 09:09

Vivi


There is a possibly better way (imho) to cache tikz-pictures. Add the following lines in your preamble:

\usetikzlibrary{external}
\tikzexternalize[prefix=i/]

After a pdflatex-run you'll see all pictures in the subdirectory ./i . If you update the code of a tikz-picture simply throw away its corresponding pdf-file and it will be regenerated. For more info see the manual of PFG/TikZ section 32.4 Externalizing Graphics and possibly 32.5 Using External Graphics Without pgf Installed.

like image 22
Chris Avatar answered Sep 19 '22 09:09

Chris