1

I need to write a document where there are written inputs and outputs of unix command line interface software (through bash). For example I need to show something like:

$ git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short --all
* 1c0435a 2013-08-17 | Aggiunta del telefono (HEAD, master) 
* 928406c 2013-08-17 | Il mio primo commit modificato (v1, origin/master) 
* 8a3b838 2013-08-17 | Il mio primo commit (v1-beta)

where the first line is the bash prompt, and the 2nd-4th lines are the software's output (git in this case).

As you know, bash-prompt's too long lines need to have a back slash \ as carriage return, otherwise bash doesn't count it as one line, but as two different lines. So, if you need to break the 1st line you have to write

 $ git log --pretty=format:"%h %ad | %s%d [%an]" \
         --graph --date=short --all

Obviously, while you'll want a back slash on prompt's broken lines, you do not want it on output lines. So, even though you DO WANT to break lines 2nd-4th, you don't want the slash:

WRONG

   * 1c0435a 2013-08-17 | Aggiunta del \
telefono (HEAD, master) 
    * 928406c 2013-08-17 | Il mio primo commit \
 modificato (v1, origin/master) 
    * 8a3b838 2013-08-17 | Il mio primo commit \
(v1-beta)

CORRECT

    * 1c0435a 2013-08-17 | Aggiunta del 
telefono (HEAD, master) 
    * 928406c 2013-08-17 | Il mio primo commit 
 modificato (v1, origin/master) 
    * 8a3b838 2013-08-17 | Il mio primo commit 
(v1-beta)

The perfect solution would be letting me decide where to break the line with a back slash, and where to break it without the back slash. Do you have any ideas on how to accomplish this? I mean something like

moredelim=[is][pbreak=\small\symbol{'134}]{§§}{§§}

(I know this example doesn't work, it's just to let you know what I mean: it's intended to break with \ only lines that I escape within the §§) Here is my lstset:

\lstset{ %
language=xml,                % choose the language of the code
basicstyle=\small\ttfamily,% \footnotesize,       % the size of the fonts that are used for the code
numbers=left,                   % where to put the line-numbers
numberstyle=\footnotesize,      % the size of the fonts that are used for the line-numbers
stepnumber=1,                   % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt,                  % how far the line-numbers are from the code
backgroundcolor=\color{white},  % choose the background color. You must add \usepackage{color}
showspaces=false,               % show spaces adding particular underscores
showstringspaces=false,         % underline spaces within strings
showtabs=false,                 % show tabs within strings adding particular underscores
frame=single,           % adds a frame around the code
tabsize=2,          % sets default tabsize to 2 spaces
captionpos=b,           % sets the caption-position to bottom
breaklines=true,        % sets automatic line breaking
prebreak=\small\symbol{'134},
breakatwhitespace=false,    % sets if automatic breaks should only happen at whitespace
moredelim=[is][\bfseries]{@@}{@@}
}

closed as unclear what you're asking by jub0bs, Peter Jansson, Claudio Fiandrino, Svend Tveskæg, Jesse Jan 13 '14 at 15:59

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. – jub0bs Aug 19 '13 at 18:33
  • I'm not sure to understand correctly. Is the problem solved if you add literate={\\}{{}}0 in the \lstset options? – karlkoeller Aug 19 '13 at 19:23
  • Actually it is not. The problem is that I need to have the possibility to chose wether break the line with a backslash or break the line without it ... – Matteo Fabbroni Aug 19 '13 at 19:43