[Tex/LaTex] AUCTeX: turn off autoindent

auctexeditors

This isn't TeX, per se, but it is about writing TeX, so perhaps it is appropriate. I find that AUCTeX's autoindent works in a way that runs counter to how I work. In case I am not clear, for instance, I like to have footnotes indented as below. When I type the close curly braces and ENTER AUCTeX will bring the footnote back to the first column. I move it back and start a new line, as below, and when I type "paragraph." and hit ENTER it moves "Start" by two spaces.

end.\footnote{%
    This is a footnote.}

Start of a new paragraph.
Second line

Whe it happens once it is an annoyance. Hundreds of times is an issue.

I've spent too much time tweaking autoindent and at this point I'd rather just indent by hand. I've searched for how to turn it off in a number of places, including here and on emacs sites, without enlightenment. At the moment this is my .emacs file, but I'm just flailing.

;; JH trying to turn off AUCTeX indenting
(setq LaTeX-indent-environment-list '())
(setq LaTeX-indent-level 0)
(setq LaTeX-item-indent 0)
(setq LaTeX-left-right-indent-level 0)
(setq TeX-brace-indent-level 0)

Best Answer

David Carlile has a point in mentioning TeX-newline-function, which is, by default, set to newline. Looking the latter's docstring, we find:

If ‘electric-indent-mode’ is enabled, this indents the final new line that it adds, and reindents the preceding line. To just insert a newline, use M-x electric-indent-just-newline.

I can reproduce the behavior you describe with my settings, and it appears electric-indent-mode is on by default (I don't have it explicitly in my init file, and it was on here). Indeed, disabling it, the editor does let me "Start of a new paragraph." without the extra spaces.

So, disabling electric-indent-mode (in LaTeX-mode, or everywhere, as you prefer) or setting TeX-newline-function to electric-indent-just-newline may be two good alternatives for you.

One sensible way to disable electric-indent-mode for specific modes is suggested at Disabling electric-indent-mode for one mode (latex mode) only. Which is to create a function to disable electric-indent-local-mode and then hook it to the mode(s) of interest:

(defun JH/remove-electric-indent-mode ()
  (electric-indent-local-mode -1))

(add-hook 'LaTeX-mode-hook 'JH/remove-electric-indent-mode)
(add-hook 'tex-mode-hook 'JH/remove-electric-indent-mode)
;; and so on

However, you seem to be fighting auto-indent in general, when it should be there to help you. For example, the reason in the first place why "When I type the close curly braces and ENTER AUCTeX will bring the footnote back to the first column." seems to be that you set (setq TeX-brace-indent-level 0). Furthermore, the fact that "when I type "paragraph." and hit ENTER it moves "Start" by two spaces" seems to indicate you have indentation set to two spaces. However, when you manually indented your footnote, you added four spaces.

The default behavior seems to rely heavily on auto-indent doing the right thing, which makes sense. However, I think you could get things to work quite close to what your are picturing, along with auto-indent, with:

(setq TeX-brace-indent-level 4)

Which will set your footnotes (and any other open braces) indented to four spaces, while the rest remains with two spaces. That alone should allow you to type what you describe.