I have inserted the following code in my init file. This code insert a space+\ (ie, " \") when typing \ in a buffer.

Despite the fact that the function ddd works without problem in any buffer, the shortcut \ doesn't work when the file is in LaTeX mode (AUCTeX).

Is there any solution to solve this problem, i.e. typing \ executes the function ddd? The function ddd is just an example, the same problem occurs for any function I bind to the backslash.

(defun ddd ()
  "Insert a dollar sign with a space in front."
  (insert " \\"))

(global-set-key (kbd "\\") 'ddd)
  • 1
    This is a Bad Idea™ – I would not recommend this to any user of AUCTeX, but your workflow is yours… Dec 7, 2014 at 19:57

1 Answer 1


When using AUCTeX, \ is bound to TeX-insert-backslash by default, which you can discover by entering C-h k \ (ie, describe-key) when in a buffer in latex-mode.

If you really want to override TeX-insert-backslash with ddd, define the key in the LaTeX-mode-map as such:

(define-key LaTeX-mode-map (kbd "\\") #'ddd)

You need to bind this key after loading AUCTeX so that Emacs knows about the keymap -- you could, for example, do an eval-after-load to achieve this:

(eval-after-load "latex"
  '(define-key LaTeX-mode-map (kbd "\\") #'ddd))

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.