Replace the \documentclass[...]{standalone} to your own \documentclass{<xxx>} where <xxx> can be replaced by any available classes such as article, book, report, etc. You will get listings that span muliple pages.
\documentclass[a4paper,11pt,twoside,openany,dvipsnames]{book}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
\lstdefinestyle{Common}
{
basicstyle=\scriptsize\ttfamily\null,
numbers=left,
numbersep=1em,
frame=single,
framesep=\fboxsep,
framerule=\fboxrule,
xleftmargin=\dimexpr\fboxsep+\fboxrule,
xrightmargin=\dimexpr\fboxsep+\fboxrule,
breaklines=true,
breakindent=0pt,
tabsize=5,
columns=flexible,
showstringspaces=false,
captionpos=b,% or t for top (default)
abovecaptionskip=0.5\smallskipamount, % there is also belowcaptionskip
}
\lstdefinestyle{CSharp}
{
style=Common,
language={[Sharp]C},
alsolanguage={[LaTeX]TeX},
morekeywords=
{
% add your new fortran keywords here!
},
}
\lstdefinestyle{CSFall}
{
style=CSharp,
backgroundcolor=\color{Blue},
basicstyle=\color{Yellow}\scriptsize\ttfamily,
keywordstyle=\color{White}\sffamily,
identifierstyle=\color{Cyan}\bfseries,
commentstyle=\color{ForestGreen},
stringstyle=\color{Maroon},
numberstyle=\color{Black}\tiny\noaccsupp,
rulecolor=\color{Black},
}
\lstnewenvironment{CSFall}
{\lstset{style=CSFall}}
{}
\usepackage{filecontents}
\begin{filecontents*}{csharp.cs}
public class DoubleFormatter : IFormatProvider, ICustomFormatter
{
// always use dot separator for doubles
private CultureInfo enUsCulture = CultureInfo.GetCultureInfo("en-US");
public string Format(string format, object arg, IFormatProvider formatProvider)
{
if (arg is double)
{
if (string.IsNullOrEmpty(format))
{
// by default, format doubles to 3 decimal places
return string.Format(enUsCulture, "{0:0.000}", arg);
}
else
{
// if user supplied own format use it
return ((double)arg).ToString(format, enUsCulture);
}
}
// format everything else normally
if (arg is IFormattable)
return ((IFormattable)arg).ToString(format, formatProvider);
else
return arg.ToString();
}
public object GetFormat(Type formatType)
{
return (formatType == typeof(ICustomFormatter)) ? this : null;
}
}
\end{filecontents*}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\lstinputlisting[style=CSFall,caption={An example of C\# code.}]{csharp.cs}
\lipsum[2]
\end{document}
