Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latex listings package ignores last blank line in listing

Tags:

latex

listings

I use LaTeX listings package with \lstinputlisting to display text from an external file. The file contains a data format description with a blank line at the end. The package ignores the blank line. How can I show the blank line in a listing?

What it displays:

1 lorem ipsum...
2 more lorem ipsum
3 lorem lorem ipsum

What I want:

1 lorem ipsum
2 more lorem ipsum
3 lorem lorem ipsum
4
like image 838
Sney Avatar asked Apr 06 '10 17:04

Sney


2 Answers

See the documentation, section 4.4

`showlines=(true|false) or showlines (default = false)

If true, the package prints empty lines at the end of listings. Otherwise these lines are dropped (but they count for line numbering).

Try adding this before your listing:

\lstset{
   showlines=true
}
like image 68
John Avatar answered Sep 28 '22 03:09

John


You can escape to LaTeX from within listings by assigning an escape character like so:

\lstset{numbers=left, stepnumber=1, frame=none,basicstyle = \ttfamily}
\begin{lstlisting}[escapechar=\%]
codeline1
codeline2
%
\end{lstlisting}

Comes out as:

1 codeline1
2 codeline2
3

I know it's not \lstinputlisting but hopefully it'll help you anyway.

like image 44
MSpeed Avatar answered Sep 28 '22 01:09

MSpeed