[Tex/LaTex] How to get TeXShop to automatically insert line breaks

line-breakingsourcecodetexshop

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'.)

Best Answer

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.