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

I create an own command like this


Now I want to use this command in normal text (no problem) and inside of a listing

Nun kann die Funktionsweise überprüft werden:

su -l griduser
globus-url-copy gsiftp://\hostname:2811/home/share/test file:///home/share/test2

In the text, the command is executed without any problems. Inside the listing it is printed as \hostname. How can I execute this inside the listing or pass this as parameter or something like that.

share|improve this question
You need to escape to normal TeX code to process the macro. See the listings manual for how to do this. – Martin Scharrer Jun 22 '11 at 11:43
up vote 3 down vote accepted

You can "escape" things as follows:

  Text (*\foo*)

Enclose macros you want tex to actually read inside some "escaping" mechanism defined by escapeinside

share|improve this answer
awkwardly, this won't work if the command \foo contains macros that you want set verbatim... I guess you'd need to use expansion magic to get around that – Seamus Jun 22 '11 at 11:52
Thank you, is working great! – strauberry Jun 22 '11 at 14:34

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.