Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word wrap in verbatim environments [closed]

Tags:

latex

I noticed that LaTeX's verbatim environment doesn't do word wrapping. How do I get it to word wrap verbatim text?

like image 464
Pieter Avatar asked Jan 22 '11 15:01

Pieter


People also ask

What is word wrap mode?

Word wrap is the additional feature of most text editors, word processors, and web browsers, of breaking lines between words rather than within words, where possible.

How do you use verbatim in LaTeX?

The verbatim environment is used to display LaTeX commands instead of having them executed. To display a single command in-line, the \verb|| command can be used. To display a whole block, we can use \begin{verbatim} to open the environment and \end{verbatim} to close it.


2 Answers

Essentially you can’t.

But the listings package, whose actual purpose is to format source code, does support word wrapping. So maybe you can use the listings environment instead.

like image 190
Konrad Rudolph Avatar answered Sep 22 '22 09:09

Konrad Rudolph


Here is the full example for the listings package:

\documentclass{report}

\usepackage{listings}
\lstset{breaklines=true} 

\begin{document}

\begin{lstlisting}
some text here
\end{lstlisting}

\end{document}

You might also add the following definitions for line numbering and _background_color:

\lstset{numbers=left, numberstyle=\scriptsize\ttfamily, numbersep=10pt, captionpos=b} 
\lstset{backgroundcolor=\color{gray-5}}
\lstset{basicstyle=\small\ttfamily}
\lstset{framesep=4pt}

Add this for inline code:

\newcommand{\inlineCode}{\lstinline[basicstyle=\normalsize\ttfamily]}
like image 44
user1251007 Avatar answered Sep 22 '22 09:09

user1251007