0

This question already has an answer here:

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.

enter image description here

Edit: Added code:

\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 Oberdiek Sep 13 '15 at 9:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @OP I'm assuming that you added the code but did so from another account? So the system won't accept your edit until it gets approved by a sufficient number of users. If so, please request your accounts be merged or stick to one or the other! – cfr Sep 13 '15 at 0:43
  • In the preamble: \lstset{ breaklines=true } – Gonzalo Medina Sep 13 '15 at 3:53

Browse other questions tagged or ask your own question.