11

Recently I discovered emacs as a text editor for my latex documents. So far, I am excited with how powerful the editor is. However, I have a problem with line wrapping.

More precisely, in the option menu I choose line wrapping in this buffer --> word wrap. After that, I choose save options, but when I reopen my tex file, line wrapping is back to the default setting.

So, my question is how can I set word wrap as my default wrapping option for all my documents?

Thanks in advance

3 Answers 3

9

As you noticed, the menu entry says "Line Wrapping in This Buffer" so this is not something that is saved by "Save Options".

To enable visual-line-mode in all your latex documents, add the following in your init file (~/.emacs or ~/.emacs.d/init.el):

(add-hook 'LaTeX-mode-hook #'visual-line-mode)

This ensures the function visual-line-mode (aka "word wrap") is called for each buffer that is put in LaTeX-mode (assuming you're using AUCTeX).

More information about the hook mechanism can be found in the emacs manual.

0
22

JeanPierre's answer will work fine if you want to use different word wrapping per type of document.

If you want all your documents word-wrapped, use the following:

(global-visual-line-mode t)

in your ~/.emacs or ~/.emacs.d/init.el file.

You can customize that value via the menus as well, by going to "Options->Customize Emacs->All Settings Matching..." and searching for "visual."

4
  • This is the right answer--the OP asked how to turn on word wrap for all files.
    – James
    Commented Apr 10, 2018 at 15:43
  • Out of curiosity, do you know why this isn't the default? What's the benefit of not having line-wrap? To me it's 99% just a nuisance
    – mowwwalker
    Commented Jul 28, 2019 at 19:00
  • @mowwwalker Visual line mode seems awkward for code buffers, especially for languages where whitespace is significant. Commented May 4, 2020 at 15:51
  • @tikhon-jelvis That's what Hollerith format is for :) Seriously though, I believe it's the default for historical reasons. Visual line mode came about in Emacs 23 I believe. Before that you had wrapping using continuation lines (the default) or by truncating the line (visually) at the right edge of the window. Commented May 9, 2020 at 3:00
0

This only worked for me in my .emacs if the mode was not capitalized and the # was omitted, like this:

(add-hook 'latex-mode-hook 'visual-line-mode)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.