I would like to create a new environment using minted, inside which there is always a prefix string.

For example, following this answer I have tried



user@host$ }




But LaTeX will not compile it:

[Loading MPS to PDF converter (version 2006.09.02).]
! FancyVerb Error:
  Extraneous input ` user@host $ ' between \begin{cmdline}[<key=value>] and line e
\FV@Error ... {FancyVerb Error:
\space \space #1

l.14 \begin{cmdline}

If I remove the prefix user@host $, it works fine.

What did I do wrong? Is there a way to do what I'm trying to do?

edit: even if I decide to work on a single-line command, the best I could get was this:



\newcommand{\cmdline}[1]{\mint{text}^user@host$ #1^}


\cmdline{echo "hello world!" # saying hello...}


but then, the hash sign (#) gets duplicated in the output:

enter image description here

(Something to do with the hash from newcommand's argument, maybe? minted saw and reprodueced it?

edit, again:

I am now verifying if I can use inline Lua code to get this working.

  • 1
    As this prefix would only be added to the first line: Do you want to only use one line of shell code (even if this might be set apart) in these environments? – TeXnician Apr 5 at 9:11
  • @TeXnician Sometimes one line, sometimes more than one. The prefix should be in the same line as the beginning of the code... (It's not only for command line, it's also for REPL interaction -- when Python programmers test code in the REPL, it usually is multiline... The same for Lisps and Prolog) – Jay Apr 5 at 9:34

Your Answer

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

Browse other questions tagged or ask your own question.