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 want to paste from the clipboard a plain text copied from a text editor (line wordpad++, vim, notepad etc), and I want TeX to respect the same line break formatting that the editor has. This works great between most text editors, however if I copy a text to a TeX editor and compile it, then it does not respect the line breaks.

Of course I can put \\ or \linebreak or whatever other typesetting function, but I don't want that. Also simple ASCII symbols like the ampersand must also be escaped (\&) I just want to have the text in my .pdf the same way I have it in my editor, without further editing it in my TeX editor.

Is there any function|style setting that can help me?

Notice I also need word wrap for the quoted text.

share|improve this question
4  
Welcome to TeX.SE. For simple ASCII text, @IanThompson's answer shows how to use verbtain. If the text is actually some other programming language that you are trying to show then you should also consider the listings package. –  Peter Grill Feb 23 '12 at 17:25
1  
This feels like it somehow points to a fundamental difference in TeX with regards to how it handles newlines and paragraphs, only I don't know exactly how to put it... :( –  jonalv Feb 24 '12 at 10:07
    
You have two contradictory requests: what did you mean when you added "I also need word wrap"? –  egreg Feb 24 '12 at 11:29
    
I think he wants the newlines that are there but also wants added line wraps whenever they are needed, in addition. –  jonalv Feb 24 '12 at 12:55
    
Exactly. I keep a lot of notes on text files and sometimes I just need to include/quote from them in a tex document. And I prefer not to do any re-editing of my notes. Without word-wrapping the larger lines go out of paper. In text editors we have word wrapping and don't care about line breaks. –  grokkaine Feb 24 '12 at 13:45
add comment

5 Answers

The listings package also allows for setting content verbatim. Here's an example, using language=TeX (which should be fine if you have plain text):

enter image description here

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\begin{document}
\begin{lstlisting}[language=TeX]
Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Fusce pulvinar risus 
eu neque porttitor a ultrices magna 
malesuada. Mauris ullamcorper, elit at 
euismod fermentum, mi velit imperdiet 
est, in auctor orci lorem eu velit. 
Integer venenatis accumsan mollis. Cras 
in eros metus, id euismod ante. Class 
aptent taciti sociosqu ad litora 
torquent per conubia nostra, per inceptos 
himenaeos. Vivamus nisl tortor, eleifend 
at vestibulum sit amet, scelerisque 
a lacus. Aenean tempus nibh eu ante 
fringilla laoreet. Pellentesque et diam 
sem, sed venenatis turpis. Aenean ac 
euismod dui. Vivamus faucibus elit non 
dolor tincidunt non pulvinar felis 
sagittis. Mauris mi massa, malesuada id 
vestibulum et, tincidunt ac nibh. 
Donec in orci eros, eu accumsan odio. 
Curabitur ipsum nunc, dictum vitae 
faucibus non, aliquet quis leo. Nullam 
nisi diam, rhoncus sagittis semper non, 
pharetra et eros. Etiam a metus nulla, non 
egestas leo.
\end{lstlisting}
\end{document}​​​​​​
share|improve this answer
7  
This cannot be unseen… –  Andrey Vihrov Feb 23 '12 at 17:59
    
@AndreyVihrov: :) user requests, however foreign and bizarre, can be accommodated to some extent. This is one of them. –  Werner Feb 23 '12 at 18:06
    
Thanks, how do I ask it to make word wraps? I tried \lstset{breaklines = true} \begin{lstlisting}[language=latex] ..text.. \end{lstlisting} but it doesn't work. –  grokkaine Feb 24 '12 at 10:08
add comment

If you want it very short, try the plain-TeX \obeylines. It should be used in a group, however. Also, TeX starts a new paragraph after each line in obeylines-mode, which might result in indentation. So you probably want to change indentation (third example below).

Try it like this (with default for comparison):

\documentclass{article}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut

{\obeylines %
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
}

{\parindent=0pt \obeylines %
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
}

\end{document}

Note that it is often undesirable to mix plain-TeX commands as \obeylines with LaTeX. However, occasionally, such solution might fit. Also, escaping is not done for you with this solution.

For more sophisticated inclusion of verbatim text, use the verbatim environment. Note that it changes the default font to typewriter-style monospaced. The fancyvrb package contains even more sophisticated facilities for verbatim text; it also changes the font in its environment by default.

The listing package is intended to typeset program code listing and syntax-highlighting. It can also be used to simply include verbatim text in your document.

share|improve this answer
    
Thanks, this works except one problem: some ASCII characters must still be skipped. '\&' for example. On verbatim I don't have to skip them, but I have no way to specify lines. I installed listings but language = latex is not among the supported languages, so I don't know what to use. –  grokkaine Feb 27 '12 at 9:06
1  
Try to use listings with no language set, using: \lstset{language={}}. This should help. Also, if you really want LaTeX as language for listings, eg, for syntax highlighting, use \lstset{language=[LaTeX]TeX} as explained in the listings documentation (Table 1). –  Tobias Feb 29 '12 at 9:30
add comment

Use the verbatim environment.

\documentclass{article}
\begin{document}
\begin{verbatim}
Do not format this text.
\end{verbatim}
\end{document}

If you need more sophisticated features, take a look at the fancyvrb package.

share|improve this answer
    
Thanks, this is fine, except one single point: it doesn't do line wrap. I forgot to mention that. :( I am re-editing my question to include it. –  grokkaine Feb 24 '12 at 9:04
add comment

The simple answer is the alltt package. The alltt is a verbatim like environment that preserves all spaces and lines, but normal TeX commands such as font changes are active.

\documentclass{article}
\usepackage{alltt}
\usepackage{color}
\begin{document}
\begin{alltt}\rmfamily
Lorem ipsum dolor sit amet, \textbf{consectetur}
adipiscing elit. Fusce pulvinar risus
eu neque porttitor a ultrices magna
   malesuada. Mauris ullamcorper, elit at
   euismod fermentum, mi velit imperdiet
est, in auctor orci lorem eu velit.

Integer venenatis accumsan \textcolor{red}{mollis}. Cras
in eros metus, id euismod ante.
\end{alltt}
\end{document}

enter image description here

share|improve this answer
add comment

I think Tobias provided the solution (vote him up!) but I don't think his example showed it so good. Hence I am providing a second example:

\documentclass{article}
\begin{document}

{\parindent=0pt \obeylines %
First comes a really really really really really really really long line that needs to be line wrapped automagicly by tex
after that comes
multiple short 
ones 
Where the newlines should be obeyed.
}

\end{document}

enter image description here

share|improve this answer
    
It does not skip all ascii characters though. For example I must do '\&' for all '&'. See my comment to Tobias. –  grokkaine Feb 27 '12 at 9:08
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.