6

In a standard TeX Live distribution Ghostscript is, to my knowledge, present; it is hidden, but it is there.

Edit: Yes, it is under

\Texlive\2013\tlpkg\tlgs 

So to my question:

How can I use arara, to activate the internal Ghostscript to get a graphics file as an output? For example mydocument.png (in addition to mydocument.pdf).

Note, that I do not ask, how can I convert a PDF to a PNG (we know there are 1000s of possibilities), I am interested to use only internal TeX Live tools (that means NO extra software) and let arara do the job.

  • 1
    Knowing how you would use ghostscript to make the PNG files from the PDF is better. Is it a single page PDF? Do you want to crop it to a minimal bounding box? However, as far as I know, ghostscript is not included in TeX Live. – egreg May 11 '14 at 19:59
  • Oh, that is a good question. For example: I create a TikZ-picture in the standalone-class, so I am interessted to have that as a png. I also thought about the preview-package, to get special parts of my document as a preview; and this I would like to have as a png too ;) – cis May 11 '14 at 20:02
  • Which platform are you on? MacTeX includes some extras although it did not used to provide ghostscript as far as I know. It did used to provide a stripped down convert independent of ImageMagick. No idea if I am misremembering or if, if not, it still does, though... – cfr May 12 '14 at 1:42
  • Ghostscript can be found under \Texlive\2013\tlpkg\tlgs in windows ;) – cis May 12 '14 at 13:58
2

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.

8

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).

  • Thank you! So we have a solution with the extra-software ImageMagick. But I ask me, if there is a elementary solution with the ghostscript, wich you can found under \Texlive\2013\tlpkg\tlgs (in Windows)? – cis May 12 '14 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.