4

I'm using AUCTeX to edit LaTeX files. The behavior of the fill command M-q (also C-c C-q C-p, LaTeX-fill-paragraph) is very erratic. For example, if I have the following text:

test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$

filling it yields:

test $1 + 1 = 2$
test $1 + 1 = 2$
test $1 + 1 = 2$
test $1 + 1 = 2$
test $1 + 1 = 2$
test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$

which is clearly not ideal. However, I have auto-fill-mode enabled, and if I take the text from the beginning and manually add a space at the end of the line, the auto-fill does this:

test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$
test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$ test $1 + 1 = 2$
test $1 + 1 = 2$ 

which is infinitely better. Is there a way I can configure the fill-command to work correctly? I'm using Emacs 24.5.1 on Windows and AUCTeX 11.88.9.

1 Answer 1

5

The behavior of filling of math switches is controlled by the LaTeX-fill-break-at-separators variable and there are currently discussions about its best default value.

I recently came up with with setting

(setq LaTeX-fill-break-at-separators '(\\\( \\\[))

which fulfills the goal of keeping math formulae in the the same line (this is useful for example for preview-latex) and to provide a somewhat pleasing filling. With the above setting, your code is filled as you expected (fill-column set to 70). As suggested by Omar Antolín-Camarena in comments, it should be noted that the presence of the opening \( in that list affects also the behavior of $ as AUCTeX treats them in the same way.


For the record, the above value LaTeX-fill-break-at-separators is now the default in the just released AUCTeX 11.89.

4
  • Sorry, I copied it wrong, you should remove the closing braces, I'm going to update the answer, i.e. use only the opening braces. The problem of removing also the opening braces it that formulae may be broken at the end of a line, which is not good for preview-latex.
    – giordano
    Commented Nov 10, 2015 at 10:16
  • 1
    Just to be explicit for future readers: this does work even though dollar signs are not mentioned in the variable! AucTeX treats them just like \\\(.
    – Omar
    Commented Nov 10, 2015 at 21:17
  • The $ seems not working here...:( Commented Jan 15, 2016 at 1:14
  • Please, provide an example.
    – giordano
    Commented Jan 15, 2016 at 8:07

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.