2

My paper was accepted with all tikz pics, but now editors say all pics need to be PNG/JPG etc. What is the best way to do it? These pictures are both in figures and picture equations. So there are a LOT of pictures. One lazy way to do it is take screenshots? But does anyone know a better way.

Martin Scharrer
  • 262,582
obi wan
  • 21

3 Answers3

1

Use the externalization library for TikZ. There's very comprehensive documentation in the pgf/TikZ manual, but as a simple example I have the following in my preamble (I'm on Linux and using luaLaTeX, there are variants for other systems):

% Use these lines when creating the document, comment out when sending to publisher
\usetikzlibrary{external}
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource" && pdftoppm -png "\image.pdf" > "\image.png"}}

% Un-comment this line when sending to publisher
%\usepackage{tikzexternal}

\tikzexternalize

When creating the document, this will make pngs of all TikZ pictures, regardless of where they are in the document. Once everything is ready, switch which bits are commented and then it will simply include those pictures in place of the original code.

Couple of other things to note:

  1. When working on a diagram, it's best to turn off externalisation for that specific diagram (it hides compilation errors so it's hard to debug an error). Put \tikzset{external/export next=false} just before that picture to avoid externalisation.

  2. If you shuffle images around a bit, giving them unique names can be helpful. The command \tikzsetnextfilename is what you should use for that.

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
0

You can export it into pdf file and then with Acrobat PRO crops figures, but it requires time, on the other hand, you will get vector graphics.

0

Pdftocairo tools

pdftocairo is a tool for converting PDF files to images, and it supports converting PDF to PNG, jpeg, tiff, ps, eps, SVG, and more.

For example, you can use the pdftocairo -r 600 -png demo.pdf command on the command line to convert a demo.pdf file to a PNG image file with a resolution of 600 ppi named demo-1.png.

The standalone document class parameters are used for the transformation

If you use the standalone document class, you can specify the conversion mode directly in its parameters and directly compile the *.tex LaTeX source file to get both the PDF file and the converted image file.

The document class parameter code to achieve the transformation can be:

\documentclass[margin=5pt,
convert,
convert={
outext=.png,
command=\unexpanded{
pdftocairo -r 600 -png \infile % Convert the generated PDF file to a PNG image
}
}
]{standalone}

example: Compile using pdflatex --shell-escape

\documentclass[margin=5pt,
convert,
convert={
outext=.png,
command=\unexpanded{
pdftocairo -r 600 -png \infile % Convert the generated PDF file to a PNG image
}
}
]{standalone}
\usepackage{mwe}
\begin{document}
  \includegraphics{example-image}
\end{document}
sikouhjw
  • 461