9

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

6
  • 2
    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. May 9, 2011 at 19:42
  • 1
    @Chris You can also use Emacs which comes with pretty handy editing features for TeX, and a general line breaking system.
    – chl
    May 9, 2011 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, 2011 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). May 11, 2011 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, 2011 at 9:14

2 Answers 2

4

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.

0
3

I don't know how to have TeXShop insert line breaks automatically (I really wish I knew, see my related question); in order to do that manually at a later stage, you can just select all text, then choose Source > Wrap Lines > Hard Wrap from the TeXShop menu. This insert hard line breaks at the end of every displayed line, and I hope that's enough for you. (It's not an optimal solution for my purposes, unfortunately.)

1
  • Thanks, that is really helpful. To just do this process once before each commit is so much better than doing it by hand!
    – Chris
    May 10, 2011 at 22:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .