# How to have AucTeX auto-complete \left[ \right], \left( \right) in custom math environment?

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)
(package-initialize)
(require 'yasnippet)
(yas-global-mode 1)
(require 'auto-complete)
(require 'ac-math)
(defun my-ac-latex-mode ()
(setq ac-sources
(append '(;  again, I don't want unicode: ac-source-math-unicode
ac-source-math-latex
ac-source-latex-commands)
ac-sources)))
(ac-flyspell-workaround)
(require 'auto-complete-config)
(ac-config-default)
(setq ac-auto-start t)
(global-auto-complete-mode t)
(show-paren-mode 1)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(auto-fill-mode -1)
(remove-hook 'text-mode-hook #'turn-on-auto-fill)
(remove-hook 'text-mode-hook 'auto-detect-wrap)
'(text-mode-hook
'((lambda nil (auto-fill-mode nil))
smart-spacing-mode))
(auto-fill-mode nil)
(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)

(setq TeX-PDF-mode t)
(require 'smartparens-config)

'("formulae" LaTeX-env-label)))

(custom-set-variables
'(font-latex-math-environments (quote
("formulae")))
'(TeX-insert-braces nil))

(setq reftex-label-alist
'(("formulae" ?e nil nil t)))


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). – Chill2Macht Sep 18 '18 at 20:46
• Do you know of a way to make the other auto-complete function stop inside this environment? – Chill2Macht Sep 18 '18 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. – Chill2Macht Sep 18 '18 at 20:49
• 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!! – Hafid Boukhoulda Sep 18 '18 at 21:02
• After looking in your .emacs, I suspect smartparens-mode. So try to disable it in latex-mode. – Hafid Boukhoulda Sep 18 '18 at 21:18