I'm trying to rebind a few keys in AUCTeX, mainly \textit and the like. So, as a test I've added to .emacs

(add-hook 'LaTeX-mode-hook
  (lambda ()
    (define-key LaTeX-mode-map (kbd "C-S-i") 'find-file)

It works, but which is the command I have to write instead of find-file to insert \textit as C-c C-f C-i does?


A very useful function in Emacs is describe-key that will tell you what function is being called by which keys. So, it seems that in AucTEX, C-c C-f C-i calls TeX-font and then passes C-i as argument.

So a simple solution would be to bind a key to TeX-font and keep the C-i (and others) to get the font you want. You can customize the list of possible fonts and secondary key shortcuts with TeX-font-list. You would thus have a simple:

(define-key LaTeX-mode-map (kbd "C-S-i") 'TeX-font)

(with whatever key you want).

If you really want to only rebind the italics and nothing else, you can always do:

(define-key LaTeX-mode-map (kbd "C-S-i") '(lambda () (interactive)(TeX-font nil ?\C-i)))

no need to redefine the whole behaviour of TeX-font.

  • Great. This is exactly what I was looking for. – Javier Bezos Apr 6 '12 at 12:39

You may use something like this:

  (defun insert-textit()
  "places textit{} into LaTeX buffer."
  (if (region-active-p)
          (goto-char (region-beginning))    
          (insert "\\textit{" ))
          (goto-char (region-end))
          (insert "}")))
    (insert "\\textit{}")
    (goto-char (forward-point -2)))
  (goto-char (forward-point 1)))

    (add-hook 'LaTeX-mode-hook
      (lambda ()
        (define-key LaTeX-mode-map (kbd "C-S-i") 'insert-textit)


This extended code handles the case of marked region too.

Edit #2

I removed the not needed concat and last progn

  • If there is a marked region C-c C-f C-i will wrap that region in \textit. This function lack that functionality. – N.N. Apr 4 '12 at 20:10
  • Thanks. Your post answers another question I didn't even ask (how to write a function applied to a region). – Javier Bezos Apr 5 '12 at 6:49
  • I do not think the concat and the last progn is needed. The function seems to work well when they are removed. – N.N. Apr 5 '12 at 7:02

I've found a simple (and general) approach based on macros (thanks to insert-kbd-macro, which I've just discovered). Since I needn't remove C-c C-f C-i I define a macro and then I bind it to C-S-i.

(fset 'my-set-textit
   (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item `(,(kbd "C-c C-f C-i") 0 "%d") arg)))

Then I use 'my-set-textit in define-key. (Edit: replaced code with special chars.)

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.