latexbuildbuild-processpdflatextikz

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 ?


Solution

  • 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 document class 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}