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

What is the LaTeX 3 equivalent to \write18 if there is one? I want to call lilypond from within my TeX document.

share|improve this question
Do you mean \tex_write:D? But :D means "Do not use it". – Marco Daniel Sep 14 '13 at 15:33
\int_const:Nn \c_eighteen and then \iow_now:Nn \c_eighteen{...} is equivalent to \immediate\write18{\unexpanded{...}}; but probably one should define some new function based on this. – egreg Sep 14 '13 at 16:57
up vote 4 down vote accepted

There is no function in LaTeX3, at the moment, dealing with \write18; it can be obtained by

\int_const:Nn \c_tobi_eighteen_int { 18 }
\int_const:Nn \c_tobi_shell_escape_int { \int_eval:n { \use:c { pdf@shellescape } } }
\cs_new_protected:Npn \tobi_system_exec_now:n #1
  \int_compare:nT { \c_tobi_shell_escape_int > 0 }
   { \iow_now:Nn \c_tobi_eighteen_int { #1 } }
\cs_new_protected:Npn \tobi_system_exec_shipout:n #1
  \int_compare:nT { \c_tobi_shell_escape_int > 0 }
   {  \iow_shipout:Nn \c_tobi_eighteen_int { #1 } }
\cs_generate_variant:Nn \tobi_system_exec_now:n { x }
\cs_generate_variant:Nn \tobi_system_exec_shipout:n { x }

%% Examples
\tobi_system_exec_now:n { ls }
\tl_set:Nn \l_tmpa_tl { ls }
\tobi_system_exec_now:x { \l_tmpa_tl }

You probably would want to add messages telling that things went wrong when shell escape is disabled; or just remove the \int_compare:nT thing.

I used the tobi prefix because using \system is probably a bad idea (I don't want to get slapped by Joseph on chat, you know).

share|improve this answer
Indeed, a good question here is what does and doesn't make sense interface-wise for this. As the team have not needed \write18 we've not worried out it. Notable of course is that catcodes might be an issue. – Joseph Wright Sep 14 '13 at 19:55
@JosephWright Catcodes can surely be an issue; but I guess the function will be called with its argument coming from "user space". Otherwise, spaces must be ~, as usual. Setting up a good diagnostic system might be tricky, because of restricted shell. – egreg Sep 14 '13 at 20:01
@JosephWright: don't you guys dare including a \write18 equivalent function in LaTeX3, I already printed interface3.pdf today! :) – Paulo Cereda Sep 14 '13 at 20:05
Seems to work fine. Thank you! – Tobi Sep 15 '13 at 8:18

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.