I am including some code into my tex file via \lstinputlisting[]{}. Unfortunately sometimes the breaklines=true-command does not work. Example: enter image description here

In line 65 the linebreak does not work, but in line 70 it works. Why? My lstset is:

  {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
  {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
  {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1
  {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1
  {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
  {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
  {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
  {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
  {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
  {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
  {€}{{\EUR}}1 {£}{{\pounds}}1,
  breaklines=true, postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}},

Full listing:


\setlength{\parskip}{1.5ex plus0.5ex minus0.2ex}


\newcommand{\unit}[1]{\ensuremath{\, \mathrm{#1}}}

def jonswap(self, w, wp = None, alpha = 0.0081, gamma = 3.3, beta = 1.25):

        return S 
  • 2
    Don't sent code snippets. Make complete, compilable (but small!) examples. – Ulrike Fischer Apr 8 '15 at 13:11
  • Should I include my (included) code, too? – arc_lupus Apr 8 '15 at 13:14
  • You should make a small but complete example that demonstrates your problem. Use your brain to decide how this is done best (hint: you probably can delete all the literate declarations, and you don't need \lstinputlistings, you can copy a small part of your code directly in a lstlisting environment). – Ulrike Fischer Apr 8 '15 at 13:23
  • Only the part to make the problem understandable and reproducable for us. -> dickimaw-books.com/latex/minexample/html – Johannes_B Apr 8 '15 at 13:23
  • 1
    @arc_lupus breaklines cannot work if you have no white space in the whole line. – yo' Apr 8 '15 at 13:49

The problem is that breaklines doesn't take decisions. It has two simple rules for breaking:

  1. Don't break the initial indentation (i.e., leave at least something other than whitespace on the line)
  2. Break only at whitespace.

Since your line doesn't contain any whitespace, there's no feasible breakpoint whence no break.

| improve this answer | |
  • 3
    Listings will break at other places too if you add (beside \breaklines=true the option breakatwhitespace=false. – Ulrike Fischer Apr 8 '15 at 14:02
  • @UlrikeFischer Ah I didn't know that. Do you plan to make it an answer or should I improve mine? – yo' Apr 8 '15 at 14:06
  • You can add it to your answer. – Ulrike Fischer Apr 8 '15 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.