How does one specify command-line options (such as -shell-escape) to pdflatex while using pdflatexmk engine in TEXShop other than in the Source file? Is there a way to specify that in Preferences?

According to Herb Schultz's "Using latexmk with TeXShop" guide, one way to specify pdflatex command-line options is in the Source file itself. But I wish to keep separate the Source files and the command-line options for the typesetting program.

  • Do you mean something like this? pdflatexmk -pdf -pdflatex="pdflatex --shell-escape %O %S" Mar 22, 2019 at 0:03
  • 1
    Welcome to TeX.SE!
    – Mensch
    Mar 22, 2019 at 0:08
  • @MajidAbdolshah, Where would I place that command? Thanks.
    – user650654
    Mar 22, 2019 at 0:11
  • @user650654 Which Operating System do you use? Maybe you want to have a look in here?: tex.stackexchange.com/questions/139173/…. Mar 22, 2019 at 0:28
  • Thanks for the pointer, @MajidAbdolshah. It's a bit of a hack, but that might work. Things have changed a bit since that posting it seems. In TeXShop v4.26, there is a file ~/Library/TeXShop/bin/latexmkrcedit that can be edited to define $TSUserCompileOptions = '--shell-escape';. This change will be reflected for all users, however. I wish there was a cleaner way, but I suppose this will do for now. Thanks.
    – user650654
    Mar 22, 2019 at 1:44

1 Answer 1


Thanks for the comments, @MajidAbdolshah and @HerbSchulz. The following answer is based on their comments.

There are two options. Both have their pros and cons.

  1. Create a new engine as described in tex.stackexchange.com/q/139173. The pdflatexmk.engine must have changed since that post - now there is a TSUserCompileOptions variable. See below for a sample. The advantage is that this engine can be selected in TeXShop only when desired. The disadvantage is that this file needs to be created, installed in the right place and so on and may not carry over to the next version of TeXShop.
  2. Add a directive - % !TEX parameter = —shell-escape - at the top of the main file (I believe in the first 20 lines). The advantage is that this directive is limited to only this file (or project). The disadvantage is that directives to the typesetting program are embedded in the source file. I guess this paradigm has been in practice for quite some time, but nonetheless there is something a bit bothersome about this to me. [As a side note, this directive ends up as the second argument, ${2}, to latexmk in the bash script.

Modifications in your new engine file (pdflatexmk-shell.engine, copied from pdflatexmk.engine) should look something like below:

if [ -n "${2}" ] ; then
"${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -e "\$TSUserCompileOptions='-shell-escape ${2}'" -r "${TSBIN}/pdflatexmkrc" ${localrc} "$1"
"${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -e "\$TSUserCompileOptions=-shell-escape" -r "${TSBIN}/pdflatexmkrc" ${localrc} "$1"

The bash script, pdflatexmk.engine can be found in ~/Library/TeXShop/Engines/ or in ~/Library/TeXShop/Engines/Inactive/Latexmk/ and the file you create needs to be placed in ~/Library/TeXShop/Engines/. After restarting TeXShop, it should appear as one of the engines in the drop-down at the top.

One other option would be to allow for each engine to be configured in the app Preferences. This route is available for some engines (such as LaTeX and and BibTeX), but not all.

You must log in to answer this question.

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