Standalone charts with TikZ?

I use TikZ to draw diagrams in LaTeX, which I then want to highlight as image files for online search. I assume that there is a way to extract these diagrams directly without teasing them from the finished .pdf file. How should I do it? (If that matters, I use TeXnicCenter.)

+67
latex tikz
Apr 23 2018-10-10T00:
source share
6 answers

Following my comment: Cirkuit converts TikZ diagrams to images, running something like the following sequence of commands:

pdflatex img.tex pdftops -eps img.pdf convert -density 300 img.eps img.png 

Here img.tex will be the LaTeX file following this template:

 \documentclass{article} \usepackage{tikz,amsmath,siunitx} \usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks} \usepackage[graphics,tightpage,active]{preview} \PreviewEnvironment{tikzpicture} \PreviewEnvironment{equation} \PreviewEnvironment{equation*} \newlength{\imagewidth} \newlength{\imagescale} \pagestyle{empty} \thispagestyle{empty} \begin{document} \begin{tikzpicture} % (your TikZ code goes here) \end{tikzpicture} \end{document} 

If you can use Cirkuit or a similar editor or write a script for yourself to put your diagram in this template and run the corresponding tools, you will have a quick way to convert the TikZ code to a PNG image.

To answer your question in more detail ... no, I don’t know how to convert a TikZ diagram directly to PNG without going through a PDF file (or at least a DVI) at some point.

+20
Apr 23 '10 at 21:19
source share

I would recommend you the following approach. Put the tikz image in a separate file and use the "standalone" class to compile it separately. It uses the preview package mentioned in other answers. To include an image in the main document, first download the "stand-alone" package and use \ input in the image file.

This will allow you to get one borderless tikz PDF file. Then you can use the PNG converter in PDF format to get PNG (recommended for web publishing of drawings). The SVG format would be more enjoyable because it is a vector format, but not all browsers could display it.

Here is a sample code:

Tikz image file (for example, "pic.tex"):

 \documentclass{standalone} \usepackage{tikz} % all other packages and stuff you need for the picture % \begin{document} \begin{tikzpicture} % your picture code \end{tikzpicture} \end{document} 

Main document:

 \documentclass{article} % or whatever class you are using \usepackage{standalone} \usepackage{tikz} % All other packages required \begin{document} % Text text text % somewhere where you want the tikz picture \input{pic} % Text text text \end{document} 

Then compile the image and convert it, for example. with ImageMagick (e.g. under Linux):

 pdflatex pic convert -density 600x600 pic.pdf -quality 90 -resize 800x600 pic.png 

or try SVG:

 convert pic.pdf pic.svg 
+52
Apr 24 '10 at 8:14
source share

See the Tikz "External Graphics" section of the manual. This allows you to make EPS or PDF versions of your graphics. I use EPS files, convert them to TIFF and then I can place them where I need to.

+9
Apr 24 '10 at 15:57
source share

I usually use something in these lines:

 \documentclass{article} \usepackage[pdftex,active,tightpage]{preview} %\setlength\PreviewBorder{2mm} % use to add a border around the image \usepackage{tikz} \begin{document} \begin{preview} \begin{tikzpicture} \shade (0,0) circle(2); % background \draw (0,0) circle(2); % rim \draw (.75,1) circle(.5); % right eye \fill (.66,.9) circle(.25); % right pupil \draw (-.75,1) circle(.5); % left eye \fill (-.66,.9) circle(.25);% left pupil \fill (.2,0) circle (.1); % right nostril \fill (-.2,0) circle (.1); % left nostril \draw (-135:1) arc (-135:-45:1) -- cycle; % mouth \end{tikzpicture} \end{preview} \end{document} 

The generated PDF file contains a separate TikZ image. To convert it to any other file format, just open it with Gimp.

+7
Apr 23 2018-10-23T00:
source share

I use this for the Makefile rule to create PNG files and thumbnails from .tex files containing one tikzpicture each. It works similarly to creating images on TeXample.net :

 % .png:% .tex
         @sed 's / ^ \\ begin {document} / \
 \\ pgfrealjobname {dummy} \\ begin {document} \\ beginpgfgraphicnamed {example} / '$ <|  \
 sed 's / ^ \\ end {document} / \\ endpgfgraphicnamed \\ end {document} /'> example.tex;  \
         pdflatex --jobname = example example.tex;  \
         gs -dNOPAUSE -r120 -dGraphicsAlphaBits = 4 -dTextAlphaBits = 4 -sDEVICE = png16m \
 -sOutputFile = $ @ -dBATCH example.pdf;  \
         convert -thumbnail 200 $ @ $ (addsuffix .thumb.png, $ (basename $ @));  \
         mv example.pdf $ (addsuffix .pdf, $ (basename $ <));  rm example. *

ghostview ( gs ) can probably be replaced with convert , and you can replace example with a different tempfile prefix.

+2
Aug 10 2018-10-10 at
source share

Windows: just to be completely explicit for noobs like me

Use the prewiew package as described in your Xabi latex code above to remove the fields.

Install MIktex and Inkscape and use the following bat file:

 cd = "C:\Path to tex" pdflatex input-file-name.tex "C:\Program Files (x86)\Inkscape\inkscape.exe" input-file-name.pdf --export-plain-svg=output-file-name.svg 
+2
Feb 07 2018-12-12T00:
source share



All Articles