1

I'm trying to use the standalone package to produce .jpeg files from my TiKz code. I use TexStudio and Windows 8.1. I have both pdf2svg and ImageMagik installed.

If I use the following code, TeXstudio hangs on me.

\documentclass[convert={density=800x300,outext=.jpg}]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,1) node [midway] {Example};
\end{tikzpicture}
\end{document}

If I change the code to:

\documentclass{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,1) node [midway] {Example};
\end{tikzpicture}
\end{document}

Then use a terminal to convert the file the command

convert standalone_test.pdf standalone.jpeg

Produces a horribly small image horribly small image

Using the terminal command

convert standalone_test.pdf -resize 800x300 standalone_test.jpeg

Simply gives me a black rectangle a black rectangle

Any help would be appreciated.

BenK-G
  • 77
  • For the convert command, use the "density" option as in "convert -density 300x300 file.pdf file.png" – James Mar 17 '16 at 15:55
  • Hi James, although this helps with the size, now the text in the resultant file (axis labels for example) looks a bit shoddy. Image Any idea how to rectify this? – BenK-G Mar 17 '16 at 16:18
  • Increase the "300x300" to "600x600" or higher as necessary. The density numbers relate the PDF size to the number of pixels. For example, a 1 inch square in PDF will result in a 300x300 pixel PNG file. – James Mar 17 '16 at 17:04

2 Answers2

3

Once you have created your PDF image, you can convert it at difference resolutions using varying density values in the convert command.

convert -density 150x150 sample.pdf sample_150.png
convert -density 300x300 sample.pdf sample_300.png
convert -density 600x600 sample.pdf sample_600.png

enter image description here

enter image description here

enter image description here

James
  • 4,587
  • 1
  • 12
  • 27
3

standalone can do automatic conversions with convert options. It assumes that Imagemagick convert is installed but for windows systems it uses imgconvert instead of convert to avoid name confusion with another program.

The problem is that ImageMagick's converter is also named convert in windows systems and automatic conversions fail because imgconvert is not found.

A possible solution could be to specify convertexe=convert suboption in standalone convert option. This way, the correct executable is called even in windows systems.

As a simple example something like

\documentclass[tikz, convert={convertexe=convert,density=800x300,outext=.jpg}]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (2,1) node [midway] {Example};
\end{tikzpicture}
\end{document}

should not hang in TeXstudio.

Ignasi
  • 136,588
  • Brilliant! Thank you very much. This code indeed doesn't hang TeXstudio and does exactly as I want. – BenK-G Mar 18 '16 at 08:54