TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use the auto-pst-pdf package and therefore I need the --shell-escape option to be enabled. I did this in my TeXShop preferences as follows:

enter image description here

However when I use pdflatexmk (by writing % !TEX TS-program = pdflatexmk on the first line) to compile my document the option is not taken into account and auto-pst-pdf can not be used.
How do I enable the --shell-escape command with pdflatexmk?

I use TeXShop 3.24 on Mac OSX with pdflatexmk version 4.37.

share|improve this question
The pdflatexmk works fine without the auto-pst-pdf package as this does not require the --shell-escape option. As far as I can tell the related questions are about getting latexmk to work basically, but I already have that working. – Saaru Lindestøkke Oct 16 '13 at 17:56
use as command pdflatexmk -pdf -pdflatex="pdflatex --shell-escape %O %S" – Herbert Oct 16 '13 at 18:24
up vote 6 down vote accepted

Navigate to your ~/Library/TeXShop/Engines folder and duplicate the file pdflatexmk.engine to, say, pdflatexmk-shell.engine. Then open this file with TeXShop itself and add the -pdflatex="pdflatex --shell-escape %O %S" option: here's how the file should be:

export TSBIN="$HOME/Library/TeXShop/bin/tslatexmk"
export LTMKBIN="$HOME/Library/TeXShop/bin/tslatexmk"
export LTMKEDIT="$HOME/Library/TeXShop/bin"
# make sure latexmkrcedit exists in bin
if [ ! -e "${LTMKEDIT}/latexmkrcedit" ] ; then
    cp "${LTMKBIN}/latexmkrcDONTedit" "${LTMKEDIT}/latexmkrcedit"
"${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -r "${TSBIN}/pdflatexmkrc" -pdflatex="pdflatex --shell-escape %O %S" "$1"

Now, if you start your document with

% !TEX TS-program = pdflatexmk-shell

the shell escape will be enabled.

Here's a copy of the console when a file with that magic line is processed:

Latexmk: This is Latexmk, John Collins, 2 July 2013, version: 4.37.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Rule 'pdflatex': File changes, etc:
   Non-existent destination files:
Run number 1 of rule 'pdflatex'
Running 'pdflatex --shell-escape  -recorder  "bart.tex"'
Latexmk: applying rule 'pdflatex'...
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2013/texmf-dist/tex/latex/base/size10.clo)) (./bart.aux)
(./bart.aux) )</usr/local/texlive/2013/texmf-dist/fonts/type1/public/amsfonts/c
Output written on bart.pdf (1 page, 11541 bytes).
Transcript written on bart.log.
Latexmk: Log file says output to 'bart.pdf'
Latexmk: All targets (bart.pdf) are up-to-date

The lines

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
 \write18 enabled.

are the proof that shell escape is enabled.

share|improve this answer

If you're open to other automation tools, I would highly recommend arara. Integration with TeXShop (which I assumed is your chosen IDE) and any other editor is easy and is covered in the documentation.

To enable --shell-escape you simply give the directive

% arara: pdflatex: {shell: yes}
share|improve this answer
Thank you for the suggestion, it looks like a powerful tool. However I'm looking for a quick way to use psfrag with pdflatexmk and using a whole new tool for this sounds like overkill to me. – Saaru Lindestøkke Oct 16 '13 at 21:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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