# Figure preview wrapper

How do I best preview my figures? I have one file with this:

\begin{figure}
\begin{tikzpicture}  %if tikz
...
\end{tikzpicture}
\includegraphics{...}  %if eps
\caption{...}
\label{fig:..}
\end{figure}


and I can use it in my papers with \input{...}, but to preview my figure, I need some compilable wrapper like this:

\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{tikz}
\begin{document}
\input{FIGURENAME}
\end{document}


Is there a way to write this wrapper in a way, so it can be used for all my figures? or is there a better way to do this? shellscript?

-

Simply use the standalone class for your tikzpicture files and then use the standalone package in your main document to ignore the preamble. This way you can compile the picture alone and as part of an or multiple documents. In standalone mode the output file is automatically cropped to the picture size.

Each picture is in its own file which looks like:

% somepic.tex
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (10,10); % ...
\end{tikzpicture}
\end{document}


And the main document:

% maindocumen.tex
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{standalone}
\begin{document}

% text ...

\begin{figure}
\input{somepic}
\caption{...}
\label{fig:..}
\end{figure}

% text ...

\end{document}


I'm working on a new version which provides \includestandalone which is also able to include the PDF or EPS generated from the picture file instead of input the file.

-
Cool - this is just what I need. I can see, that you consider \begin{figure} and \caption{} to be part of the main doc and not the figure. I do not do doubt your reason, but why!? – Hans-Peter E. Kristiansen Oct 17 '11 at 16:04
@Hans-PeterE.Kristiansen: This has multiple reasons. You might want to insert the same picture into multiple documents (e.g. paper, presentation & thesis) with different captions or using a different form like a non-float or subfigure. Then, figure is a float and standalone uses preview by default which removes all white space around it, but can't handle floats. It stores the content in a box which doesn't work with floats. See also my recent answer to Nested standalone files with standalone package. – Martin Scharrer Oct 17 '11 at 16:09
It is not working - what am I doing wrong. pdf is ok. dvi is partly outside page - shown with xdvi. ps from dvips is empty - shown with mac preview. .... Mac OS X 10.6.8 (10K549), pdfTeX 3.1415926-1.40.11-2.2 (TeX Live 2010), Preview Version 5.0.3 (504.1). This is dvips(k) 5.99, xdvik version 22.84.16 (Xaw toolkit) Libraries: kpathsea version 6.0.0, T1lib version 5.1.2 – Hans-Peter E. Kristiansen Oct 18 '11 at 5:32
@Hans-PeterE.Kristiansen: This seems to be a problem of the underlying preview package. Try with preview=false as class option in the pictures files. This won't crop the white space but avoid this things. – Martin Scharrer Oct 18 '11 at 7:52
@Hans-PeterE.Kristiansen: I now released v1.0 of standalone which provides a new option crop as alternative to preview. It should fix certain problems with the preview option. There is also a float option to allow floating environments inside subfiles (but they are turned to non-floats in standalone mode). Both new options are turned on by default in v1.0. – Martin Scharrer Dec 21 '11 at 16:21