10

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

  • 1
    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
  • 4
    \myCommand\space should work; but you should add some context to your question – egreg Feb 17 '12 at 16:35
  • 1
    @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
14

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.

  • thanks a lot! adding \space helped – Tombart Feb 17 '12 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.