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'd like to call a command from LaTeX, which looks like this:

bash -c "\myCommand -Tpdf #2.dot > #2.pdf"

\myCommand is replaced by string variable, however the space after is also removed so I get something-Tpdf which is of course not understood by bash. How can I force LaTeX to leave a space in this string?

\myCommand{} doesn't help

share|improve this question
We could do with a full MWE to see how you are setting this up: for example, usually \myCommand{} would work fine. –  Joseph Wright Feb 17 '12 at 16:35
\myCommand\space should work; but you should add some context to your question –  egreg Feb 17 '12 at 16:35
@Werner This might be in a \write18, if I understand correctly, so neither {} nor \xspace is the solution. –  egreg Feb 17 '12 at 16:48
add comment

1 Answer

up vote 14 down vote accepted

If you want to add a space in an expandable way, which is required for \write18 system calls you can do so using the \space macro which is defined like \newcommand*{\space}{ } (actually \def\space{ }) and therefore expands to a single space.

So you can write your command string like:

bash -c "\myCommand\space -Tpdf #2.dot > #2.pdf"

The explicit space is required because spaces after a macro are removed, because they are taken as separator between the macro name and the text afterwards. The usual way to add {} after it would preserve the space behind it, but this is only good for typesetting the text where the braces are ignored. If you want the text in an expandable context, like to write it into an external (auxiliary) file, to the shell (like in this case) or build a macro name from it (advanced topic), then the {} are unwanted and usually cause trouble.

share|improve this answer
thanks a lot! adding \space helped –  Tombart Feb 17 '12 at 17:30
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.