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.
- 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.
- 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"
else
"${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -e "\$TSUserCompileOptions=-shell-escape" -r "${TSBIN}/pdflatexmkrc" ${localrc} "$1"
fi
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.
$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 '19 at 01:44% !TEX parameter = —shell-escapedirective is that you don’t want to use it for all documents. All recent latexmk based TeXShop engines accept that directive and pass that flag to the underlying engine. – Herb Schulz Mar 22 '19 at 18:12