Files
org-roam/20230522133530-helm_bibtex.org
2025-11-05 09:18:11 +01:00

87 lines
5.9 KiB
Org Mode
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
:PROPERTIES:
:ID: b3503901-bb4f-4fda-b85f-5e738df311fb
:END:
#+title: helm-bibtex
#+filetags: :EMACS:
Helm-bibtex is a search engine based on Helm literature. You can specify here the path to the bibtex file and to the corresponding PDF.
* Minimal config
#+begin_src emacs-lisp
;;(autoload 'helm-bibtex "helm-bibtex" "" t)
(use-package helm-bibtex
:ensure t
)
#+end_src
A minimal configuration involves telling bibtex-completion where your bibliographies can be found:
#+begin_src emacs-lisp
(setq bibtex-completion-bibliography
'("/path/to/bibtex-file-1.bib"
"/path/to/bibtex-file-2.bib"))
#+end_src
Org-bibtex users can also specify org-mode bibliography files, in which case it will be assumed that a BibTeX file exists with the same name and extension bib instead of org. If the bib file has a different name, use a cons cell ("orgfile.org" . “bibfile.bib") instead:
#+begin_src emacs-lisp
(setq bibtex-completion-bibliography
'("/path/to/bibtex-file-1.bib"
"/path/to/org-bibtex-file.org"
("/path/to/org-bibtex-file2.org" . "/path/to/bibtex-file.bib")))
#+end_src
* Basic config
Specify where PDFs can be found:
#+begin_src emacs-lisp
(setq bibtex-completion-library-path '("/path1/to/pdfs" "/path2/to/pdfs"))
#+end_src
Bibtex-completion assumes that the name of a PDF consists of the BibTeX key followed plus a user-defined suffix (.pdf by default). For example, if a BibTeX entry has the key Darwin1859, bibtex-completion searches for Darwin1859.pdf.
If the BibTeX entries have a field that specifies the full path to the PDFs, that field can also be used. For example, JabRef and Zotero store the location of PDFs in a field called File:
#+begin_src emacs-lisp
(setq bibtex-completion-pdf-field "File")
#+end_src
If bibtex-completion-pdf-field is non-nil, bibtex-completion will first try to retrieve the file specified in this field. If the field is not set for an entry or if the specified file does not exists, bibtex-completion falls back to the method described above (searching for key + .pdf in the directories listed in bibtex-completion-library-path).
File specifications can be bare paths or follow the format used by JabRef, Zotero, Calibre, and Mendeley. This format also allows the specification of multiple files (e.g., the main paper and supplementary material). Examples:
File = {/path/to/article.pdf}
File = {:/path/to/article.pdf:PDF}
File = {:/path/to/article.pdf:PDF;:/path/to/supplementary_materials.pdf:PDF}
* Notes
ibtex-completion supports two methods for storing notes. It can either store all notes in one file or store notes in multiple files, one file per publication. In the first case, the customization variable bibtex-completion-notes-path has to be set to the full path of the notes file:
#+begin_src emacs-lisp
(setq bibtex-completion-notes-path "/path/to/notes.org")
#+end_src
If one file per publication is preferred, bibtex-completion-notes-path should point to the directory used for storing the notes files:
#+begin_src emacs-lisp
(setq bibtex-completion-notes-path "/path/to/notes")
#+end_src
The names of these files consist of the BibTeX key plus a user-defined suffix (.org by default).
At this point most people will be ready to go. Skip to Usage below to see how to use helm-bibtex and ivy-bibtex.
* Follow Processor
Invoking helm-bibtex or ivy-bibtex when point is on an org-mode citation will automatically select that key. However, the default org-open-at-point on a org citation will take you to the corresponding bibliography entry. The following code will change this behavior to instead open helm-bibtex-follow when following an org citation by entering RET or clicking on it:
#+begin_src emacs-lisp
(setq org-cite-follow-processor 'helm-bibtex-org-cite-follow)
#+end_src
Note in the case of an org citation with multiple keys, the above code will not preselect any entry when the [cite: portion is selected. See here for the ivy alternative.
* LaTeX citation commands
Bibtex-completion prompts for a LaTeX citation command when inserting citations in LaTeX documents. The list of commands available for auto-completion can be defined using the variable bibtex-completion-cite-commands.
The default setting includes all cite commands defined in biblatex (except multicite commands and \volcite et al.). If no command is entered, a default command is used which can be configured using bibtex-completion-cite-default-command. The default value for the default command is cite. The variable bibtex-completion-cite-default-as-initial-input controls how the default command is used. If t, it is inserted into the minibuffer before reading input from the user. If nil, it is not inserted into the minibuffer but used as the default if the user doesnt enter anything.
By default, bibtex-completion also prompts for the optional pre- and postnotes for the citation. This can be switched off by setting the variable bibtex-completion-cite-prompt-for-optional-arguments to nil.
See also the section Insert LaTeX cite commands below.
* Insert LaTeX cite commands
The action for inserting a citation command into a LaTeX document prompts for the citation command and, if applicable, for the pre- and postnote arguments. The prompt for the citation command has its own minibuffer history, which means that previous inputs can be accessed by pressing the <up> key for helm-bibtex or M-p for ivy-bibtex. By pressing <down> it is also possible to access the list of all citation commands defined in biblatex (except for multicite commands and volcite et al. which have different argument structures). The prompt also supports auto-completion via the tab key. If no command is entered, the default command is used. The default command is defined in the customization variable bibtex-completion-cite-default-command. By default, helm-bibtex and ivy-bibtex prompt for pre- and postnotes for the citation. This can be switched off by setting the variable bibtex-completion-cite-prompt-for-optional-arguments to nil.