Note: This is probably a duplicate, but I can't figure out the right search terms. If you can post the link to the original question and close this one, it would be greatly appreciated.

I followed the advice here, and now AucTeX has the correct font highlighting and has math mode enabled in my custom math environment. But AucTex doesn't auto-complete \left[ \right] or \left( \right) in my custom math environment, which is really inconvenient.

Question: How can I change my .emacs file to have AucTeX auto-complete \left[ \right], \left( \right) in my custom math environment?

For reference, here is my .emacs:

(require 'package)
(require 'yasnippet)
(yas-global-mode 1)
(require 'auto-complete)
(add-to-list 'ac-modes 'latex-mode) 
(require 'ac-math) 
(defun my-ac-latex-mode () 
   (setq ac-sources
         (append '(;  again, I don't want unicode: ac-source-math-unicode
(add-hook 'LaTeX-mode-hook 'my-ac-latex-mode)
(add-to-list 'ac-modes 'org-mode)
(require 'auto-complete-config) 
(setq ac-auto-start t)          
(setq ac-auto-show-menu t)
(global-auto-complete-mode t) 
(show-paren-mode 1)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(auto-fill-mode -1)
(remove-hook 'text-mode-hook #'turn-on-auto-fill)
(remove-hook 'text-mode-hook 'auto-detect-wrap)
  '((lambda nil (auto-fill-mode nil))
(auto-fill-mode nil)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)
(setq mouse-wheel-follow-mouse 't)
(setq scroll-step 1)
(setq mac-mouse-wheel-mode t)
(setq mac-mouse-wheel-smooth-scroll t)
(setq TeX-save-query nil)

(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(setq TeX-PDF-mode t)
(require 'smartparens-config)
(add-hook 'LaTeX-mode-hook #'smartparens-mode)

(add-hook 'LaTeX-mode-hook 'add-my-latex-environments)
(defun add-my-latex-environments ()
   '("formulae" LaTeX-env-label)))

 '(font-latex-math-environments (quote  
  '(TeX-insert-braces nil))

(setq reftex-label-alist 
  '(("formulae" ?e nil nil t))) 
  • You can use C-c C-m and type left and your brace
    – lawirz
    Mar 7, 2020 at 6:07

1 Answer 1


Try to add the following command to your .emacs file:

(setq LaTeX-electric-left-right-brace t)

  • This almost works -- now when I type \left[ it auto-completes to \left[ ] \right], i.e. it auto-completes as both [] (which is all it did before) and now also \left[ \right]. Same thing with \left( -- now it auto-completes to \left( ) \right) instead of just \left( \right) (what I want and what happens in non-custom math modes) or just () (what it was before). Sep 18, 2018 at 20:46
  • Do you know of a way to make the other auto-complete function stop inside this environment? Sep 18, 2018 at 20:46
  • Also, now outside of any math environment (i.e. just plain text), \left( auto-completes to \left( \right)) (notice the two right-parentheses), and \left[ auto-completes to \left[ \right]]. So the same behavior as in the custom math environment but in the opposite order I guess. Sep 18, 2018 at 20:49
  • 1
    With me this works as expected, i.e \left( --> \left ( \right) even in math mode. So I suspect something wrong in your .emacs file. Try to figure out what you have tried before!! Sep 18, 2018 at 21:02
  • 1
    After looking in your .emacs, I suspect smartparens-mode. So try to disable it in latex-mode. Sep 18, 2018 at 21:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .