1

I am trying to automate using ImageMagick in Windows 7 to convert an externalized eps image to a png file. The challenge is that ImageMagick can't be reliably added to the system path because convert is not a unique windows command (see: http://www.imagemagick.org/Usage/windows/#convert_issue). So I have defined an environmental variable called IMAGEMAGICK to be the path to my portable ImageMagick folder: IMAGEMAGICK = C:\Tools\ImageMagick. From the command line I can issue convert commands: %IMAGEMAGICK%\convert myfig.eps myfig.png

The problem here is to get tikz to use the %IMAGEMAGICK% variable, since % is a comment symbol. I have tried this, but it does not work:

\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
    -interaction=batchmode -jobname "\image" "\texsource" && 
    dvips -o "\image".ps "\image.dvi" && 
    ps2epsi \image.ps \image.eps &&
    "\%IMAGEMAGICK\%/convert" -density 1200 "\image.eps" "\image.png" }}

(With the key portion being the final line).

When I look in my log file, the % symbol is not properly escaped:

    ===== 'mode=convert with system call': Invoking 'latex -enable-write18 -halt-on
-error -interaction=batchmode -jobname "tikzpngeps/externalize_png_eps-figure0"
 "\def\tikzexternalrealjob{externalize_png_eps}\input{externalize_png_eps}" && 
dvips -o "tikzpngeps/externalize_png_eps-figure0".ps "tikzpngeps/externalize_pn
g_eps-figure0.dvi" && ps2epsi tikzpngeps/externalize_png_eps-figure0.ps tikzpng
eps/externalize_png_eps-figure0.eps && "\%IMAGEMAGICK\%convert" -density 1200 "
tikzpngeps/externalize_png_eps-figure0.eps" "tikzpngeps/externalize_png_eps-fig
ure0.png"' ========
\openout3 = `externalize_png_eps.auxlock'.

How can I get % to appear in my convert command? Or is there a better alternative to do this?

1 Answer 1

1

I can't test it, but you may get what you want by adding

\makeatletter
\edef\IMAGEMAGICK{\@percentchar IMAGEMAGICK\@percentchar}
\makeatother

in the preamble and using

\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
    -interaction=batchmode -jobname "\image" "\texsource" && 
    dvips -o "\image".ps "\image.dvi" && 
    ps2epsi \image.ps \image.eps &&
    "\IMAGEMAGICK/convert" -density 1200 "\image.eps" "\image.png" }}

Or, maybe,

\makeatletter
\edef\IMAGEMAGICKconvert{\@percentchar IMAGEMAGICK\@percentchar\string\convert}
\makeatother

and

\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
    -interaction=batchmode -jobname "\image" "\texsource" && 
    dvips -o "\image".ps "\image.dvi" && 
    ps2epsi \image.ps \image.eps &&
    "\IMAGEMAGICKconvert" -density 1200 "\image.eps" "\image.png" }}
1
  • Nice -- that first solution worked like a charm. Thanks!
    – elsevers
    Commented Jan 31, 2016 at 19:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .