# [Tex/LaTex] TikZ to non-PDF

conversiongraphicsstandalonetikz-pgf

How do I tell TikZ to output to a standalone image file? Like JPG, PNG, etc?

Yes, there is a way to output it to PDF, then do a snapshot. But this is for mathematical-visual comparisons, and I need precision trimming so that I can put the images side-by-side in a Word document.

Here's a sample using the standalone class. It only takes care of the length, but the width stays the same as the textwidth

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw [step=0.5] (-1.4,-1.4) grid (1.4,1.4);
\end{tikzpicture}

\end{document}


I want the whole PDF to be trimmed to the edges of the tikzpicture. Or, even better, trim the PDF so that that I can leave (custom) margins around the graphic.

You have empty lines between the document and tikzpicture environment which puts the picture in an paragraph (which is \textwidth wide). Simply removing the lines fixes this:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw [step=0.5] (-1.4,-1.4) grid (1.4,1.4);
\end{tikzpicture}
\end{document}


The rest of your question is already answered in Compile a LaTeX document into a PNG image that's as short as possible.

In short:

pdflatex file
convert -density 300 file.pdf -quality 90 file.png


or with v1.0 of the standalone class:

\documentclass[convert={density=300,size=1080x800,outext=.png}]{standalone}


compile with:

pdflatex -shell-escape file


You might also want to use the new border option to set the border to 0pt.