1

I'm having a heck of a time optimizing my desired \cite behavior when writing LaTeX source in emacs using helm-bibtex. I made a C-c [ key-binding to get helm-bibtex going when I want to insert a citation:

(autoload 'helm-bibtex "helm-bibtex" "" t)
(global-set-key (kbd "C-c [") 'helm-bibtex-with-local-bibliography)

What I want then is once I press C-c [, I want to start typing the name of a bib key, and when the entry is highlighted, I want to press Enter and it should insert the block \cite{mykey} into the text.

However the current process is so inefficient, I have to do C-c [, start typing until entry is highlighted, press F3, and then it asks me which kind of citation command I want where cite is the default, then it asks for "prenotes", then "postnotes", then FINALLY it inserts the cite block.

How do I get the behavior described first where I just press enter and it inserts cite block, instead of having to press a function key and Enter 3 times?

adamconkey
  • 113
  • 4

1 Answers1

2

There doesn't appear to be a way to stop helm-bibtex from asking which kind of citation you want. You can stop it from asking you for prenotes and postnotes:

(setq  bibtex-completion-cite-prompt-for-optional-arguments nil)

You can also make inserting a citation the default action:

(helm-delete-action-from-source "Insert Citation" helm-source-bibtex)
(helm-add-action-to-source "Insert Citation" 
                           'helm-bibtex-insert-citation 
                            helm-source-bibtex 0)

This will automatically insert a citation when you hit enter, so you don't need to select it with f3.

With these values set, I can enter a new citation via:

  1. M-x helm-bibtex (or your keybinding)
  2. search for the entry
  3. hit enter twice

That saves you two keypresses. I agree it would be nice to have helm-bibtex default to adding cite, without having to select it. It seems like there should be a way to configure this, but I don't see it.

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • 1
    The issue I'm seeing when I try this is I get the error `Wrong type argument: sequencep, 122` where the 122 is the ascii char number for `z` which is the first letter of the bibtex item key I selected on pressing Enter the first time in your Step 3. Any thoughts on this? – adamconkey Apr 23 '21 at 20:03
  • Sorry, pasted the wrong code. Try the edited version – Tyler Apr 23 '21 at 20:42
  • Thanks that did the trick, definitely far more efficient than the original. – adamconkey Apr 23 '21 at 22:12
  • Great solution! It works on Emacs 28 – PinkCollins Jun 30 '23 at 05:08