For displaying only few lines of source code lstlisting has a linerange key which prints only those ranges.
\documentclass[slidestop]{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[fragile]
\begin{lstlisting}[language=C,linerange={1-2,5-6}]
#include<stdio.h>
int void main(int argc, char **argv)
{
printf("hello world\n");
return 0;
}
\end{lstlisting}
\end{frame}
\end{document}
The above listing displays following lines of code without any spaces in between the lines. :
#include<stdio.h>
int void main(int argc, char **argv)
return 0;
}
What I really want is
#include<stdio.h>
int void main(int argc, char **argv)
return 0;
}
I want the lines 3-4 not to be displayed but I need blank lines for that range. So there should be 2 blank lines between first two and last two displayed lines.
Constraints:
Source code should not be changed, it is actually in a separate file which can't be changed
The actual source code I have is pretty big so using multiple lstlisting for different parts of source is cumbersome.
[Update]: My requirement in short: "lines in source code which are excluded in given range(s) should be printed as blank lines(even when they are non empty in source code)"
Inserting the following piece of code in the preamble seems to do the trick.