I'm using Latex to write a program listing all my code and I am following this:
http://texblog.wordpress.com/2008/04/02/include-source-code-in-latex-with-listings/
It works, but my code runs of the side of the page. How can I fix this? Additional question: How can I get it to highlight syntax? I do have lang set to Java.
Try something like this:
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
language=c,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fullflexible,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}
\begin{document}
\begin{lstlisting}
#include <stdio.h>
int main()
{
// A line comment
printf("A really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, REALLY long line. && & \n");
return 0;
}
\end{lstlisting}
\end{document}
which produces:
alt text http://img260.imageshack.us/img260/1608/codes.png
Did you consider
\lstset{...}
breaklines=true -> sets automatic line breaking
breakatwhitespace=false -> automatic breaks happen at whitespace
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With