4

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)
  • 1
    do you want to turn off auto-fill-mode entirely (M-x auto-fill-mode ) ? – David Carlisle Dec 31 '18 at 17:00
  • Don't have any emacs to test anymore, so this is just a not so strong hypothesis, but are you sure some 0 shouldn't be replaced with nil ? – sztruks Dec 31 '18 at 19:49
  • @DavidCarlisle I did not mean to ask about autofill, I meant autoindent, where when you hit <enter> AUCTeX will change the indent of the line. I edited the post to try to be clearer. – Jim Hefferon Dec 31 '18 at 22:18
  • @sztruks I am clearly doing something wrong, but I think that those are numbers to indent by. – Jim Hefferon Dec 31 '18 at 22:18
  • 1
    @JimHefferon hmm doesn't for me, but then I last configured auctex last century:-) C-h k suggest <enter> runs the function set by the customisable variable TeX-newline-function so perhaps you want to customise that... – David Carlisle Dec 31 '18 at 22:29
3

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.

  • 2
    electric-indent-mode changed behaviour at Emacs 24.4, see here and it is nightmarish with AUCTeX mode. I turn it off for tex in my init file. Also for some other modes. – user4686 Jan 1 at 11:01
  • 1
    @jfbu Thank you for the pointer, I wasn't aware of this discussion. Though it doesn't really interfere much with my own use, I do agree messing with <Ret> default behavior in this way is quite intrusive. Given your experience with the matter, would you say I should revise the advice in the answer? How do you usually disable electric-indent-mode for AUCTeX? – gusbrs Jan 1 at 11:16
  • 1
    For reference, one sensible way to disable electric-indent-mode for LaTeX-mode: emacs.stackexchange.com/a/30148/18951 – gusbrs Jan 1 at 11:27
  • I had forgotten but I turned it off as part of a hook to lisp-mode, see gist and it is inherited by tex mode in particular. And my initial-major-mode is left unmodified (lisp-interaction-mode) (I don't know if that last remark has any relevance, it seems to regard *scratch* buffer) – user4686 Jan 1 at 11:59
  • 1
    @JimHefferon I was actually unaware of electric-indent-mode workings, because it felt sensible to me. But it was nice to get a better grasp on it. And, I must admit, depending on what you expect, it does make sense to disable it selectively or altogether. – gusbrs Jan 1 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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