# Inserting code using listings, goes off page [duplicate]

When I use \begin{lstlistings}, the code is too long and goes off the page, will I have to go through every line and fit it onto the page ? The code is incredibly long and this will take a very long time.

\begin{lstlisting}[language=Python]

def bilinear_matrix(volatility,r,x0):

"""Finds the bilinear form matrix A for the Black Scholes PDE"""

x = np.array(x0)
N = len(x0) - 1
h = x[1:]-x[:-1]

a = np.empty(N+1)
a[0] =  ((volatility**2) / 2) * ((x[1]**3 - x[0]**3) / (3 * h[0]**2)) + \
(volatility**2 - r) * (-1.0 / h[0]) * (0.5 * (1 + (x[0] / h[0])) * (x[1]**2 - x[0]**2) - ((x[1]**3 - x[0]**3) / (3 * h[0]))) \
+ (r * h[0] / 3)

\end{lstlisting}


## marked as duplicate by Gonzalo Medina, moewe, Torbjørn T., Paul Gaborit, Heiko OberdiekSep 13 '15 at 9:11

• In the preamble: \lstset{ breaklines=true } – Gonzalo Medina Sep 13 '15 at 3:53