TikZ to non-PDF
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
.
This is a complement to the Martin Scharrer's answer for the particular case of Windows. This answer is not exhaustif, but gives a particular configuration that works for me.
Installation under Windows (checked with XP/7/10)
- Install GhostScript;
- Put the folder (something like
C:\...\Ghostscript\bin
) containinggswin32c.exe
in thePATH
; - Create a folder named
StackExchange
where you will put all your questions and answers for TeX.SX; In this folder create a file
standalone.cfg
with the following content\input{standalone/standalone.cfg} \standaloneconfig{convert={ghostscript, density=700, command={\gsexe\space -dDownScaleFactor=4 -dSAFER -dBATCH -dNOPAUSE -sDEVICE=\gsdevice\space -r\density\space -sOutputFile=\outfile\space \infile}}}
Use as model for your question/answer in this folder something like
\documentclass[tikz,border=7pt]{standalone} % \usetikzlibrary{ } \begin{document} \begin{tikzpicture} \fill[red] (0,0) circle (1); \end{tikzpicture} \end{document}
And now just compile your tex
file with the option -shell-escape
and you will obtain a PNG
with the same name and "resonable" default size.