3

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.

antonio
  • 10,629
  • 13
  • 68
  • 136
  • @wvxvw: To clarify, I said: "To get to the functions involved, I tried with `C-h k`". In order to use a binding function such as: `global-set-key` or `define-key`, you need to know the name of the command to bind. ``C-h k` helps in as far as typing `C-h k C x 1` will show that the sequence `C x 1` is bound to the command named `delete-other-windows`, which allows me to rebind it with the above functions. As told, `C-h k C-c C-f C-b` doesn't work as expected, i.e. you don't get the name of the command bound to `C-c C-f C-b`. – antonio Jan 31 '13 at 19:56
  • @wvxvw: again for some reason I see `C-c C-f`, but I am unable to find `C-c C-f C-b` – antonio Jan 31 '13 at 22:39
  • @wvxvw: I am not sure, but if you type `C-c C-f C-b` in LaTeX mode, you get `\textbf{}`. Anyway, inspecting `tex.el`, as suggested by Tyler, showed the related function is `(TeX-font nil ?\C-b)`. – antonio Jan 31 '13 at 23:05
  • I found a solution for `C-h k` with custom prefixes. The trick is `C-c C-f C-h`. It is a kind of `C-h k C-c C-f C-b` which, instead, works. Sorry, wvxvw the system is discouraging me to interact with you. I get "Please avoid extended discussions in comments." I'd rather to comply to avoid to unleash the wrath of SE. – antonio Jan 31 '13 at 23:57
  • @wvxvw: I added a brief explanation as to why you can't find the key bindings in the usual way to my answer. – Tyler Feb 01 '13 at 03:31

2 Answers2

5

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).

Tyler
  • 9,872
  • 2
  • 33
  • 57
  • +1, but why numbers? Following your suit I dug `tex.el`. It seems I can do it like `(TeX-font nil ?\C-b)` instead of `(TeX-font nil 2)`, and similarly I can use `?\C-e`, `?\C-i`, etc. – antonio Jan 31 '13 at 22:57
  • @antonio: At the time I wrote this, I think, the source of TeX-font-list used numbers, rather than the much more sensible char-values (e.g., ?\C-i etc.). I kept the numbers for consistency. I see that sometime since they switched to using the char-values. I'll update my answer (and my code). – Tyler Feb 01 '13 at 03:18
  • Well, `TeX-italics` was missing. I edited the answer. For coherence with other functions, I used `TeX-italic`, no 's'. – antonio Feb 02 '13 at 16:10
1

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.

Community
  • 1
  • 1
antonio
  • 10,629
  • 13
  • 68
  • 136
  • Just saw this. What was the error in my code? I don't see a difference with what you've done. – Tyler Nov 19 '13 at 16:37
  • @Tyler: In the list of the functions `(defun TeX-italic()...` is missing, despite there is a `(local-set-key "\C-ci" 'TeX-italic)`. Probably I should say a typo. In writing I changed the spell with "italic", using an adjective like the following `TeX-bold` and like the native `facemenu-set-italic`. You can see I detail this in a comment to your answer and claim I fixed this too. I did, but the editing was not accepted by SO because of my reputation. – antonio Nov 20 '13 at 12:20