[Tex/LaTex] Best practice to include (standalone precompiled) graphics

best practicesgraphicspstricksstandalonetikz-pgf

General understanding

I know that several people have asked about how to include plots and graphics (created by tikz and pstricks) into a latex document.

Now it seems evident to ask how to handle a big number of figures.
At first it seems crucial to pre-compile graphics that should enter the document to reduce the final document's compilation time.

But there are many different ways to perform that issue and actually the package standalone seems the most auspicious.
By trying it, I recognized that all standalone tex-files have to be in the same folder to be compiled if changes were performed. Otherwise it would result in errors (Including pictures in subdirectories with standalone package).

Question

How do I now include graphics like the following MWE (adapted from matlab2tikz for including my macros), in order to have the same common formatting (e.g. font size and shape) for all text in my document including the figure labels?

MWE

\documentclass{article}
\input{Style/macros.tex}
\usepackage{standalone}
\standaloneconfig{mode=buildnew}

\usepackage{filecontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File Style/macros.tex
\begin{filecontents*}{Style/macros.tex}
  \fontsize{10}{12}
\end{filecontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File Documents/test_standalone_slave.tex
\begin{filecontents*}{Documents/test_standalone_slave.tex}
  \documentclass{standalone}
  \input{../Style/macros.tex}
  \usepackage{tikz,pgfplots}
  \pgfplotsset{compat=newest}

  \begin{document}
  \begin{tikzpicture}
  \draw (0,0) circle (2);
  \end{tikzpicture}
  \end{document}
  \endinput
\end{filecontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
This is my MWE!
\includestandalone{Documents/test_standalone_slave}
\end{document}

Best Answer

If I were you, I would do the following:

  1. In order to make your common settings accessible for all figures, diagrams, documents, etc, put the settings into a single package, namely, mycommon.sty. Register this package globally so you can use it throughout your projects. If you don't know how to do this, see my answer here (click).

  2. If you want your diagram or figures to be accessible for other projects, put them in a separate directory that is higher than the project directories. For example,

    <any directory>\Diagrams\
    <any directory>\Diagrams\Projects\Project-01\
    <any directory>\Diagrams\Projects\Project-02\
    
  3. To get a tight drawing for each diagram, use standalone document class as follows

    \documentclass[pstricks,border=12pt,12pt]{standalone}
    \usepackage{mycommon}
    \begin{document}
    % your drawing code goes here...
    \end{document}
    

    Also load your package for common settings.

  4. Compile each diagram with the appropriate compilers to get a PDF version. It will save a lot of your time when compiling the main input file of your projects.

  5. Import the PDF diagrams from within the main input file of your projects. And compile the main input file with pdflatex (recommended because it is fully supported by microtype package). You may also load the mycommon package if necessary.

    \includegraphics from graphicx will do the job of importing diagrams. You can set \graphicspath{{../../Diagrams/}} to shorten your path when invoking \includegraphics.

Related Question