0

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)))
  • 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 '16 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 '16 at 10:59
3

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\}
  • If one likes to temporary disable inserting electric braces, one use C-q or C-u 1 before typing {, (, [, etc. – Name Sep 22 '16 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 '16 at 8:22
  • No, I don't use smart parens, sorry. – giordano Oct 9 '16 at 10:30

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.