Question

I'd like to modify font bindings, such as C-c C-f C-b, to something faster, such as C-b. To get to the functions involved, I tried with C-h k, but I am unable to terminate the key sequence properly: in fact as I type C-c C-f, it triggers the help page for TeX-font command.

Secondly, I'd like to override confirmation in C-c C-c. I don't understand how to use the OVERRIDE-CONFIRM argument in general and in particular how I could associate everything to a new binding, say F1, without confirmation.

Thanks for helping.

Was it helpful?

Solution 2

With my "powers" I am unable to fix a little error in Tyler code. Here I partly rewrite it and I give a solution for the second part of the question too.

Redefine AUCTeX font keybindings

Assume we want to set these font bindings (but you can modify them at will):

Italic      "\C-ci" 
Bold        "\C-cb" 
Typewriter  "\C-ct" 
Emphasis    "\C-ce" 
Smallcaps   "\C-cs" 

Add these line to your init.el, or whatever the name of your Emacs init file:

(defun TeX-italic()
  (interactive)
  (TeX-font nil ?\C-i))

(defun TeX-bold()
  (interactive)
  (TeX-font nil ?\C-b))

(defun TeX-typewriter()
  (interactive)
  (TeX-font nil ?\C-t))

(defun TeX-emphasis()
  (interactive)
  (TeX-font nil ?\C-e))

(defun TeX-smallcaps()
  (interactive)
  (TeX-font nil ?\C-c))

(defun latex-font-hook ()
  (local-set-key "\C-ci" 'TeX-italic)
  (local-set-key "\C-cb" 'TeX-bold)
  (local-set-key "\C-ct" 'TeX-typewriter)
  (local-set-key "\C-ce" 'TeX-emphasis)
  (local-set-key "\C-cs" 'TeX-smallcaps))

(add-hook 'LaTeX-mode-hook 'latex-font-hook)

If you are dissatisfied with the keys used here, change the first argument of local-set-key as you like it, e.g. set (local-set-key "\C-b" 'TeX-bold) to bind to Control-b.

Redefine AUCTeX compile keybinding

To modify the C-c C-c keybinding and possibly to meliorate the bound compilation function (TeX-command-master), please see my post Build & view.

OTHER TIPS

The auctex font keybindings are particularly tricky to sort out, because the command you are after uses the interactive function with the "c" code letter. As a consequence, C-c C-f calls the function TeX-font, and the next letter you type is collected as an argument to be passed to this function. So C-c C-f is bound to a function, but acts like a prefix. See the linked manual page for a full explanation.

This means the usual suggestions offered as comments won't be enough to get what you want. The key piece of code you need to invoke is TeX-font. Getting the correct arguments required digging into the source code. I use the following functions in my .emacs:

(defun TeX-typewriter()
  (interactive)
  (TeX-font nil ?\C-t))

(defun TeX-bold()
  (interactive)
  (TeX-font nil ?\C-b))

(defun TeX-emphasis()
  (interactive)
  (TeX-font nil ?\C-e))

(defun TeX-smallcaps()
  (interactive)
  (TeX-font nil ?\C-c))

With those functions defined, I then apply the keybindings in the LaTeX-mode-hook:

(defun my-LaTeX-hook ()
  (local-set-key "\C-ci" 'TeX-italics)
  (local-set-key "\C-cb" 'TeX-bold)
  (local-set-key "\C-ct" 'TeX-typewriter)
  (local-set-key "\C-ce" 'TeX-emphasis)
  (local-set-key "\C-cs" 'TeX-smallcaps))

(add-hook 'LaTeX-mode-hook 'my-LaTeX-hook)

This binds TeX-bold to C-c b, but you could use whatever you like here (such as C-b as you asked for).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top