I would like to define a command that wraps a lstlisting environment in some other environments (esp. a minipage). I understand that working with verbatim arguments is a difficult task. I tried the xparse package which provides the argument type v, but code like


does not work. Can anybody give me advice on that?

Is it any easier if I use an environment instead of a command?

  • 2
    The lstlisting environment cannot go in the argument of a command. It can go in a minipage without any problem. – egreg Mar 24 '13 at 17:33
  • There isn't any way to circumvent this? Maybe I have to find out how lstlisting handles the "verbatim problem" and try to mimick it... – J Fabian Meier Mar 24 '13 at 17:41
  • 2
    No, there isn't. Moreover, when you put some tokens in the argument to a command you lose the line endings. – egreg Mar 24 '13 at 17:46

You can use lstlisting environment with minipage using \lstnewenvironment:


And use it like the any other environment:


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.