How do you get TeXShop to automatically insert line breaks?

As I am using version control (hg) it is convenient to have hard line breaks in my tex files.

Is there a way to set up TeXShop so that it automatically inserts line breaks? (For instance, as I am typing, at some fixed maximum width.)

If this is not possible, is there a convenient command line way to insert hard line breaks into a whole file automatically? (I tried, for instance, "cat longlines.tex | tr '\r' '\n' > shortlines.tex", but this does not work because TeXShop does not even put in Mac breaks '\r'.)

-
When using version control, I find that I want to go the other way: that is, take out the line breaks inserted by the editor. I know nothing about TeXShop, but to remove line breaks (and only have them at sensible places) you could use my script referenced here: tex.stackexchange.com/questions/100/… (there's also a link to a post I wrote about using VCS with LaTeX). If you really want to insert hard line breaks in a whole file according to some fixed line width (but respecting word breaks), use the `fmt` program on unix. –  Andrew Stacey May 9 '11 at 19:42
@Chris You can also use Emacs which comes with pretty handy editing features for TeX, and a general line breaking system. –  chl May 9 '11 at 20:02
@Andrew, thanks I do also sometimes want to remove line breaks, so that's good to know about. @chl, yes, I vaguely remembered that from my emacs days, but I wanted to avoid having to use two editors for the procedure (ie texshop and emacs), so I'll keep that as a last resort. –  Chris May 10 '11 at 23:04
@Chris: Did you notice my comment about the `fmt` program? That inserts the line breaks for you (but I don't know how safe it is with regard to TeX - it might break some stuff in the preamble by inserting line breaks when there shouldn't be any). –  Andrew Stacey May 11 '11 at 8:38
@Andrew, Yes, thanks. I looked at the documentation for fmt quickly last night. I was also a touch concerned that it cleaned things up by removing line breaks as well to make paragraphs nice and neat, which of course would be really bad, but perhaps that isn't part of its mandate. –  Chris May 11 '11 at 9:14
show 1 more comment

One solution is to use an external editor for the source file. TeXShop makes this possible: in the Source panel of its Preferences, check the "configure for external editor" button and link it to a code editor. I always use AlphaX, freely available here which has an excellent TeX/LaTeX menu. With AlphaX, you can set up your source window to wrap automatically at, say, 70 characters (globally, or only in TeX mode, as you please).

Moreover, AlphaX integrates with the MacTeX-2010 code base to typeset in the background until the citations and references are properly sorted (just hit the space bar to redo the Latex run), and then invokes TeXShop to display the typeset window, in pdf by default. A quick initial configuration is needed, but there are clear setup instructions.

-
Okay, I'll check that out too, thanks. –  Chris May 11 '11 at 9:18