1

I want to give listings and somehow mark a particular set of lines. My preference would be to make them italic. (The purpose of wanting to do this is so I can say "these lines are required but you do not yet need to understand them"). I am open to other ways of marking the lines (bold, putting a star next to them etc.

How should I go about doing this?

Joe
  • 199
  • 8

1 Answers1

3

You could use escaping to latex to emphasize the intended lines.

Check out Chapter 4.14 Escaping to LATEX of the Listings package manual.

Or, you could refer to certain line numbers.

Check out Chapter 7 How to's

This is some code of mine: i searched for all running processes on my machine and fed the output to grep. grep then searched for the pattern 'Foam'. I marked all matches red in the listing.

\begin{lstlisting}[escapechar=§,caption={In der Liste der laufenden Prozesse suchen},label=lst:listProcessesFindFoam] 
user@host:~$ ps -ef | grep Foam
user  11005  5117  0 17:11 pts/2    00:00:05 mpirun -np 4 twoPhaseEuler§\color{red}{Foam}§ -parallel
user  11006 11005 99 17:11 pts/2    00:40:27 twoPhaseEuler§\color{red}{Foam}§ -parallel
user  11007 11005 99 17:11 pts/2    00:40:28 twoPhaseEuler§\color{red}{Foam}§ -parallel
user  11008 11005 99 17:11 pts/2    00:40:27 twoPhaseEuler§\color{red}{Foam}§ -parallel
user  11009 11005 99 17:11 pts/2    00:40:26 twoPhaseEuler§\color{red}{Foam}§ -parallel
user  11673 11116  0 17:52 pts/12   00:00:00 grep --color=auto §\color{red}{Foam}§
user  32041     1  0 Aug01 ?        00:00:31 evince /tmp/lyx_tmpdir.J18462/lyx_tmpbuf0/open§\color{red}{Foam}§UserManual_CDLv2.pdf
user@host:~$  
\end{lstlisting}
Dohn Joe
  • 1,912
  • Can I change the background color of code line this way? – Masud Rahman Mar 05 '14 at 08:10
  • Try \colorbox instead of \color. Between the escape-characters (in this case the §) you can state any latex code. So coloring the lines in the listing works the same as coloring any text in latex. – Dohn Joe Mar 05 '14 at 08:24