I would like to use AUCTeX to create a PNG image of a TikZ picture using the standalone
package. I use macOS Sierra.
According to the standalone
documentation v1.2-2015/07/15 (section 4.6 Conversion to images, p. 15)
Using the
convert
class option the standalone file can be easily converted to an raster image. This is done by executing an external program to convert the output file (PDF or PS) to an image (recommended is the lossless PNG format, but also others are supported).
According to subsection 4.6.1 Conversion settings (p. 15)
Conversion settings can be given as the value of the
convert={<settings>}
option. By default conversion is disabled(convert=false)
. If enabled without providing own settings (convert,convert=true
) the following default settings are used: PNG format, a density of 300dpi, no explicit size and the output file name is given by\jobname
, i.e. the name of the LaTeX document. Using theconvert
option with any value other thanfalse
will enabled it.
According to section 4.6.2 Conversion software (p. 16)
The conversion requires an external image converter program to be installed. By default the two following tools are supported and either of them must be installed in order to use the conversion feature. In order for an external program to be executed the
-shell-escape
option must be used for the compiler executable, e.g.pdflatex -shell-escape filename
. Without this option no conversion is possible.By default the conversion program of Image Magick is used for PDF LaTeX files [...]
So I used Homebrew (a popular package manager for macOS) to install Image Magick. It was installed in the directory /usr/local/Cellar/imagemagick/7.0.6-0
. I then added the following lines to my Emacs init file (~/.emacs
) so that Emacs would know where to look for the Image Magick executables:
(setenv "PATH" (concat (getenv "PATH") ":/usr/local/Cellar/imagemagick/7.0.6-0/bin/"))
(setq exec-path (append exec-path '("/usr/local/Cellar/imagemagick/7.0.6-0/bin/")))
After restarting Emacs, I wrote the following LaTeX manuscript, called my_tikz_drawing.tex
:
\documentclass[tikz,convert]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (1,1)
[rounded corners] -- (2,0) -- (3,1)
[sharp corners] -- (3,0) -- (2,1);
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-engine: default
%%% TeX-command-extra-options: "-shell-escape"
%%% End:
and compiled it using C-c C-a
.
The result was a PDF file, but the PNG file was not created, at least not in the same directory where the LaTeX manuscript was.
I then opened Terminal (the macOS command-line console), cd
-ed to the directory containing the LaTeX manuscript, and executed the following command:
pdflatex -shell-escape my_tikz_drawing
The result was a my_tikz_drawing.png
file in the same directory.
A possible clue
Executing the following command, which is found in the log file, once from the Terminal and once from Emacs (using M-!):
convert -density 300 my_tikz_drawing.pdf -quality 90 my_tikz_drawing.png
yields the following results.
From the Terminal: The command executes silently and creates the file
my_tikz_drawing.png
.From Emacs: No PNG file is created, and an error message shows in the mini-buffer:
convert: no images defined 'my_tikz_drawing.png' @error/convert.c/ConvertImageCommand/3254.
This is the same error that appears in the output from the Emacs pdflatex run.
-shell-escape
option.el
files. Thus when I try your code, my Emacs just ignores the optionC-c C-l
in Emacs (C might not be Ctrl on the Mac). That opens the log. The exact command executed is listed at the start of the log. Where exactly did you get therunsystem
part from?