TransWikia.com

Does tikz 2.1 no longer work with the preview package?

TeX - LaTeX Asked by crobar on August 4, 2021

I used to be able to create png images of diagrams made with tikz code by using the preview package and printing the dvi output from dvips to a png file using ghostscript. The latest version of tikz seems to have broken this ability in some way.

If I use the following latex code:

documentclass{article}
usepackage{tikz}
usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks}
usepackage[graphics,tightpage,active]{preview}
PreviewEnvironment{tikzpicture}

begin{document}
begin{tikzpicture}
    draw (0,0) rectangle (1,1);
end{tikzpicture}
end{document}

I then run Latex to get the dvi file, and dvips to convert to postscript. I then run ghostscript to produce the png with the following command:

gswin32c.exe -sDEVICE=png16m -dTextAlphaBits=4 -r300 -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE -sOutputFile="tikz_preview_png_problem.png" -f "tikz_preview_png_problem.ps"

Previous to tikz 2.1 this worked fine, but now produces the following output:

Error: /undefined in pgfo
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval-
-   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   fa
lse   1   %stopped_push   1878   1   3   %oparray_pop   1877   1   3   %oparray_
pop   1861   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval-
-   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringv
al--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1161/1684(ro)(G)--   --dict:0/20(G)--   --dict:74/200(L)--   --dict:95
/300(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 9094
GPL Ghostscript 8.71: Unrecoverable error, exit code 1

Is there any way to get around this, it’s a pain in the bum as I liked to be able to produce high res png of my vector graphics for use in non-latex docs or websites etc. I’m using Miktex on windows with Texniccenter as my editor in case it is relevant.

One Answer

I poked around a bit and I couldn't figure out what is going wrong with the Postscript pipeline. My preferred method of generating standalone images uses the PDF pipeline along with ImageMagick's convert utility. The workflow is considerably simpler:

pdflatex foo.tex
convert -density 300 foo.pdf foo.png

Windows binaries can be found here, but there are two caveats:

  • You will need gswin32c.exe on your PATH as convert requires GhostScript to get images out of PDF or PS format.

  • convert.exe will have to be before Windows binaries on the PATH as there is a system32 tool also called convert.exe that shares the same name. Or you will have to rename convert.exe to something like imconvert.exe.

The Rapid Environment Editor is a nifty tool that can help you sort the Windows PATH.


Update

It appears there was indeed a change in TikZ 2.10 that broke compatibility with Preview on the Postscript side. There are two prior bug reports that reference this problem and a post on the PGF mailing list that pins the problem down to a line in pgfsys-dvips.def.


Update 2

Since the problem is with TikZ producing broken Postscript and not with GhostScript, then gswin32c should be able to perform the conversion on a PDF file:

pdflatex foo.tex
gswin32c -sDEVICE=png16m -dTextAlphaBits=4 -r300 -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE -dBATCH -sOutputFile=foo.png foo.pdf

This would spare the installation and setup of ImageMagick.

Correct answer by Sharpie on August 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP