How can I use arara to get a graphics file?
Here's a simple way to get what you need with standalone
:
% arara: pdflatex: { shell: yes }
\documentclass[
convert,
outext=.png,
tikz,
]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw [red] (0,0) circle [radius=2pt]
(1,1) circle [radius=2pt] (2,1) circle [radius=2pt] (2,0) circle [radius=2pt];
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\end{document}
This will use convert
and needs ImageMagick, which can be easily installed. Conversion using ghostscript
is possible, but you need tweaking the parameters. With the default ones, the conversion with convert
is good, with ghostscript
(that you get by convert=ghostscript
) is quite bad.
The conversion with ghostscript
is obtained with
% arara: pdflatex: { shell: yes }
\documentclass[
convert=ghostscript,
tikz,
]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw [red] (0,0) circle [radius=2pt]
(1,1) circle [radius=2pt] (2,1) circle [radius=2pt] (2,0) circle [radius=2pt];
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\end{document}
Examining the .log
file I see
runsystem(gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -sOutputFile=gsconv-%d.png gsconv.pdf)...executed.
which shows that ghostscript
is called. You may need to do some adjustment to the internal parameters, in particular for helping standalone
in finding the ghostscript executable. I can't be more precise, because I don't have Windows (and never will).
Without using standalone
, you may create a specific arara
rule.
Inspired by the animate
rule provided by cmhughes, I have created a convertgs.yaml
rule and put in ...\MiKTeX 2.9\scripts\arara\rules
(the path varies according to which operating system and TeX distribution you are using, I have MiKTeX):
Note that I have used mgs
because mgs.exe
is the Ghostscript executable which came with the MikTeX 2.9 installation, I have discovered it here, maybe you have to change it with your executable name.
Moreover, I have tested this rule only with Windows 10, even if I think this works also with other operating systems.
!config
# Convert .pdf to any format file allowed by Ghostscript (the default is png)
# author: CarLaTeX
# last edited by: CarLaTeX, November 16th 2016
# requires arara 3.0+
#
# Sample usage:
# - these both create a .png file:
# % arara: convertgs
# % arara: convertgs: {format: png}
#
# - this creates a .ps file:
# % arara: convertgs: {device: ps2write, format: ps}
#
# This rule is really just a shortcut for commands like the following:
#
# mgs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r300 -sOutputFile=myfile.png myfile.pdf
#
# which will output myfile.png
#
# Attention: 1. I have used `mgs` because `mgs.exe` is then Ghostscript executable which came with the MikTeX 2.9
# installation, maybe you have to change it with your executable name.
# 2. I have tested this rule only with Windows 10.
#
identifier: convertgs
name: convertgs
commands:
- <arara> @{ isWindows( "cmd /c mgs", "mgs" ) } -dSAFER -dBATCH -dNOPAUSE -sDEVICE=@{device} -r@{density} -sOutputFile="@{ getBasename(file) }.@{format}" "@{ getBasename(file) }.pdf"
arguments:
- identifier: device
flag: <arara> @{parameters.device}
default: png16m
- identifier: density
flag: <arara> @{parameters.density}
default: 600
- identifier: format
flag: <arara> @{parameters.format}
default: png
(Take also into account that I'm not an expert, maybe this could be done better).
Of course, you have to do this once for all, then it is sufficient to put:
% arara: pdflatex (or any other command you are using to compile)
% arara: ... (possible other commands)
% arara: convertgs
at the beginning of your document and compile it with arara
.
For example, if you have this myfile.tex
:
% arara: pdflatex
% arara: convertgs
\documentclass{article}
\begin{document}
Quack!
\end{document}
and you run arara myfile.tex
, you will get a myfile.pdf
and a myfile.png
.
For an analogous solution with convert
command of ImageMagick see this answer of mine.