I expected the following code would toggle electric-pair-local-mode every time I toggle LaTeX-math-mode (CTRL+C ~ in LaTeX-mode). It only works one way meaning it does turn on the electric pair mode locally after I have entered the math mode but then Emacs stays in this mode even though I disable the math mode.

(add-hook 'LaTeX-math-mode-hook 'electric-pair-local-mode) 

I tried things like (setq electric-pair-local-mode -1) but evaluating this expression does not make any expected effect meaning Emacs still uses electric pair mode.

I tried to search for similar solutions and it seems checking mode and setting +1 or -1 or t and nil works for other modes but this one. I might be missing something regarding the electric mode and I would appreciate any help. Thanks.

1 Answer 1


C-h f electric-pair-local-mode RET says:


This is a minor mode.  If called interactively, toggle the
‘Electric-Pair-Local mode’ mode.  If the prefix argument is
positive, enable the mode, and if it is zero or negative, disable
the mode.

If called from Lisp, toggle the mode if ARG is ‘toggle’.  Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.


You’re calling it from Lisp, so the second paragraph applies. You can therefore do something along the lines of:

(add-hook 'LaTeX-math-mode-hook (lambda () (electric-pair-local-mode 'toggle)) 
  • 1
    It's working thanks. I knew about the help but still need to make a habit of checking it first. Thanks
    – Celdor
    Sep 4, 2022 at 10:17

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.