According to https://www.emacswiki.org/emacs/AutoPairs the package smartparens supports an electric pair of any length for example \{.

My question about the possibility that the built-in electric-pair-mode can do it. I tried this without success:

(add-hook 'LaTeX-mode-hook
              (lambda ()
                (define-key LaTeX-mode-map "\\{" 'electric-pair)))
  • 1
    AUCTeX doesn't play nicely with electric-pair-mode, this minor mode is actually disabled in AUCTeX if LaTeX-electric-left-right-brace is non nil.
    – giordano
    Sep 15, 2016 at 10:56
  • @giordano if you have a solution purely based on auctex or any other suggestion (e.g. using another package) I would be grateful. Otherwise I am happy to use smartparens.
    – Name
    Sep 15, 2016 at 10:59

1 Answer 1


AUCTeX has a bultin support for pairing braces, and \{...\} is in the default set of supported braces. In order to enable this feature, just set LaTeX-electric-left-right-brace to non nil, either with customize interface (M-x customize-variable RET LaTeX-electric-left-right-brace RET) or by adding the following line to your init file:

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

This is much more advanced than any other generic mode for pairing braces, because it is able to do something like this:

\Bigl\{  →  \Bigl\{\Bigr\}
  • 1
    If one likes to temporary disable inserting electric braces, one use C-q or C-u 1 before typing {, (, [, etc.
    – Name
    Sep 22, 2016 at 9:26
  • I enable smartparens-mode globally, but since LaTeX-electric-left-right-brace is more useful for tex file, so I disable sp using (turn-off-smartparens-mode) inside LaTeX-mode-hook, but sp will always be triggered somehow after some time of editing tex file, and I don't know how to completely in LaTeX-mode. Any idea?
    – CodyChan
    Oct 9, 2016 at 8:22
  • No, I don't use smart parens, sorry.
    – giordano
    Oct 9, 2016 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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