Citations in org-mode: Org-cite and Citar
Table of Contents
org-cite
and citation management should remain relevant and insightful. Readers should be aware that some package-specific information in this article may be outdated. Thus, readers are advised from outright copying code in this article without verifying (e.g. reading docstrings) the intended behavior. Nevertheless, the concepts related to Summary
First, I’ll outline the broadest components to producing files in org-mode
with a citation system (e.g. org-cite
, org-ref
). Then I’ll introduce org-cite
and the differences between its bibtex
, csl
, and basic
export processors. Then, I will walk through my configuration for org-cite
and citar
(formerly bibtex-actions
). You can see a gist/snippet of all the code present in this post here (alongside other additions of mine).
My goal is to plot the landscape, preparing you to understand other available sources which are more suited for a user already familiar with the landscape.
Helpful sources
I recommend the following reading for more information regarding how org-cite
works:
- Citation handling (The Org Manual)
- The first source you should visit should almost always be the manual (available within Emacs via
info
, i.e. M-x info). It covers the fundamentals to understanding how to useorg-cite
. Isn’t well documented currently, but that will change in the future. - Org-cite guide by tecosaur
- I’ll be referencing this frequently, for good reason.
What are citation systems?
There are roughly three moving parts to citation management.
- The tool that produces the bibliography file.
A bibliography file is where information regarding sources are stored. This almost always comes in the form of a .bib file; usually one is sufficient. There are various ways to create these files. Though you can manually create your own.bib
files, the most common way is exporting a Zotero library (see Zotero). - The text processor.
This is the software the user (you) directly writes in. In our case, it’s Emacs! - The “layer” from text to product.
This is the code that lies in between your plain text writing and an output file (e.g. PDF). Sometimes this is identical to the text processor—in our case it isn’t. For instance, Microsoft Word is both a text editor and the producer of an output file, such as a PDF or a.docx
.
org-cite
lies closer to (3) because it is responsible for exporting citations, whereas citar
is closer to (2) because it is an interface for inserting citations into the buffer. A software like Zotero is responsible for (1).
Org-cite
In around July of 2021, org-cite
was publicly released. org-cite
a library packaged with org-mode
that processes org
citations (e.g. [cite:@wittgensteinTractatusLogicoPhilosophicus2021]
). To those not familiar with another citation workflow (e.g. biblatex
in LaTeX), it is quite daunting to leap into citations in Emacs. This was certainly the case for me: I leapt into org-mode
citation integration with Zotero and LaTeX with no experience in org
, Zotero, or LaTeX! Nonetheless, org-cite
is quite simple once laid out. After reading this post or section, I recommend taking a look at tecosaur’s fabulous guide to using org-cite
. His explanation of the citation styles of org-cite and their variants is particularly useful.
Understanding org-cite export processors
The most crucial concept to org-cite
are “export processors.” Take a look at the following passage from the documentation for org-cite-export-processors (as it is at the time of writing):
When non-nil, the value is an association list between export back-ends and
citation export processors:
(BACK-END . PROCESSOR)
where BACK-END is the name of an export back-end or t, and PROCESSOR is a
triplet following the pattern
(NAME BIBLIOGRAPHY-STYLE CITATION-STYLE)
There, NAME is the name of a registered citation processor providing export
functionality, as a symbol. BIBLIOGRAPHY-STYLE (respectively CITATION-STYLE)
is the desired default style to use when printing a bibliography (respectively
exporting a citation), as a string or nil. Both BIBLIOGRAPHY-STYLE and
CITATION-STYLE are optional. NAME is mandatory.
What this suggests is that different combinations of “processors,” “bibliography styles,” and “citation styles” can be configured to work with different org-export
backends. Presently, there are three processors available: basic
, csl
, natbib
, and bibtex
. Though org-cite
citations will always follow the same format, the output text that is exported will change depending on the processor used. I will go over these differences now, focusing primarily on the bibtex
and csl
backends1.
The bibtex
processor can only be used with the latex
backend. Using this processor exports citations using the BibLaTex LaTeX package. That means that [cite:@bradleyAppearanceRealityMetaphysical2011 82–5;]
will export into a LaTeX command like \cite[82–5]{bradleyAppearanceRealityMetaphysical2011}. Compiling the org
exported LaTeX file will in turn produce a PDF whose citations are handled by biblatex
. The end citation style will be determined by the provided package options (e.g. style=mla-new
). Read the biblatex documentation for more information (namely, section 3.1.1 in the February 2, 2022 version of the manual).
The natbib
processor unsurprisingly uses the natbib
LaTeX package. biblatex
is slowly growing to replace the older natbib
package, though some users may circumstantially be limited to natbib
—you can read more about the differences between natbib
and biblatex
here. I have not personally used the natbib
, but I suspect its usage is similar if not identical to the bibtex
processor.
The csl
processor will use CSL to export citations. Citation Style Language (CSL) is a language used to instruct the formatting of citations and bibliographies; citation styles are provided by .csl
files. Most importantly, CSL is intended to be a universal standard for citation formatting. Accordingly, .csl
supports essentially every output format.
In sum:
Which processor should I use?
The most common confusion comes from realizing that CSL can also export to LaTeX. So, when exporting to LaTeX: should you use the csl
or bibtex/natbib
processor? The difference lies in whether or not you want to rely on the biblatex
package to manage exports.
The important difference is that csl
exports to rendered text. Rendered text is text whose end formatting will match that of org
’s, e.g. italic text in org-mode
will become wrapped in, say, \emph{} in LaTeX. So, for instance, if I export [cite:@bradleyAppearanceRealityMetaphysical2011 82–5;]
into a LaTeX file using the csl
processor using a CSL file for the Modern Language Association (MLA) citation style, I will see the following in-text citation in the LaTeX file as: (Bradley 82–85)
—if anything needed to be bold, italicized, etc., then that would be wrapped in the appropriate LaTeX command. Contrast that with the LaTeX command in the paragraphs above.
So when it comes to exporting to LaTeX, when wouldn’t rendered text be enough? If you want the most basic functionality, i.e. “Seeing in-text citations and bibliographies in my documents is enough,” then CSL will always cover you. However, if you want access to the more complex or nuanced facilities of biblatex
, use the bibtex
processor instead. biblatex
use cases include (i) using obscure or uncommon field and entry types and (ii) wanting “automation” in the citation variant. By (ii) I mean that biblatex
handles the variant whereas you must manually list the variant in the org-cite
citation when using CSL (see the above link to tecosaur’s guide).
I will give an example. Basic MLA in-text citations following a (AUTHOR PAGE)
format. However, closely following MLA means that subsequent in-text citations from the same source should have a (PAGE)
format. Using the csl
processor, without specifying a style or variant in the org-cite
citation, will always output the former formatting as rendered text; as r/bdarcus explains in his comment, CSL focuses on higher-level commands in order to be agnostic of output format. On the other hand, org-cite
will, by default, leverage the \autocite command (see org-cite-biblatex-styles). This tells biblatex
to change the variant when appropriate. This is an immensely powerful upside to using the bibtex
processor—though it is minor in this particular case, this demonstrates the advantages of the biblatex
package. You can read more about the differences between CSL and biblatex
in this thorough StackExchange explanation. Of course, however, biblatex
is only available when exporting to LaTeX, whereas CSL can be used to export into any format (e.g. HTML, Markdown, ODT, plain-text).
In sum, use the bibtex
processor when you are exporting to LaTeX and only LaTeX and
- want automatic selection of citation variants
- or have rare field or entry types in your
.bib
file.
Otherwise, use the csl
processor2 (assuming you have a .csl
file for your desired citation style).
Finally, it should be noted that the csl
and bibtex
processors use different locators in citations. As explained in tecosaur’s guide, the csl
processor uses locators like bk.
and vol.
, so citations may look like [cite/noauthor:See@mollisonNietzscheContraStoicism2018 pp. 28–9;@priestWhyItIrrational2001 pp. 14;]
—CSL processes these locators. On the other hand, a citation key’s suffix is directly passed as an option to BibLaTeX commands, so an equivalent to the above would be [cite/noauthor:See@mollisonNietzscheContraStoicism2018 28–9;@priestWhyItIrrational2001 14;]
, which doesn’t have CSL locators.
Configuration
Luckily, the difficulty in org-cite
is only conceptually: configuring it is incredibly straightforward. There are two main variables that affect functionality. The first is crucial, and the second is useful to be aware of:
- org-cite-global-bibliography
- org-cite-export-processors
org-cite-global-bibliography is the bare minimum to getting org-cite ready to work. This should be a list of bibliography file (.bib) paths. I have mine set to a list whose single element is a file that Zotero exports:
|
|
Alternatively, you can use the org-mode #+BIBLIOGRAPHY: keyword to set this value per-file; it’s value should be a file path.
org-cite-export-processors is useful as a means to tweak how you’d like org-cite to export citations. You can also set a file-local value using the #+CITE_EXPORT
file keyword (e.g. #+CITE_EXPORT: csl chicago-author-date.csl
); see this section in tecosaur’s guide for an example of how to set the processor, bibliography style, and citation style with this keyword. For a given backend3, you can choose how org-cite exports it. For instance, here is mine:
|
|
As you can see, I have CSL be the default in every case aside from LaTeX. The styles can either be a file path or a file name in org-cite-csl-styles-dir—see Zotero for how to easily acquire CSL files.4 (I use LaTeX strictly for my academic papers, so I really enjoy biblatex
’s features.)
I also choose to customize faces—I prefer the green faces that org-ref
uses:5
|
|
Usage
Using org-cite
is incredibly simple:
- org-cite-insert to insert citations in
org
files, and - #+PRINT_BIBLIOGRAPHY: within a document to mark where the bibliography/references/works cited should be.6
Citar
Using org-cite
is really simple. But many users will find the interface… too bare. Citar is, roughly, the foremost attempt to provide a pleasing frontend to org-cite
. It adds the citar citation-insert processor. The following is the minimum to start using citar
:
|
|
You can then set keybinds for common citar
commands. For example, in the :general use-package keyword:7
|
|
If you use embark
and org-roam
you can also set these variables:
|
|
Capturing (Outdated)
org-roam
and citar
. The If you use org-roam
, then the following is how you select bibliographic source and create an org-roam
node from it. All credit goes to Jethro Kuan, the creator of org-roam, though I’ve made a few of my own customizations:8
|
|
I add it to an accessible keybinding:9
|
|
Advising citar-org-update-pre-suffix (Outdated)
A useful command is citar-org-update-pre-suffix. This command sets the prefix and suffix of a citation key (a single citation can have multiple keys). This is notable since a citation’s suffix is where you provide a locator (e.g. a page number). The command is bound to M-p when the point is on a citation key.
Before advising citar-org-update-pre-suffix, I first advise org-cite-insert such that citar-org-update-pre-suffix is run immediately after inserting a citation:
|
|
A limitation with this code is that this only calls citar-org-update-pre-suffix on the last citation key, which is fine when only one key is inserted at once, and not when multiple are inserted. (Though, citar-org-update-pre-suffix can still be called manually on the other citation keys afterward.)
Additionally, I override citar-org-update-pre-suffix with my own version which adds the following functionality:
|
|
One can also add this command to citar-citation-map
.11
Aesthetics
Finally, we can change the way the citar interface appears. The most relevant variables are citar-templates and citar-symbols. Below is my configuration for these variables. Notably, my definition for citar-symbols utilizes all-the-icons icons to fancify the candidates (all-the-icons must be installed in order to have the faces below available):
|
|
Here’s the end-result:
Other interesting packages
Zotero
Zotero isn’t an Emacs package, but it is crucial to most users' workflow, so it deserves attention. Zotero makes gathering, storing, and exporting bibliographic data infinitely easier. For instance, an ISBN or DOI of a source is all that is necessary for an entry’s fields to be populated. There are two things to note about my setup:
- I install the BetterBibLaTex add-on (see its features in the official documentation page. Its main benefits include unique citation key generation and exporting facilities),
- and export my library using the BetterBibLaTeX format. I also tick the “Keep Updated” option; this continually updates the
.bib
file as I make changes to my library. I then point org-cite-global-bibliography and citar-bibliography to this file.
Additionally, for over a year now, I’ve been using Zotero’s own PDF viewer and annotator. Until recently, this feature had only been available in Zotero Beta, but it is now merged onto the main branch. Though it isn’t powerful, it gets the job done for me, and the convenience is what sells it.
Finally, a very handy tip is to use the CSL files that Zotero already provides (credit to this section of tecosaur’s guide). The CSL files (which provide citation styles) are located in ZOTERO_DIR/styles/
. You can set org-cite-csl-styles-dir to this path:
|
|
Embark
Embark provides menus (essentially keymaps) based on “context,” that is, the type of thing the point is on. As a result, embark
has immense potential. Citar
is built to exploit embark
without requiring it—for instance, see citar-citation-map
.
Org-roam-bibtex
Org-roam-bibtex integrates org-roam with citation systems, such as org-cite
. This packages allows org-roam
to recognize particular nodes as bibliographic (i.e. associated with a particular .bib
entry).
Additionally, as as citar
’s author, u/bdarcus, shares here, there is work being done on citar
’s end to more tightly integrate org-roam
with citar
, in the form of citar-org-roam
.
Citar-capf
Citar-capf provides a complation-at-point-function12 for citations. However, if you’re reading this in the future, there’s a likely chance that this commit would have been merged. The commit merges citar-capf
with citar
.
Org-ref
Org-ref has historically been the dominant citation system for org-mode
. I elect to use org-cite
instead because (i) it comes with org-mode
, meaning there is one less conceptual- and configuration-layer to navigate, (ii) Moreover, org-ref
uses a format that follows org
conventions less closely, and (iii) I have read that is arguably more robust and future-proof. Nevertheless, some users still prefer it.
Changelog
- Better clarity in Advising citar-org-update-pre-suffix (Outdated).
- Mention the merging of
citar-capf
intocitar
(see Citar-capf). - Added Embark.
- Mention
citar-org-roam
in Org-roam-bibtex. - Made comments clarifying kb/bib-files.
- Add screenshot that showcases visually improved
citar
interface (see Aesthetics).
- Added Helpful sources.
- Change processor explanations to include the
natbib
processor. - Change processor explanations to recognize the difference between plain-text and rendered text.
- Noted that some package-specific information in this article may be outdated.
- Noted update to citar-org-update-pre-suffix
- Mentioned
citar-org-roam
as preferable to any desired integration betweenorg-roam
andcitar
.
- Mentioned
- Updated GitLab Gist.
The
basic
processor provides bare functionality and should never be preferred over the alternative, if possible. ↩︎See Configuration. ↩︎
This is an
org-export
backend. This means that, for instance, md refers to theorg-export
md backend as well as any other derived backends. Read the documentation for org-export-define-derived-backend. ↩︎Notice that a citation style is required for the
csl
processor, and not for thebibtex
processor. ↩︎Be aware that I use use-package’s :custom-face keyword to redefine these two faces. One can just as easily use the built-in defface of set-face-attribute. ↩︎
Also see this section of tecosaur’s guide. ↩︎
You can also just use the built-in define-key. ↩︎
This assumes that you have
org-roam-bibtex
installed and enabled. See Org-roam-bibtex. ↩︎kb/note-keys is my own general.el leader key. I’ve mapped its prefix to C-c n. ↩︎
I prefer directly inserting curly quotes, em-dashes, and en-dashes into my buffers. I enable
typo-mode
here so that typing page ranges properly inserts en-dashes. ↩︎Also see Vertico, Marginalia, All-the-icons-completion, and Orderless. ↩︎
Writing papers in org-mode series
- Citations in org-mode: Org-cite and Citar this post!