1

This answer says how to make AUCTeX use tabs for leading indentation. However, it doesn't work for me and I don't understand why it doesn't.

After adding the code to my init file, LaTeX-mode just stopped indenting altogether.

I suspected that's because I customized variable and removed the LaTeX-mode- and indentation-related lines

 '(LaTeX-indent-level 4)
 '(LaTeX-item-indent 0)
 '(TeX-brace-indent-level 4)
 '(indent-tabs-mode t)

from the block

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(LaTeX-indent-level 4)
 '(LaTeX-item-indent 0)
 '(TeX-brace-indent-level 4)
 '(indent-tabs-mode t)
 '(org-agenda-files
   (quote
    (<I censored the strings in here.>)))
 '(org-file-apps
   (quote
    ((auto-mode . emacs)
     ("\\.mm\\'" . default)
     ("\\.x?html?\\'" . default)
     ("\\.pdf\\'" . "evince %s"))))
 '(safe-local-variable-values (quote ((TeX-master . t))))
 '(show-paren-mode t)
 '(tool-bar-mode nil))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

in my init file after backing ~/.emacs.d up as the comments say I'm not supposed to modify that block by hand. LaTeX mode still didn't indent (at all), so I had to remove the code I got from the linked answer and go back to indentation via spaces.

How do I get indentation via tabs working?


Update

After removing the customization with Andrew Swann's help and adding the code stated in the linked answer back to my init file, AUCTeX still doesn't use tabs for indentation. Or rather: It doesn't seem to indent anything. I tried setting LaTeX-indent-level to 4 and LaTeX-item-indent to 0 and even setting LaTeX-item-indent to 4, too. It still didn't indent.

When I hit Tab, however, it actually enters a tab character.

  • You can modify those settings via the customization interface: M-x customize or M-x customize-variable. – Andrew Swann Sep 26 '17 at 5:18
  • @AndrewSwann I know how I can customize the values of those variables but not how I can reset them to their default values so customize deletes those lines from the init file. That's why I tried simply deleting the lines to see whether it worked would I be able to reset those variables properly. – UTF-8 Sep 26 '17 at 13:42
  • The customize interface has the option to clear the customization resetting to the standard varibale. This is under the options from the "State" button. – Andrew Swann Sep 26 '17 at 14:52
  • @AndrewSwann Thank you. Resetting the variables worked but the indentation still doesn't. I updated the question. – UTF-8 Sep 26 '17 at 16:00
  • What is TAB key bound to? Issue C-x k TAB – giordano Sep 27 '17 at 5:56
0
+50

With this minimal init.el, it works for me:

;; --- This is just the MELPA setup to fetch auctex ---
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
  (add-to-list 'package-archives (cons "melpa" url) t))
(when (< emacs-major-version 24)
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)

;; --- Remove the indent-line-function overwrite
(add-hook 'LaTeX-mode-hook
          (lambda ()
            (setq indent-tabs-mode t)))

(custom-set-variables
 '(LaTeX-indent-level 4)
 '(LaTeX-item-indent 4)
 '(TeX-brace-indent-level 4)
 '(indent-tabs-mode t)
 '(package-selected-packages (quote (auctex))))

If you want the tab to be 4 spaces wide, you can M-x customize-variable RET tab-width and set it to 4.

So, the customizations are:

  • Set indent-tabs-mode for LaTeX:

    (add-hook 'LaTeX-mode-hook
              (lambda ()
                (setq indent-tabs-mode t)))
    
  • Customize indent sizes for LaTeX:

     '(LaTeX-indent-level 4)
     '(LaTeX-item-indent 4)
     '(TeX-brace-indent-level 4)
     '(indent-tabs-mode t)
    
  • Now I'm very confused. I copied everything from ;; --- Remove the indent-line-function overwrite downwards into my init file. Then AUCTeX suddenly actually used tabs for leading indentation. Great. But the automatically created comments say I'm not supposed to have more than 1 custom-set-variables variables block, so I made sure I set all the variables but the last one in your custom-set-variables block to what you set them to. I didn't figure out how to set the last one using M-x RET customize-set-variable, so I removed all but the last (and very first, of course) line of your ... – UTF-8 Oct 1 '17 at 22:06
  • ... custom-set-variables block and left the add-hook block above as it was. It then stopped working. AUXTeC went back to using spaces. Why doesn't it work when I try to use M-x RET customize-set-variable? If it needs to be in the same custom-set-variables block, how do I generate the last line using M-x RET customize-set-variable? (Because the automatically created comments say one should do it that way and not edit the block directly.) – UTF-8 Oct 1 '17 at 22:08
  • I'm guessing you mean, by the last line of custom-set-variables, this one: (package-selected-packages ..., right? That was just added automatically when I installed AUCTeX (M-x package-install RET auctex RET), but you shouldn't worry about that because there's probably already another block with package-selected-packages and auctex inside somewhere. – Marcel Samyn Oct 2 '17 at 17:58
  • The only changes that should be made are the code blocks at the end; the first one somewhere in your init file and the last one as customizations. So...honestly if that doesn't work I'm out of guesses too :/ (as I can't reproduce your setup here) – Marcel Samyn Oct 2 '17 at 18:01
  • I think something with my TeX-brace-indent-level was wrong because I was able to remove all the other lines without it stopping to work. After setting it again via customize, the block was removed from my init file automatically whilst customizing. After setting the tab width to 4, it inserted 2 tabs. So I customized LaTeX-item-indent to 0 and it now works as I wanted it to. Thank you. – UTF-8 Oct 2 '17 at 19:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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