# How do I manage newlines in Latex?

So, maybe I missed something completely when I started using Latex, but I have a difficult managing newlines in the Latex source. I have to put hard returns at the end of lines because even powerful editors like Emacs or Vim don't seem to manage that (at least out of the box).

For example, if I have the following paragraph in my Latex file:

So, maybe I missed something completely when I started using Latex,[\n]
but I have a difficult managing newlines in the Latex source. I have[\n]
to put hard returns at the end of lines because even powerful editors[\n]
like Emacs or Vim don't seem to manage that (at least out of the box).[\n]

But then I want to add a the parenthetical "but, not newlines in the Latex output" to the second line so then I get something like this:

So, maybe I missed something completely when I started using Latex, [\n]
but I have a difficult managing newlines in the Latex source (but, not newlines in the Latex output). I have [\n]
to put hard returns at the end of lines because even powerful editors [\n]
like Emacs or Vim don't seem to manage that (at least out of the box).[\n]

Assuming that before I insert the phrase, the lines we at the 80 character boundary, I get rather unmanageable soft line wraps. When this happens, the act of pushing the 'down' arrow brings me to the same column in the next line, completely ignoring the soft line breaks.

What am I missing?

-

I'm not certain I understand what you are asking, but it is possible that `longlines-mode` in emacs will gve you the behavior that you want.

-
Ah. Yeah that's it. LongLines of AutoFillMode. Thanks. I'm somewhat new to emacs, and I don't have any emacs wizards I can just walk up and ask anymore :\ –  Jeremy Powell Nov 18 '09 at 2:46

If I read your question right, this has nothing to do with LaTeX other than you happen to be editing LaTeX source?

If you want to tell vim to wrap lines at, say, 78 characters:

``````:set tw=78
``````

If you want to do this for all .tex files, add the following command to your .vimrc:

``````autocmd BufRead *.tex set tw=78
``````
-
yeah. that's pretty much what I need; I wasn't really thinking that there's a more global solution. I guess its been a longer day than I thought.. –  Jeremy Powell Nov 18 '09 at 2:47

For me, LaTeX source is, well, source. I got accustomed to cut lines at "logical points" (after punctuation, keep a phrase together on a line, ...). It helped me to catch errors like "an dog" or "a animal" or even "the the phrase". Splitting the text this way, and using indentation to reflect structure, makes longer text source much more readable. It also makes much editing of the text be shuffling lines around, and editors have good commands for that.

Later I came to use version control heavily, and there having changes be mostly lines added/deleted wholesale, not a full paragraph replaced just because a word was added to a line, becomes essential when the text (and its history) grow.

For the same reason you don't fill your C code, don't fill LaTeX.

-
You should clarify paragraph 2, only people using a VCS can make sthg out of it at present. –  Joce Apr 23 at 20:49
@Joce, sorry I don't see how to enhance it. Feel free to edit. OTOH, somebody who doesn't use VCS won't understand anyway... –  vonbrand Apr 23 at 20:51
Well, let’s make it dead simple then: Changes are tracked on the line level. Without line breaks, any modification in a long paragraph would result in a needlessly large and confusing changeset. If it’s just one sentence per line, this problem can be avoided. –  Daniel B Apr 23 at 21:09

In emacs, with Autofill mode `M-x auto-fill-mode`, you can `M-q` and emacs formats the text as you want it.

-