2

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."
  (interactive)
  (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… – Sean Allred Dec 7 '14 at 19:57
6

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, privacy policy and cookie policy

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