36

Do you use "hard wrapping" (either yourself or automatically by your editor) by inserting newlines into your source document at a certain line length, or do you write your paragraphs in one continual line and let your editor "soft-wrap" for you?

Also, what editor do you use for this?

Note: I'm interested in how you wrap lines in your TeX source code (.tex file, general prose), not how TeX wraps lines for the final document.

jparker
  • 1,569
  • 2
  • 16
  • 16

10 Answers10

46

I recently switched to hard-wrapping per sentence (i.e., newline after sentence end only; one-to-one mapping between lines and sentences) for two reasons:

  • softwrap for a whole paragraph makes typos impossible to spot in version control diffs.
  • hardwrapped paragraphs look nice until you start to edit them, and if you re-flow a hard wrapped paragraph you end up with a whole bunch of lines changed in the diff for a possibly one word change.

Only wrapping per sentence fixes these two problems:

  • Small changes are comparatively easy to spot in a diff.
  • No re-flowing of text, only changes to, insertions of, or removal of single lines.

Looks a bit weird when you first look at it, but is the only compromise I've seen that addresses the two problems of soft and hard wrapping.

Of course, if you're working collaboratively, the answer is to use whatever the other people are using.

Will Robertson
  • 62,540
  • 32
  • 99
  • 117
  • 1
    I also changed to this, and it has made things significantly easier. I think that I'll be doing this everywhere I can now: markdown, html, reST, etc. – Paul Biggar Oct 10 '09 at 13:11
  • 2
    One more thing: this makes it much much easier to find text as well. Suppose I wanted to find errors where I had written "straight forward" instead of "straightforward". "straight forward" might have had a line break before, making it hard to grep for. Now it never will. – Paul Biggar Oct 10 '09 at 13:12
  • 3
    This also makes immediately obvious how long lines are. If you've ever accidentally written a 5 line, 20 comma sentence, you'll know how important this is to stamp out. I don't know a good sentence length exactly, but I can easily spot suspicious ones. – Paul Biggar Oct 10 '09 at 13:14
  • +1: Have arrived at the same solution -- and along the same path :) Hardwrap -> softwrap per paragraph -> softwrap per sentence. – Janus Dec 03 '10 at 02:10
  • 1
    I'm now using this too, because of the good arguments put here (even though I'm currently not using a VCS). I'm finding that it makes writing sentences different though - forces me to be conscious of sentence length, and seem to make me write shorter sentences. I'm not sure if this is a good thing or not yet. – naught101 Apr 03 '12 at 02:16
  • 1
    Also, now that I think of it, `git diff --word-diff` kind of negates the problems with spotting minor changes to sentences. – naught101 Apr 03 '12 at 02:17
  • OP: Why not mark this is correct answer so it shows at the top of the page? – aaronsnoswell Aug 17 '13 at 12:33
  • While I have been following this approach for years (actually, I was extremely happy when I discovered others have had the same idea as I did, thus confirming how much sense it makes to do it like this), I sometimes struggle when I have to express direct speech (such as *"Hello, World!" he said.*). Do you happen to have any good solution for that? – O. R. Mapper Nov 25 '14 at 11:25
7

I use Emacs (with AUCTeX). After editing or writing a paragraph, I hit M-q to hard-wrap it. It also handles indenting items, and it also formats commented paragraphs. I don't like soft wraps, because they are visually indistinguishable from real newline characters, but behave differently.

Svante
  • 50,694
  • 11
  • 78
  • 122
5

I generally let my LaTeX editor softwrap the lines. I think part of it is due to the fact that I had some bad experiences with significant whitespace when I was first learning LaTeX, and part of it is because I don't like heavily-jagged right-margins when I'm editing the text file.

Greg D
  • 43,259
  • 14
  • 84
  • 117
5

Depending on what os you use, i recommend winedt (windows) and kile (linux). Both of these soft wrap, and there is no need for hard wraps. (That is, i leave my paragraphs as long lines in the source) Latex sorts out line breaks in the output and when i read the source, i use my editor.

The only possible reason to use hard line breaks is to make it easier to find errors in the code (which the compiler indicates by line number) but they are generally not hard to find, if it's mainly text, errors are rare anyway.

second
  • 28,029
  • 7
  • 75
  • 76
3

Typically I have my editor insert newlines. That is, I try not to hit the "enter" key for a new line, but when the editor soft-wraps, it actually inserts a newline character.

I use vim to accomplish this, and I don't know if other editors have this feature or how they work. In specific, i use the wrapmargin feature.

I typically try to keep my lines of code (TeX or otherwise) at n-characters long for clarity and consistency. I tend to go with 80 characters, but that is up to you.

More vim-related line-breaking docs:

http://www.vim.org/htmldoc/usr_25.html

http://www.vim.org/htmldoc/options.html#%27textwidth%27

poundifdef
  • 18,726
  • 23
  • 95
  • 134
2

I use Kile under Linux with hard wrapping (called static word wrap in Kile) because apparently in my work environment everybody do like that. Soft wrapping makes much more sense to me, so if I could choose I would use that rather than hard wrapping.

Marco Lackovic
  • 6,077
  • 7
  • 55
  • 56
2

I tend to do hard-wrapping with TeX, but that's rooted more in my obsession with text formatting than any real gain of efficiency. One major thing that I don't like about soft-wrapping is that it tends (in my opinion, obviously) to make things harder to read by wrapping in semantically-random places.

Paul Morie
  • 15,528
  • 9
  • 52
  • 57
2

Although I would prefer to use soft wrapping I end up using hard wrapping for one practical reason: all of my collaborators do the same. So, when I work on an article with someone it would be a big pain for me to soft wrap while the other person hard wraps. The second reason is that Emacs was until recently able to handle properly on hard wrapping. Emacs 23 which I currently use changes this but it will be a long time before everybody upgrades to 23 so I can sneak soft wrapped texts to them.

The way I actually use hard wrapping is to have auto-fill-mode turned on. Furthermore M-q is bound to LaTeX-fill-paragraph (in the AucTeX mode - but I don't remember if this is a standard binding or one of my bindings - I'm pretty sure it's the latter). Combining these two I manage to keep my TeX source more or less decently formatted.

By the way, I have heard the suggestion to always start a new sentence at the beginning of a line. In other words a period at the end of a sentence should be followed by a hard return. The benefit is that it works well with version control systems since changes to a sentence can remain localized. I think that this is in principle a nice idea but I have not managed to use it because of my obsessive-compulsive usage of M-q.

cefstat
  • 2,336
  • 1
  • 18
  • 25
1

I use Auctex with automatic line breaking switched off, and insert line breaks by hand. I avoid auto-formatting, since I want as few changes to where line breaks occur between edits to the document, which makes diffs less cluttered.

Using a smarter diff, one that doesn't care about tex-irrelevant whitespace, would be better, but that's the tool I use.

I like Will's suggestion of hard wrapping per sentence. I thought about it before, but I am fixed in my habits.

Charles Stewart
  • 11,661
  • 4
  • 46
  • 85
1

I work in joe mostly. I from time to time press enter automatically, and if it doesn't look good I press auto-format (ctrl-k j).

Joe has autowrap modes, but I don't even bother.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89