I am writing a set of tutorial documents on some command-line based tools. This tutorials need to show a "screen session". Something along the lines of:

$ git status
# on branch "master"

I want to be able to:

  1. mark the shell prompt with a particular color (I always use the initial $ to indicate I'm on the prompt)
  2. Identify the command output with a different color
  3. Identify keywords in the shell commands

I was looking at the listings package and it seems to be on the right path, but I couldn't find a way to produce that kind of output. I saw the documentation on how to produce a different "language" for the listings package, but I couldn't get myself around that, since I couldn't find much documentation.

Is there a public implementation of such "language" specification? If not, can you give me some tips on how to define it?

  • So far, I came up with the following, which is not yet complete, since it won't inherit the settings from the shell language... \lstdefinelanguage{screensession}{ basicstyle=\color{black}\ttfamily\small, delim=**[il][\color{lightgray}\$\color{blue}]{\$} }
    – ruoso
    Commented May 18, 2011 at 19:55

3 Answers 3


This might answer some of your questions. For the prompt, you may use the literate option. Two ways are shown to color output. The first way is not very good but it gets the job done for very short and simple output. The other way is to define an output environment. The result from the two are different : when using the escape character, you are leaving the listings mode and the spacing between the letters is not the same. See the output text in red below.






$ git status
# on branch "master"
foo in bar is blah

for short output
~\color{red}This is output\color{black}~

This is output


The output is



I'll post my setup that I originally made for ActionScript:

\lstdefinelanguage{ActionScript} { %this is the name that you are going to use when you want to use the formatting
    basicstyle=\ttfamily\scriptsize, %font family & size
    sensitive=true, %if you want your keywords to be case sensitive
    %morestring: if single quotes open and close string or character literals in 
    %the same way as double quotes do in the example.
    %morecomment has to do with comments in the text, read about them in the documentation
    stringstyle=\color{flashred}, %string style (red in this case)
    commentstyle=\color{flashgreen}, %comment style
    showstringspaces=false, %the following are well documented in the listings docs
    numberstyle=\scriptsize, %you can include almost any standard settings that you can efine in 
    emph =
            here, you, define, your, keywords, separated, by, commas, even, the, last,
    emphstyle={[1]\color{flashblue}\textbf}, %set the style of these keywords
    emph = 
        %more keywords with different style

Just ask if anything is unclear and I'll try to help you as much as I can.

  • I'm sorry... have you read my question? If I wanted just the bash language, then I'll be using it... I wanted a way to define something that embed shell, but also includes the $PS1 marker as well as a different format for command output.
    – ruoso
    Commented May 18, 2011 at 19:54
  • 1
    @ruoso: I did indeed read your question. I seem to be misunderstanding a lot tonight. What I could understand, you wanted to know if anyone knew about an already formatted listings language for the language that you want to highlight and if not you wanted pointers on how to define a language in listings. If I totally misunderstood your question and wasted your time, then I am truly sorry and please accept my apologies.
    – benregn
    Commented May 18, 2011 at 20:13

I can recommend the minted package which uses pygments.

$ git status
# on branch "master"
foo in bar is blah

for short output
$ for i in `seq 2`; do 
for> echo "Test \"number\" ${i}  {}";
Test "number" 1  {}
Test "number" 2  {}

enter image description here

  • If you encounter ANSI colors in the output of a program then you can use ansi2html which I extended to convert to LaTeX including the colors.
    – ypid
    Commented May 20, 2014 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .