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

Why can't I compile the following even though I have enabled -shell-escape?

\def\paramB{Hello World}

\immediate\write18{pdflatex "\def\paramA{standalone}\input{inputfile}"}

Log File

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/W32TeX)
 \write18 enabled.

<< the unnecessary texts are intentionally removed by me for the sake of simplicity >>

No file executor.aux.
! Undefined control sequence.
<write> pdflatex "\def \paramA 
                               {standalone}\input {inputfile}"
l.13 ...\def\paramA{standalone}\input{inputfile}"}

share|improve this question
As the error message says: \paramA is not defined. \write18 tries to expand it before sending it to the shell (which it shouldn’t in this example). It needs therefore to be protected by \noexpand or \string or \unexpanded: \immediate\write18{pdflatex "\def\noexpand\paramA{standalone}\noexpand\input{inputfile}"} or \immediate\write18{\unexpanded{pdflatex "\def\paramA{standalone}\input{inputfile}"}} – Qrrbrbirlbel Feb 13 '13 at 1:50
Or \immediate\write18{pdflatex "\def\string\paramA{standalone}\string\input{inputfile}"} or \immediate\write18{\detokenize{pdflatex "\def\paramA{standalone}\input{inputfile}"}}. The error is caused by the expansion of \immediate\write. – Heiko Oberdiek Feb 13 '13 at 1:56
up vote 8 down vote accepted

As the error message describes, the macro \paramA is undefined.

\write18 tries to expand its content before forwarding it to the shell, so you need to “protect” (not \protect!) the macros \paramA and \input with

  • \noexpand (single use),
  • \string (single use),
  • \unexpanded (multiple uses), or
  • \detokenize (multiple uses).

The easiest solution in this case would be to use \unexpanded or \detokenize as you actually have no macros that needs to get expanded:

\immediate\write18{\unexpanded{pdflatex "\def\paramA{standalone}\input{inputfile}"}}

Single macros needs to be protected every time:

\immediate\write18{pdflatex "\def\string\paramA{standalone}\string\input{inputfile}"}
share|improve this answer

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.