Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am having a problem converting this pdflatex command to use latexmk:

pdflatex --file-line-error --shell-escape --synctex=1 \
         -jobname=foobar "\def\MyCustomDef{} \input{file-name.tex}"

I attempt to use this with latexmk as:

latexmk -pdf -silent \
        -pdflatex=/usr/texbin/pdflatex --file-line-error --shell-escape --synctex=1 \
        -jobname=foobar "\def\MyCustomDef{} \input{file-name.tex}"

but this results in

   Latexmk: Could not find file [\def\MyCustomDef{} \input{file-name.tex}].
   -- Use the -f option to force complete processing.

Removing the double quotes in the above results in:

Latexmk: Need to specify at most one filename if jobname specified, 
but 2 were found (after defaults and wildcarding).

My earlier attempt was:

latexmk -pdf -silent \
        -pdflatex=/usr/texbin/pdflatex --file-line-error --shell-escape --synctex=1 "\def\MyCustomDef{}" \
        -jobname=foobar file-name.tex 

but after having figured out the syntax to get pdflatex to work, I am assuming that one must use \input{} to specify the file name when defining macros on the command line.


I was able to get the solution form mph working on the command line, but then when I attempt to place that in my script I run into further issues. I suspect these are due to the need to escape things until the right moment that David Carlisle mentioned. Hmmm... This sounds a bit like TeX's expansion related issues -- no wonder I am having trouble. :-)

Here is my shell script :


set LATEX_MAKE                = latexmk 
set PDFLATEX                  = pdflatex

set LATEX_MAKE_OPTIONS        = "-f -silent "
set PDFLATEX_OPTIONS          = "-pdf -pdflatex=$PDFLATEX --file-line-error --shell-escape --synctex=1 "
set PDFLATEX_OPTIONS_WITH_DEF = "$PDFLATEX_OPTIONS %O '\def\MyCustomDef{}\input{%S}'"

set TEX_FILE = "mf2"

echo "----- Normal build:"

echo "----- Custom build (with jobname & def):"


and test file:


    My CustomDef was used.
    My CustomDef was not used.
share|improve this question
don't you want to lose the double quotes which makes the whole thing a file name called literally "\def\MyCustomDef{} \input{file-name.tex}" –  David Carlisle Jul 22 '12 at 1:10
@DavidCarlisle: That results in a different error -- see updated question. I had assumed the double quotes were required as they are required by pdflatex. –  Peter Grill Jul 22 '12 at 3:36
add comment

2 Answers

up vote 3 down vote accepted

Pass a proper Latexmk rule as the argument of the -pdflatex option. Thus:

latexmk -pdf -silent    \
        -jobname=foobar \
        -pdflatex="/usr/texbin/pdflatex --file-line-error --shell-escape --synctex=1 %O '\def\MyCustomDef{}\input{%S}'" file-name.tex

Alternatively, instead of using the -pdflatex option, you could set the $pdflatex variable in one of the Latexmk initialization files (e.g. ./latexmkrc or ./.latexmkrc).


A working Csh script similar to the one used by the OP:


set LATEX_MAKE                = latexmk
set PDFLATEX                  = pdflatex

set LATEX_MAKE_OPTIONS        = '-f -silent '
set PDFLATEX_OPTIONS          = '-pdf -pdflatex="'"$PDFLATEX --file-line-error --shell-escape --synctex=1 %O %S"'"'
set PDFLATEX_OPTIONS_WITH_DEF = '-pdf -pdflatex="'"$PDFLATEX --file-line-error --shell-escape --synctex=1 %O '\def\MyCustomDef {} \input { %S }'"'"'

set TEX_FILE                  = 'mf2'

echo '----- Normal build:'

echo '----- Custom build (with jobname & def):'


Support for nested quotes is rather limited in Csh. Moreover, it’s not easy to escape braces – you have to surround them with spaces.

share|improve this answer
This seems to work fine on the command line, but I am not able to get it to work if it is in a script. –  Peter Grill Jul 23 '12 at 2:07
@PeterGrill: I’ve updated my answer. –  mhp Jul 23 '12 at 11:56
@PeterGrill: A (subjective) tip of a Bash user: Use Csh only if it’s really required – quoting and escaping might give a hard time. –  mhp Jul 23 '12 at 12:23
add comment

Given this file


The following works for me using bash shell in cygwin as my command line. Note the command line is interpreted for { and \ in different ways in different shells and operating systems, so basically start with the simplest thing and add \\ until it stops complaining.

latexmk -f  -jobname=mf2 "\\\\def\\\\mydef\{a\}\\\\input\{mf2\}"


Latexmk: All targets (mf2.dvi) are up-to-date

but if I remove mf2.dvi and do it again I get

> \mydef=macro:
l.1 \show\mydef

which shows it worked.

The command line is first parsed by the shell and then by latexmk and then by pdftex itself, and you have to make the \ and { pass through them all. Also you need the -f option to latexmk to force it to do something and stop worrying so much.

using tcsh you need a different quoting order

 $ latexmk -f -jobname=mf2 "\\def\\mydef\{a\}\\input\{mf2\}" 

The easiest way to see what you need in any particular shell is to let latexmk do whatever ot does and then look in the TeX log file to see what commandline TeX actually saw

If the log shows

 restricted \write18 enabled.
 %&-line parsing enabled.

You need some more \ to preserve the {

share|improve this answer
I tried this solution but was not able to figure out the correct number of \ (tried quite a few) to use with a csh script. The solution of @mhp seems cleaner though. –  Peter Grill Jul 23 '12 at 2:08
Hmph if I'd known you were a csh user I wouldn't have helped, next you'll be telling me you use vi not emacs:-) did you avoid all spaces in the argument as well as quoting characters? the other answer suggests the author might have used latexmk before, or read the manual or something, surely that's an unfair advantage. If this cygwin update ever finishes I might have (t)csh and will give it a try didn't even have it installed it seems. –  David Carlisle Jul 23 '12 at 8:51
tcsh version added –  David Carlisle Jul 23 '12 at 9:20
It’s astonishing that this works! Apparently, the Latexmk argument parser is much more capable than it officially claims to be :-) –  mhp Jul 23 '12 at 17:33
add comment

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.