Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've been wondering about how to display simple codes. I used verbatim and then found the fancyvrb package which added a lot of nice little features, but then I inserted some code with a long line and it did not break.

I looked around and found that this was apparently a problem with this package, and thus looked for alternative ways to display code, and found listings (I found that it displayed the code strangely, I like the typewriter look of verbatim) and minted coupled with the Pygments Python tool (but I never got it to work with winshell). While looking at the 'listings' documentation I saw the 'fancyvrb' listed as an alternative, and in the description it said

The package provides frames, line numbers on the left or on the right, automatic line breaking (difficult)...

This question does not get an answer to the question of how to break lines using the fancyvrb package. I googled around and found this solution which provides a way to have automatic line-breaking in the verbatim environment, but this solution does not work with the fancyvrb package.

So the question is: The listings documentation hints at a way to have automated line-breaking in the fancyvrb package, does anyone know how?

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

I don't see any major problems with the listings package. See example below for a very basic structure.

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{xcolor}

\lstset{%
  language=[LaTeX]TeX,
  backgroundcolor=\color{gray!25},
  basicstyle=\ttfamily,
  breaklines=true,
  columns=fullflexible
}

\begin{document}
  \lstinputlisting{minimal.cls}
\end{document}

The package manual has the details.

share|improve this answer
    
Ah, this actually looks exactly like I wanted it to. Somehow this columns=fullflexible option fixes this problem I had with the listings package :). –  Jóhann Feb 24 '11 at 21:22
    
Hi, I'm trying to do something similar but I don't understand the answer. I am inserting some codes in my document. I am displaying them within the verbatim environment. How do I break the lines? –  Costanza Sep 3 '12 at 14:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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