4

This question already has an answer here:

I just started to learn LaTeX, and I have to do some documentation with it.

However, the guy editing the TeX manuscript of the documentation before me didn't pay attention to word wrapping, so long lines aren't wrapped at all at the moment.

What is the best way to do auto-word-wrap (based on the margin, if possible)?

Improve/Edit: I use verbatim, and the word wrap I mean is the output-file

marked as duplicate by user13907, user2478, Kurt, Torbjørn T., Andrew Apr 5 '16 at 14:06

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.

  • 2
    Hi, welcome to TeX.SX. Normal text is wrapped by default, is this code or something like that is in e.g. a verbatim environment? It might make it easier to answer if you could create a minimal code example demonstrating the behaviour (an MWE). – Torbjørn T. Nov 14 '13 at 13:05
  • 3
    Do you mean words aren't wrapped in the .tex file, or in the output .dvi or .pdf file? – Steven B. Segletes Nov 14 '13 at 13:10
  • edited original post: I use verbatim and it's in the output file. Example code can be supplied after the weekend – ShadowFlame Nov 15 '13 at 10:16
7

One way would be to add the listings package and change the verbatim environments to lstlisting. Using find&replace in your editor should make that change quite quick. listings doesn't break lines by default either, so you need to add breaklines=true to the package options, or to \lstset. A small example is below, I also changed the basicstyle of listings to \ttfamily, so that it uses the monospaced font.

\documentclass{article}
\usepackage{listings}
\lstset{
   breaklines=true,
   basicstyle=\ttfamily}
\begin{document}

\begin{verbatim}
This is a very very very very very very long line that will run off the page in verbatim but not in lstlisting with breaklines=true.
\end{verbatim}

\begin{lstlisting}
This is a very very very very very very long line that will run off the page in verbatim but not in lstlisting with breaklines=true.
\end{lstlisting}

\end{document}
  • I'll try this monday, and I'll keep you posted – ShadowFlame Nov 15 '13 at 14:51

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