22

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?

1 Answer 1

20

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .