For various reasons, I prefer to have short physical lines in my latex documents, so that the various editors I switch among don't need to soft-wrap the display. But many GUI editors have terrible support for "hard" line-wrapping. The "hard wrap" option in TeXShop, for example, is not comment-aware and is therefore extremely dangerous. Texcenter 2 breaks lines in places that can insert spaces in the output; etc. (Emacs handles all this well, but I can't always use it.)

So the question: What external tools or (non-interactive) command-line scripts can reliably hard-wrap latex documents, in a way that does not change the output? For the purposes of this question I am interested in any and all platforms (though OS X-compatible or portable solutions would be most useful to me).

A good tool should also respect newlines in places that are important to human authors; e.g., a good heuristic is not to remove a newline that is immediately followed by a command sequence or comment (perhaps: even if indented).

Obviously, only TeX can handle unusual documents that change the comment character, etc.; but anything else can in principle be handled quite robustly. What tools are there that do so?

Related: This answer suggests that TextWrangler is one possibility; haven't tried it yet.

1 Answer 1


As usual, I'm quite happy the way emacs+AucTeX handles the situation. Paragraph-formatting via Meta-q is quite nice and helps a lot to improve the readability. The lines are cut below the limit as you set it. It is comment sensitive as you want (adds automatically % in front of the new line, once it got wrapped). If you're looking for a solution beyond emacs, I have nothing reasonable to offer ;)

  • 3
    Yes, unfortunately emacs proves how well it can be done... and it's a general-purpose editor (and almost-operating system). Why latex-specific editors can't manage such a simple thing is beyond me. :-(
    – alexis
    Commented Nov 7, 2013 at 12:02
  • 3
    PS. I'm happy for @Stefan that he's getting upvoted, but since I already stated in the question that emacs handles this properly, this really doesn't answer my question; I'm looking for information on alternatives, please!
    – alexis
    Commented Nov 7, 2013 at 14:52

You must log in to answer this question.

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