1

In AucTeX there are two useful commands: C-c C-e for inserting the environment and C-u C-c C-e for changing the environment at the point to another one. For me the latter command is quite inconvenient, so I would like to rebind it to something simpler, lets say, to C-c e I've tried to do that in a standard way:

    (defun my-tex-mode-hook ()
    (local-set-key ((kbd "C-c e") (kbd "C-u C-c C-e")))
    (add-hook 'TeX-mode-hook 'my-tex-mode-hook)

but the command C-c e does not ask for the argument, i.e., which environment I want to choose. Instead it always changes to default itemize environment. Moreover, it works only one time per emacs session.

Probably, my question fits better for the Emacs community, then sorry for that.

0

Add the following code to your init file:

(with-eval-after-load "latex"
  (define-key LaTeX-mode-map (kbd "C-c e")
    (lambda ()
      (interactive)
      (LaTeX-environment 1))))

I'm assuming you have Emacs 24.4 or newer versions, otherwise this code will need to be slightly changed (with-eval-after-load was introduced in that version).

  • In my Emacs 24.5.1 I've got the following error message: Symbol's value as variable is void: LaTeX-mode-map – cheyp Mar 23 '17 at 9:49
  • with-eval-after-load is needed to evaluate the code after the package has been loaded (and the mode map defined), I really can't understand why you get that error, doesn't happen to me :-/ – giordano Mar 23 '17 at 11:22
  • Neither me do. But it started to work when I put your code without the first line (with-eval-after-load "latex" instead of my command (local-set-key ((kbd "C-c e") (kbd "C-u C-c C-e"))). Thanks! How I survived earlier without that command... – cheyp Mar 23 '17 at 14:56

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.