Skip to content

Latest commit

 

History

History
1635 lines (1218 loc) · 59.4 KB

org-roam.org

File metadata and controls

1635 lines (1218 loc) · 59.4 KB

Org-roam User Manual

This manual is for Org-roam version 2.0.0.

Copyright (C) 2020-2021 Jethro Kuan <jethrokuan95@gmail.com>

You can redistribute this document and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Introduction

Org-roam is a tool for networked thought. It reproduces some of Roam Research’s [fn:roam] key features within Org-mode.

Org-roam allows for effortless non-hierarchical note-taking: with Org-roam, notes flow naturally, making note-taking fun and easy. Org-roam augments the Org-mode syntax, and will work for anyone already using Org-mode for their personal wiki.

Org-roam leverages the mature ecosystem around Org-mode. For example, it has first-class support for org-ref for citation management, and is able to piggyback off Org’s excellent LaTeX and source-block evaluation capabilities.

Org-roam provides these benefits over other tooling:

  • Privacy and Security: Your personal wiki belongs only to you, entirely offline and in your control. Encrypt your notes with GPG.
  • Longevity of Plain Text: Unlike web solutions like Roam Research, the notes are first and foremost plain Org-mode files – Org-roam simply builds an auxiliary database to give the personal wiki superpowers. Having your notes in plain-text is crucial for the longevity of your wiki. Never have to worry about proprietary web solutions being taken down. The notes are still functional even if Org-roam ceases to exist.
  • Free and Open Source: Org-roam is free and open-source, which means that if you feel unhappy with any part of Org-roam, you may choose to extend Org-roam, or open a pull request.
  • Leverage the Org-mode ecosystem: Over the decades, Emacs and Org-mode has developed into a mature system for plain-text organization. Building upon Org-mode already puts Org-roam light-years ahead of many other solutions.
  • Built on Emacs: Emacs is also a fantastic interface for editing text, and Org-roam inherits many of the powerful text-navigation and editing packages available to Emacs.

Target Audience

Org-roam is a tool that will appear unfriendly to anyone unfamiliar with Emacs and Org-mode, but it is also extremely powerful to those willing to put effort inn mastering the intricacies. Org-roam stands on the shoulders of giants. Emacs was first created in 1976, and remains the tool of choice for many for editing text and designing textual interfaces. The malleability of Emacs allowed the creation of Org-mode, an all-purpose plain-text system for maintaining TODO lists, planning projects, and authoring documents. Both of these tools are incredibly vast and require significant time investment to master.

Org-roam assumes only basic familiarity with these tools. It is not difficult to get up and running with basic text-editing functionality, but one will only fully appreciate the power of building Roam functionality into Emacs and Org-mode when the usage of these tools become more advanced.

One key advantage to Org-roam is that building on top of Emacs gives it malleability. This is especially important for note-taking workflows. It is our belief that note-taking workflows are extremely personal, and there is no one tool that’s perfect for you. Org-mode and Org-roam allows you to discover what works for you, and build that perfect tool for yourself.

If you are new to the software, and choose to take this leap of faith, I hope you find yourself equally entranced as Neal Stephenson was.

Emacs outshines all other editing software in approximately the same way that the noonday sun does the stars. It is not just bigger and brighter; it simply makes everything else vanish. – Neal Stephenson, In the Beginning was the Command Line (1998)

A Brief Introduction to the Zettelkasten Method

Org-roam provides utilities for maintaining a digital slip-box. This section aims to provide a brief introduction to the “slip-box”, or “Zettelkasten” method. By providing some background on the method, we hope that the design decisions of Org-roam will become clear, and that will aid in using Org-roam appropriately. In this section we will introduce terms commonly used within the Zettelkasten community and the Org-roam forums.

The Zettelkasten is a personal tool for thinking and writing. It places heavy emphasis on connecting ideas, building up a web of thought. Hence, it is well suited for knowledge workers and intellectual tasks, such as conducting research. The Zettelkasten can act as a research partner, where conversations with it may produce new and surprising lines of thought.

This method is attributed to German sociologist Niklas Luhmann, who using the method had produced volumes of written works. Luhmann’s slip-box was simply a box of cards. These cards are small – often only large enough to fit a single concept. The size limitation encourages ideas to be broken down into individual concepts. These ideas are explicitly linked together. The breakdown of ideas encourages tangential exploration of ideas, increasing the surface for thought. Making linking explicit between notes also encourages one to think about the connections between concepts.

At the corner of each note, Luhmann ascribed each note with an ordered ID, allowing him to link and jump between notes. In Org-roam, we simply use hyperlinks.

Org-roam is the slip-box, digitalized in Org-mode. Every zettel (card) is a plain-text, Org-mode file. In the same way one would maintain a paper slip-box, Org-roam makes it easy to create new zettels, pre-filling boilerplate content using a powerful templating system.

Fleeting notes

A slip-box requires a method for quickly capturing ideas. These are called fleeting notes: they are simple reminders of information or ideas that will need to be processed later on, or trashed. This is typically accomplished using org-capture (see info:org#Capture), or using Org-roam’s daily notes functionality (see Daily-notes). This provides a central inbox for collecting thoughts, to be processed later into permanent notes.

Permanent notes

Permanent notes are further split into two categories: literature notes and concept notes. Literature notes can be brief annotations on a particular source (e.g. book, website or paper), that you’d like to access later on. Concept notes require much more care in authoring: they need to be self-explanatory and detailed. Org-roam’s templating system supports the addition of different templates to facilitate the creation of these notes.

For further reading on the Zettelkasten method, “How to Take Smart Notes” by Sonke Ahrens is a decent guide.

Installation

Org-roam can be installed using Emacs’ package manager or manually from its development repository.

Installing from MELPA

Org-roam is available from Melpa and Melpa-Stable. If you haven’t used Emacs’ package manager before, you may familiarize yourself with it by reading the documentation in the Emacs manual, see info:emacs#Packages. Then, add one of the archives to package-archives:

  • To use Melpa:
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
  • To use Melpa-Stable:
(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "http://stable.melpa.org/packages/") t)

Org-roam also depends on a recent version of Org, which can be obtained in Org’s package repository (see info:org#Installation). To use Org’s ELPA archive:

(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)

Once you have added your preferred archive, you need to update the local package list using:

M-x package-refresh-contents RET

Once you have done that, you can install Org-roam and its dependencies using:

M-x package-install RET org-roam RET

Now see Post-Installation Tasks.

Installing from Apt

Users of Debian 11 or later or Ubuntu 20.10 or later can simply install Org-roam using Apt:

apt-get install elpa-org-roam

Org-roam will then be autoloaded into Emacs.

Installing from Source

You may install Org-roam directly from the repository on GitHub if you like. This will give you access to the latest version hours or days before it appears on MELPA, and months (or more) before it is added to the Debian or Ubuntu repositories. This will also give you access to various developmental branches that may be available.

Note, however, that development version, and especially any feature branches, may not always be in working order. You’ll need to be prepared to do some debugging, or to manually roll-back to working versions, if you install from GitHub.

Installing from GitHub requires that you clone the repository:

git clone https://github.com/org-roam/org-roam.git /path/to/org/roam

where ./path/to/org/roam is the location you will store your copy of the code.

Next, you need to add this location to your load path, and require the Org-roam library. Add the following code to your .emacs:

(add-to-list 'load-path "/path/to/org/roam")
(require 'org-roam)

You now have Org-roam installed. However, you don’t necessarily have the dependencies that it requires. These include:

  • dash
  • f
  • s
  • org
  • emacsql
  • emacsql-sqlite3

You can install this manually as well, or get the latest version from MELPA. You may wish to use use-package, straight.el to help manage this.

If you would like to install the manual for access from Emacs’ built-in Info system, you’ll need to compile the .texi source file, and install it in an appropriate location.

To compile the .texi source file, from a terminal navigate to the /doc subdirectory of the Org-roam repository, and run the following:

make infodir=/path/to/my/info/files install-info

Where /path/to/my/info/files is the location where you keep info files. This target directory needs to be stored in the variable `Info-default-directory-list`. If you aren’t using one of the default info locations, you can configure this with the following in your .emacs file:

(require 'info)
(add-to-list 'Info-default-directory-list
             "/path/to/my/info/files")

You can also use one of the default locations, such as:

  • usr/local/share/info
  • usr/share/info
  • usr/local/share/info

If you do this, you’ll need to make sure you have write-access to that location, or run the above make command as root.

Now that the info file is ready, you need to add it to the corresponding dir file:

install-info /path/to/my/info/files/org-roam.info /path/to/my/info/files/dir

Post-Installation Tasks

Org-roam requires sqlite3 to be locatable by Emacs (i.e. on exec-path). Please ensure that sqlite3 is installed appropriately on your operating system. You can verify that this is the case by executing [fn:2]:

(executable-find "sqlite3")

If you have sqlite3 installed, and executable-find still reports nil, then the path to the executable is not a member of the Emacs variable exec-path. Rectify this by manually adding the path within your Emacs configuration:

(add-to-list 'exec-path "path/to/sqlite3")

Getting Started

The Org-roam Node

We first begin with some terminology we’ll use throughout the manual. We term the basic denomination in Org-roam a node. We define a node as follows:

A node is any headline or top level file with an ID.

For example, with this example file content:

:PROPERTIES:
:ID:       foo
:END:
#+title: Foo

* Bar
:PROPERTIES:
:ID:       bar
:END:

We create two nodes:

  1. A file node “Foo” with id foo.
  2. A headline node “Bar” with id bar.

Headlines without IDs will not be considered Org-roam nodes. Org IDs can be added to files or headlines via the interactive command M-x org-id-get-create.

Links between Nodes

We link between nodes using Org’s standard ID link (e.g. id:foo). While only ID links will be considered during the computation of links between nodes, Org-roam caches all other links in the documents for external use.

Setting up Org-roam

Org-roam’s capabilities stem from its aggressive caching: it crawls all files within org-roam-directory, and maintains a cache of all links and nodes.

To start using Org-roam, pick a location to store the Org-roam files. The directory that will contain your notes is specified by the variable org-roam-directory. Org-roam searches recursively within org-roam-directory for notes. This variable needs to be set before any calls to Org-roam functions.

For this tutorial, create an empty directory, and set org-roam-directory:

(make-directory "~/org-roam")
(setq org-roam-directory (file-truename "~/org-roam"))

The file-truename function is only necessary when you use symbolic links inside org-roam-directory: Org-roam does not resolve symbolic links.

Next, we setup Org-roam to run functions on file changes to maintain cache consistency. This is achieved by running M-x org-roam-setup. To ensure that Org-roam is available on startup, place this in your Emacs configuration:

(require 'org-roam)
(org-roam-setup)

To build the cache manually, run M-x org-roam-db-build-cache. Cache builds may take a while the first time, but subsequent builds are often instantaneous because they only reprocess modified files.

Creating and Linking Nodes

Org-roam makes it easy to create notes and link them together. There are 2 main functions for creating nodes:

  • org-roam-node-insert: creates a node if it does not exist, and inserts a link to the node at point.
  • org-roam-node-find: creates a node if it does not exist, and visits the node.

Let’s first try org-roam-node-find. Calling M-x org-roam-node-find will show a list of titles for nodes that reside in org-roam-directory. It should show nothing right now, since there are no notes in the directory. Enter the title of the note you wish to create, and press RET. This begins the note creation process. This process uses org-capture’s templating system, and can be customized (see The Templating System). Using the default template, pressing C-c C-c finishes the note capture.

Now that we have a node, we can try inserting a link to the node using M-x org-roam-node-insert. This brings up the list of nodes, which should contain the node you just created. Selecting the node will insert an id: link to the node. If you instead entered a title that does not exist, you will once again be brought through the node creation process.

One can also conveniently insert links via the completion-at-point functions Org-roam provides (see Completion).

The Org-roam Buffer

Org-roam provides the Org-roam buffer: an interface to view relationships with other notes (backlinks, reference links, unlinked references etc.). There are two main functions to use here:

  • org-roam-buffer: Launch an Org-roam buffer for the current node at point.
  • org-roam-buffer-toggle: Launch an Org-roam buffer that tracks the node currently at point. This means that the content of the buffer changes as the point is moved, if necessary.

Use org-roam-buffer-toggle when you want wish for the Org-roam buffer to buffer, call M-x org-roam-buffer.

  • Function: org-roam-buffer

    Launch an Org-roam buffer for the current node at point.

To bring up a buffer that tracks the current node at point, call M-x org-roam-buffer-toggle.

  • Function: org-roam-buffer-toggle

    Toggle display of the org-roam-buffer.

Navigating the Org-roam Buffer

The Org-roam buffer uses magit-section, making the typical magit-section keybindings available. Here are several of the more useful ones:

  • M-{N}: magit-section-show-level-{N}-all
  • n: magit-section-forward

-~<TAB>~: magit-section-toggle

  • <RET>: org-roam-visit-thing

org-roam-visit-thing is a placeholder command, that is replaced by section-specific commands such as org-roam-node-visit.

Configuring what is displayed in the buffer

There are currently 3 provided widget types:

Backlinks
View (preview of) nodes that link to this node
Reference Links
Nodes that reference this node (see Refs)
Unlinked references
View nodes that contain text that match the nodes title/alias but are not linked

To configure what sections are displayed in the buffer, set org-roam-mode-sections.

(setq org-roam-mode-sections
      (list #'org-roam-backlinks-section
            #'org-roam-reflinks-section
            ;; #'org-roam-unlinked-references-section
            ))

Note that computing unlinked references may be slow, and has not been added in by default.

Configuring the Org-roam buffer display

Org-roam does not control how the pop-up buffer is displayed: this is left to the user. The author’s recommended configuration is as follows:

(add-to-list 'display-buffer-alist
             '(("\\*org-roam\\*"
                (display-buffer-in-direction)
                (direction . right)
                (window-width . 0.33)
                (window-height . fit-window-to-buffer))))

Crucially, the window is a regular window (not a side-window), and this allows for predictable navigation:

  • RET navigates to thing-at-point in the current window, replacing the Org-roam buffer.
  • C-u RET navigates to thing-at-point in the other window.

Styling the Org-roam buffer

Node Properties

Standard Org properties

Org-roam caches most of the standard Org properties. The full list now includes:

  • outline level
  • todo state
  • priority
  • scheduled
  • deadline
  • tags

Titles and Aliases

Each node has a single title. For file nodes, this is specified with the `#+title` property for the file. For headline nodes, this is the main text.

Nodes can also have multiple aliases. Aliases allow searching for nodes via an alternative name. For example, one may want to assign a well-known acronym (AI) to a node titled “Artificial Intelligence”.

To assign an alias to a node, add the “ROAM_ALIASES” property to the node:

* Artificial Intelligence
:PROPERTIES:
:ROAM_ALIASES: AI
:END:

Alternatively, Org-roam provides some functions to add or remove aliases.

  • Function: org-roam-alias-add alias

    Add ALIAS to the node at point. When called interactively, prompt for the alias to add.

  • Function: org-roam-alias-remove

    Remove an alias from the node at point.

Tags

Tags for top-level (file) nodes are pulled from the variable org-file-tags, which is set by the #+filetags keyword, as well as other tags the file may have inherited. Tags for headline level nodes are regular Org tags.

Note that the #+filetags keyword results in tags being inherited by headers within the file. This makes it impossible for selective tag inheritance: i.e. either tag inheritance is turned off, or all headline nodes will inherit the tags from the file node. This is a design compromise of Org-roam.

Refs

Refs are unique identifiers for nodes. These keys allow references to the key to show up in the Org-roam buffer. For example, a node for a website may use the URL as the ref, and a node for a paper may use an Org-ref citation key.

To add a ref, add to the “ROAM_REFS” property as follows:

* Google
:PROPERTIES:
:ROAM_REFS: https://www.google.com/
:END:

With the above example, if another node links to https://www.google.com/, it will show up as a “reference backlink”.

These keys also come in useful for when taking website notes, using the roam-ref protocol (see Roam Protocol).

You may assign multiple refs to a single node, for example when you want multiple papers in a series to share the same note, or an article has a citation key and a URL at the same time.

Org-roam also provides some functions to add or remove refs.

  • Function: org-roam-ref-add ref

    Add REF to the node at point. When called interactively, prompt for the ref to add.

  • Function: org-roam-ref-remove

    Remove a ref from the node at point.

Completion

Completions for Org-roam are provided via completion-at-point. Org-roam currently provides completions in two scenarios:

  • When within an Org bracket link
  • Anywhere

Completions are installed locally in all Org-roam files. To trigger completions, call M-x completion-at-point. If using company-mode, add company-capf to company-backends.

Completions respect completion-styles: the user is free to choose how candidates are matched. An example of a completion style that has grown in popularity is orderless.

Completing within Link Brackets

Completions within link brackets are provided by org-roam-complete-link-at-point.

The completion candidates are the titles and aliases for all Org-roam nodes. Upon choosing a candidate, a roam:Title link will be inserted, linking to node of choice.

Completing anywhere

The same completions can be triggered anywhere for the symbol at point if not within a bracketed link. This is provided by org-roam-complete-everywhere. Similarly, the completion candidates are the titles and aliases for all Org-roam nodes, and upon choosing a candidate a roam:Title link will be inserted linking to the node of choice.

This is disable by default. To enable it, set org-roam-completion-everywhere to t:

(setq org-roam-completion-everywhere t)
  • Variable: org-roam-completion-everywhere

When non-nil, provide link completion matching outside of Org links.

Encryption

Emacs has support for creating and editing encrypted gpg files, and Org-roam need not provide additional tooling. To create encrypted files, simply add the .gpg extension in your Org-roam capture templates. For example:

(setq org-roam-capture-templates '(("d" "default" plain "%?"
     :if-new (file+head "${slug}.org.gpg"
                        "#+title: ${title}\n")
     :unnarrowed t)))

Org-roam Protocol

Org-roam provides extensions for capturing content from external applications such as the browser, via org-protocol. Org-roam extends org-protocol with 2 protocols: the roam-file and roam-ref protocols.

Installation

To enable Org-roam’s protocol extensions, simply add the following to your init file:

(require 'org-roam-protocol)

We also need to set up org-protocol: the instructions for setting up org-protocol are reproduced below.

We will also need to create a desktop application for emacsclient. The instructions for various platforms are shown below.

For Linux users, create a desktop application in ~~/.local/share/applications/org-protocol.desktop~:

[Desktop Entry]
Name=Org-Protocol
Exec=emacsclient %u
Icon=emacs-icon
Type=Application
Terminal=false
MimeType=x-scheme-handler/org-protocol

Associate org-protocol:// links with the desktop application by running in your shell:

xdg-mime default org-protocol.desktop x-scheme-handler/org-protocol

To disable the “confirm” prompt in Chrome, you can also make Chrome show a checkbox to tick, so that the Org-Protocol Client app will be used without confirmation. To do this, run in a shell:

sudo mkdir -p /etc/opt/chrome/policies/managed/
sudo tee /etc/opt/chrome/policies/managed/external_protocol_dialog.json >/dev/null <<'EOF'
{
  "ExternalProtocolDialogShowAlwaysOpenCheckbox": true
}
EOF
sudo chmod 644 /etc/opt/chrome/policies/managed/external_protocol_dialog.json

and then restart Chrome (for example, by navigating to chrome://restart) to make the new policy take effect.

See here for more info on the /etc/opt/chrome/policies/managed directory and here for information on the ExternalProtocolDialogShowAlwaysOpenCheckbox policy.

For MacOS, we need to create our own application.

  1. Launch Script Editor
  2. Use the following script, paying attention to the path to emacsclient:
on open location this_URL
    set EC to "/usr/local/bin/emacsclient --no-wait "
    set filePath to quoted form of this_URL
    do shell script EC & filePath
    tell application "Emacs" to activate
end open location
  1. Save the script in /Applications/OrgProtocolClient.app, changing the script type to “Application”, rather than “Script”.
  2. Edit /Applications/OrgProtocolClient.app/Contents/Info.plist, adding the following before the last </dict> tag:
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>org-protocol handler</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>org-protocol</string>
    </array>
  </dict>
</array>
  1. Save the file, and run the OrgProtocolClient.app to register the protocol.

To disable the “confirm” prompt in Chrome, you can also make Chrome show a checkbox to tick, so that the OrgProtocol app will be used without confirmation. To do this, run in a shell:

defaults write com.google.Chrome ExternalProtocolDialogShowAlwaysOpenCheckbox -bool true

If you’re using Emacs Mac Port, it registered its `Emacs.app` as the default handler for the URL scheme `org-protocol`. To make OrgProtocol.app the default handler instead, run:

defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{"LSHandlerPreferredVersions" = { "LSHandlerRoleAll" = "-"; }; LSHandlerRoleAll = "org.yourusername.OrgProtocol"; LSHandlerURLScheme = "org-protocol";}'

Then restart your computer.

For Windows, create a temporary org-protocol.reg file:

REGEDIT4

[HKEY_CLASSES_ROOT\org-protocol]
@="URL:Org Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\org-protocol\shell]
[HKEY_CLASSES_ROOT\org-protocol\shell\open]
[HKEY_CLASSES_ROOT\org-protocol\shell\open\command]
@="\"C:\\Windows\\System32\\wsl.exe\" emacsclient \"%1\""

The above will forward the protocol to WSL. If you run Emacs natively on Windows, replace the last line with:

@="\"c:\\path\\to\\emacs\\bin\\emacsclientw.exe\"  \"%1\""

After executing the .reg file, the protocol is registered and you can delete the file.

The roam-file protocol

This is a simple protocol that opens the path specified by the file key (e.g. org-protocol://roam-file?file=/tmp/file.org). This is used in the generated graph.

The roam-ref protocol

This protocol finds or creates a new note with a given roam_key:

images/roam-ref.gif

To use this, create the following bookmarklet in your browser:

javascript:location.href =
    'org-protocol://roam-ref?template=r&ref='
    + encodeURIComponent(location.href)
    + '&title='
    + encodeURIComponent(document.title)
    + '&body='
    + encodeURIComponent(window.getSelection())

or as a keybinding in qutebrowser in , using the config.py file (see Configuring qutebrowser):

config.bind("<Ctrl-r>", "open javascript:location.href='org-protocol://roam-ref?template=r&ref='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)")

where template is the template key for a template in org-roam-capture-ref-templates (see The Templating System). These templates should contain a #+roam_key: ${ref} in it.

The Org-mode Ecosystem

Frequently Asked Questions

The Templating System

Rather than creating blank files on org-roam-insert and org-roam-find-file, it may be desirable to prefill the file with templated content. This may include:

  • Time of creation
  • File it was created from
  • Clipboard content
  • Any other data you may want to input manually

This requires a complex template insertion system. Fortunately, Org ships with a powerful one: org-capture (see info:org#capture). However, org-capture was not designed for such use. Org-roam abuses org-capture, extending its syntax and capabilities. To first understand how org-roam’s templating system works, it may be useful to look into basic usage of org-capture.

For these reasons, Org-roam capture templates are not compatible with regular org-capture. Hence, Org-roam’s templates can be customized by instead modifying the variable org-roam-capture-templates. Just like org-capture-templates, org-roam-capture-templates can contain multiple templates. If org-roam-capture-templates only contains one template, there will be no prompt for template selection.

Template Walkthrough

To demonstrate the additions made to org-capture templates. Here, we walkthrough the default template, reproduced below.

("d" "default" plain (function org-roam--capture-get-point)
     "%?"
     :file-name "%<%Y%m%d%H%M%S>-${slug}"
     :head "#+title: ${title}\n"
     :unnarrowed t)
  1. The template has short key "d". If you have only one template, org-roam automatically chooses this template for you.
  2. The template is given a description of "default".
  3. plain text is inserted. Other options include Org headings via entry.
  4. (function org-roam--capture-get-point) should not be changed.
  5. "%?" is the template inserted on each call to org-roam-capture-. This template means don’t insert any content, but place the cursor here.
  6. :file-name is the file-name template for a new note, if it doesn’t yet exist. This creates a file at path that looks like /path/to/org-roam-directory/20200213032037-foo.org. This template also allows you to specify if you want the note to go into a subdirectory. For example, the template private/${slug} will create notes in /path/to/org-roam-directory/private.
  7. :head contains the initial template to be inserted (once only), at the beginning of the file. Here, the title global attribute is inserted.
  8. :unnarrowed t tells org-capture to show the contents for the whole file, rather than narrowing to just the entry.

Other options you may want to learn about include :immediate-finish.

Org-roam Template Expansion

Org-roam’s template definitions also extend org-capture’s template syntax, to allow prefilling of strings. We have seen a glimpse of this in Template Walkthrough.

In org-roam templates, the ${var} syntax allows for the expansion of variables, stored in org-roam-capture--info. For example, during org-roam-insert, the user is prompted for a title. Upon entering a non-existent title, the title key in org-roam-capture--info is set to the provided title. ${title} is then expanded into the provided title during the org-capture process. Any variables that do not contain strings, are prompted for values using completing-read.

After doing this expansion, the org-capture’s template expansion system is used to fill up the rest of the template. You may read up more on this on org-capture’s documentation page.

To illustrate this dual expansion process, take for example the template string: "%<%Y%m%d%H%M%S>-${title}", with the title "Foo". The template is first expanded into %<%Y%m%d%H%M%S>-Foo. Then org-capture expands %<%Y%m%d%H%M%S> with timestamp: e.g. 20200213032037-Foo.

All of the flexibility afforded by Emacs and Org-mode are available. For example, if you want to encode a UTC timestamp in the filename, you can take advantage of org-mode’s %(EXP) template expansion to call format-time-string directly to provide its third argument to specify UTC.

("d" "default" plain (function org-roam--capture-get-point)
     "%?"
     :file-name "%(format-time-string \"%Y-%m-%d--%H-%M-%SZ--${slug}\" (current-time) t)"
     :head "#+title: ${title}\n"
     :unnarrowed t)

Graphing

Org-roam provides graphing capabilities to explore interconnections between notes. This is done by performing SQL queries and generating images using Graphviz. The graph can also be navigated: see Roam Protocol.

The entry point to graph creation is org-roam-graph.

  • Function: org-roam-graph & optional arg file node-query

    Build and possibly display a graph for FILE from NODE-QUERY. If FILE is nil, default to current buffer’s file name. ARG may be any of the following values:

    • nil show the graph.
    • C-u show the graph for FILE.
    • C-u N show the graph for FILE limiting nodes to N steps.
    • C-u C-u build the graph.
    • C-u - build the graph for FILE.
    • C-u -N build the graph for FILE limiting nodes to N steps.
  • User Option: org-roam-graph-executable

    Path to the graphing executable (in this case, Graphviz). Set this if Org-roam is unable to find the Graphviz executable on your system.

    You may also choose to use neato in place of dot, which generates a more compact graph layout.

  • User Option: org-roam-graph-viewer

    Org-roam defaults to using Firefox (located on PATH) to view the SVG, but you may choose to set it to:

    1. A string, which is a path to the program used
    2. a function accepting a single argument: the graph file path.

    nil uses view-file to view the graph.

    If you are using WSL2 and would like to open the graph in Windows, you can use the second option to set the browser and network file path:

    (setq org-roam-graph-viewer
        (lambda (file)
          (let ((org-roam-graph-viewer "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"))
            (org-roam-graph--open (concat "file://///wsl$/Ubuntu" file)))))
        

Graph Options

Graphviz provides many options for customizing the graph output, and Org-roam supports some of them. See https://graphviz.gitlab.io/_pages/doc/info/attrs.html for customizable options.

  • User Option: org-roam-graph-extra-config

    Extra options passed to graphviz for the digraph (The “G” attributes). Example: '~(("rankdir" . "LR"))

  • User Option: org-roam-graph-node-extra-config

    Extra options for nodes in the graphviz output (The “N” attributes). Example: '(("color" . "skyblue"))

  • User Option: org-roam-graph-edge-extra-config

    Extra options for edges in the graphviz output (The “E” attributes). Example: '(("dir" . "back"))

  • User Option: org-roam-graph-edge-cites-extra-config

    Extra options for citation edges in the graphviz output. Example: '(("color" . "red"))

Excluding Nodes and Edges

One may want to exclude certain files to declutter the graph.

  • User Option: org-roam-graph-exclude-matcher

    Matcher for excluding nodes from the generated graph. Any nodes and links for file paths matching this string is excluded from the graph.

    If value is a string, the string is the only matcher.

    If value is a list, all file paths matching any of the strings are excluded.

(setq org-roam-graph-exclude-matcher '("private" "dailies"))

This setting excludes all files whose path contain “private” or “dailies”.

Minibuffer Completion

Org-roam allows customization of which minibuffer completion system to use for its interactive commands. The default setting uses Emacs’ standard completing-read mechanism.

(setq org-roam-completion-system 'default)

If you have installed Helm or Ivy, and have their modes enabled, under the 'default setting they will be used.

In the rare scenario where you use Ivy globally, but prefer Helm for org-roam commands, set:

(setq org-roam-completion-system 'helm)

Other options include 'ido, and 'ivy.

Daily-notes

Org-roam provides journaling capabilities akin to Org-journal with org-roam-dailies.

Configuration

For org-roam-dailies to work, you need to define two variables:

  • Variable: org-roam-dailies-directory

    Path to daily-notes.

  • Variable: org-roam-dailies-capture-templates

    Capture templates for daily-notes in Org-roam.

Here is a sane default configuration:

(setq org-roam-dailies-directory "daily/")

(setq org-roam-dailies-capture-templates
      '(("d" "default" entry
         #'org-roam-capture--get-point
         "* %?"
         :file-name "daily/%<%Y-%m-%d>"
         :head "#+title: %<%Y-%m-%d>\n\n")))

Make sure that org-roam-dailies-directory appears in :file-name for your notes to be recognized as daily-notes. You can have different templates placing their notes in different directories, but the one in org-roam-dailies-directory will be considered as the main one in commands.

See The Templating System for creating new templates. org-roam-dailies provides an extra :olp option which allows specifying the outline-path to a heading:

(setq org-roam-dailies-capture-templates
      '(("l" "lab" entry
         #'org-roam-capture--get-point
         "* %?"
         :file-name "daily/%<%Y-%m-%d>"
         :head "#+title: %<%Y-%m-%d>\n"
         :olp ("Lab notes"))

        ("j" "journal" entry
         #'org-roam-capture--get-point
         "* %?"
         :file-name "daily/%<%Y-%m-%d>"
         :head "#+title: %<%Y-%m-%d>\n"
         :olp ("Journal"))))

The template l will put its notes under the heading ‘Lab notes’, and the template j will put its notes under the heading ‘Journal’.

Capturing and finding daily-notes

  • Function: org-roam-dailies-capture-today &optional goto

    Create an entry in the daily note for today.

    When goto is non-nil, go to the note without creating an entry.

  • Function: org-roam-dailies-find-today

    Find the daily note for today, creating it if necessary.

There are variants of those commands for -yesterday and -tomorrow:

  • Function: org-roam-dailies-capture-yesterday n &optional goto

    Create an entry in the daily note for yesteday.

    With numeric argument n, use the daily note n days in the past.

  • Function: org-roam-dailies-find-yesterday

    With numeric argument N, use the daily-note N days in the future.

There are also commands which allow you to use Emacs’s calendar to find the date

  • Function: org-roam-dailies-capture-date

    Create an entry in the daily note for a date using the calendar.

    Prefer past dates, unless prefer-future is non-nil.

    With a ‘C-u’ prefix or when goto is non-nil, go the note without creating an entry.

  • Function: org-roam-dailies-find-date

    Find the daily note for a date using the calendar, creating it if necessary.

    Prefer past dates, unless prefer-future is non-nil.

Navigation

You can navigate between daily-notes:

  • Function: org-roam-dailies-find-directory

    Find and open org-roam-dailies-directory.

  • Function: org-roam-dailies-find-previous-note

    When in an daily-note, find the previous one.

  • Function: org-roam-dailies-find-next-note

    When in an daily-note, find the next one.

Diagnosing and Repairing Files

Org-roam provides a utility for diagnosing and repairing problematic files via org-roam-doctor. By default, org-roam-doctor runs the check on the current Org-roam file. To run the check only for all Org-roam files, run C-u M-x org-roam-doctor, but note that this may take some time.

  • Function: org-roam-doctor &optional this-buffer

    Perform a check on Org-roam files to ensure cleanliness. If THIS-BUFFER, run the check only for the current buffer.

The checks run are defined in org-roam-doctor--checkers. By default, there are checkers for broken links and invalid #+roam_* properties.

Each checker is an instance of org-roam-doctor-checker. To define a checker, use make-org-roam-doctor-checker. Here is a sample definition:

(make-org-roam-doctor-checker
    :name 'org-roam-doctor-broken-links
    :description "Fix broken links."
    :actions '(("d" . ("Unlink" . org-roam-doctor--remove-link))
               ("r" . ("Replace link" . org-roam-doctor--replace-link))
               ("R" . ("Replace link (keep label)" . org-roam-doctor--replace-link-keep-label))))

The :name property is the name of the function run. The function takes in the Org parse tree, and returns a list of (point error-message). :description is a short description of what the checker does. :actions is an alist containing elements of the form (char . (prompt . function)). These actions are defined per checker, to perform autofixes for the errors. For each error detected, org-roam-doctor will move the point to the current error, and pop-up a help window displaying the error message, as well as the list of actions that can be taken provided in :actions.

Finding Unlinked References

Unlinked references are occurrences of strings of text that exactly match the title or alias of an existing note in the Org-roam database. Org-roam provides facilities for discovering these unlinked references, so one may decide whether to convert them into links.

To use this feature, simply call M-x org-roam-unlinked-references from within an Org-roam note. Internally, Org-roam uses ripgrep and a clever PCRE regex to find occurrences of the title or aliases of the currently open note in all Org-roam files. Hence, this requires a version of ripgrep that is compiled with PCRE support.

NOTE: Since ripgrep cannot read encrypted files, this function cannot find unlinked references within encrypted files.

Developer’s Guide to Org-roam

Org-roam’s Design Principle

Org-roam is primarily motivated by the need for a dual representation. We (humans) love operating in a plain-text environment. The syntax rules of Org-mode are simple and fit snugly within our brain. This also allows us to use the tools and packages we love to explore and edit our notes. Org-mode is simply the most powerful plain-text format available, with support for images, LaTeX, TODO planning and much more.

But this plain-text format is simply ill-suited for exploration of these notes: plain-text is simply not amenable for answering large-scale, complex queries (e.g. how many tasks do I have that are due by next week?). Interfaces such as Org-agenda slow to a crawl when the number of files becomes unwieldy, which can quickly become the case.

At its core, Org-roam provides a database abstraction layer, providing a dual representation of what’s already available in plain-text. This allows us (humans) to continue working with plain-text, while programs can utilize the database layer to perform complex queries. These capabilities include, but are not limited to:

  • link graph traversal and visualization
  • Instantaneous SQL-like queries on headlines
    • What are my TODOs, scheduled for X, or due by Y?

All of these functionality is powered by this database abstraction layer. Hence, at its core Org-roam’s primary goal is to provide a resilient dual representation that is cheap to maintain, easy to understand, and is as up-to-date as it possibly can. Org-roam also then exposes an API to this database abstraction layer for users who would like to perform programmatic queries on their Org files.

Building Extensions and Advanced Customization of Org-roam

Because Org-roam’s core functionality is small, it is possible and sometimes desirable to build extensions on top of it. These extensions may one or more of the following functionalities:

  • Access to Org-roam’s database
  • Usage/modification of Org-roam’s interactive commands

Org-roam provides no guarantees that extensions will continue to function as Org-roam evolves, but by following these simple rules, extensions can be made robust to local changes in Org-roam.

  1. Extensions should not modify the database schema. Any extension that requires the caching of additional data should make a request upstream to Org-roam.
  2. Extensions requiring access to the database should explicitly state support for the database version (org-roam-db--version), and only conditionally load when support is available.

Accessing the Database

Access to the database is provided singularly by org-roam-db-query, for example:

(org-roam-db-query [:select * :from nodes])

One can refer to the database schema by looking up org-roam-db--table-schemata. There are multiple helper functions within Org-roam that call org-roam-db-query, these are subject to change. To ensure that extensions/customizations are robust to change, extensions should only use org-roam-db-query, and perhaps replicate the SQL query if necessary.

Accessing and Modifying Nodes

The node interface is cleanly defined using cl-defstruct. The primary method to access nodes is org-roam-node-at-point and org-roam-node-read:

  • Function: org-roam-node-at-point &optional assert

    Return the node at point. If ASSERT, throw an error if there is no node at point.

  • Function: org-roam-node-read &optional initial-input filter-fn sort-fn require-match

    Read and return an org-roam-node. INITIAL-INPUT is the initial prompt value. FILTER-FN is a function to filter out nodes. SORT-FN is a function to sort nodes. If REQUIRE-MATCH, require returning a match.

Once you obtain the node, you can use the accessors for the node, e.g. org-roam-node-id or org-roam-node-todo.

It is possible to define (or override existing) properties on nodes. This is simply done using a cl-defmethod on the org-roam-node struct:

(cl-defmethod org-roam-namespace ((node org-roam-node))
  "Return the namespace for NODE.
The namespace is the final directory of the file for the node."
  (file-name-nondirectory
   (directory-file-name
    (file-name-directory (org-roam-node-file node)))))

The snippet above defines a new property namespace on org-roam-node, which making it available for use in capture templates.

Extending the Capture System

Org-roam applies some patching over Org’s capture system to smooth out the user experience, and sometimes it is desirable to use Org-roam’s capturing system instead. The exposed function to be used in extensions is org-roam-capture-:

  • Function: org-roam-capture- &key goto keys node info props templates

    Main entry point. GOTO and KEYS correspond to `org-capture’ arguments. INFO is an alist for filling up Org-roam’s capture templates. NODE is an `org-roam-node’ construct containing information about the node. PROPS is a plist containing additional Org-roam properties for each template. TEMPLATES is a list of org-roam templates.

An example of an extension using org-roam-capture- is org-roam-dailies itself:

(defun org-roam-dailies--capture (time &optional goto)
  "Capture an entry in a daily-note for TIME, creating it if necessary.

When GOTO is non-nil, go the note without creating an entry."
  (org-roam-capture- :goto (when goto '(4))
                     :node (org-roam-node-create)
                     :templates org-roam-dailies-capture-templates
                     :props (list :override-default-time time))
  (when goto (run-hooks 'org-roam-dailies-find-file-hook)))

Performance Optimization

Profiling Key Operations

Garbage Collection

During the cache-build process, Org-roam generates a lot of in-memory data-structures (such as the Org file’s AST), which are discarded after use. These structures are garbage collected at regular intervals (see <a href=”info:elisp#Garbage Collection”>info:elisp#Garbage Collection).

Org-roam provides the option org-roam-db-gc-threshold to temporarily change the threshold value for GC to be triggered during these memory-intensive operations. To reduce the number of garbage collection processes, one may set org-roam-db-gc-threshold to a high value (such as most-positive-fixnum):

(setq org-roam-db-gc-threshold most-positive-fixnum)

_ Copying

Copyright (C) 2020-2021 Jethro Kuan <jethrokuan95@gmail.com>

You can redistribute this document and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Appendix

Note-taking Workflows

Books
Articles
Threads
Videos

Ecosystem

Browsing History with winner-mode

winner-mode is a global minor mode that allows one to undo and redo changes in the window configuration. It is included with GNU Emacs since version 20.

winner-mode can be used as a simple version of browser history for Org-roam. Each click through org-roam links (from both Org files and the backlinks buffer) causes changes in window configuration, which can be undone and redone using winner-mode. To use winner-mode, simply enable it, and bind the appropriate interactive functions:

(winner-mode +1)
(define-key winner-mode-map (kbd "<M-left>") #'winner-undo)
(define-key winner-mode-map (kbd "<M-right>") #'winner-redo)

Versioning Notes

Since Org-roam notes are just plain text, it is trivial to track changes in your notes database using version control systems such as Git. Simply initialize org-roam-directory as a Git repository, and commit your files at regular or appropriate intervals. Magit is a great interface to Git within Emacs.

In addition, it may be useful to observe how a particular note has evolved, by looking at the file history. Git-timemachine allows you to visit historic versions of a tracked Org-roam note.

Full-text search interface with Deft

Deft provides a nice interface for browsing and filtering org-roam notes.

(use-package deft
  :after org
  :bind
  ("C-c n d" . deft)
  :custom
  (deft-recursive t)
  (deft-use-filter-string-for-filename t)
  (deft-default-extension "org")
  (deft-directory "/path/to/org-roam-files/"))

If the title of the Org file is not the first line, you might not get nice titles. You may choose to patch this to use org-roam’s functionality. Here I’m using el-patch:

(use-package el-patch
  :straight (:host github
             :repo "raxod502/el-patch"
             :branch "develop"))

(eval-when-compile
  (require 'el-patch))

The Deft interface can slow down quickly when the number of files get huge. Notdeft is a fork of Deft that uses an external search engine and indexer.

Org-journal

Org-journal provides journaling capabilities to Org-mode. A lot of its functionalities have been incorporated into Org-roam under the name ~org-roam-dailies~. It remains a good tool if you want to isolate your verbose journal entries from the ideas you would write on a scratchpad.

(use-package org-journal
  :bind
  ("C-c n j" . org-journal-new-entry)
  :custom
  (org-journal-date-prefix "#+title: ")
  (org-journal-file-format "%Y-%m-%d.org")
  (org-journal-dir "/path/to/journal/files/")
  (org-journal-date-format "%A, %d %B %Y"))

Note-taking Add-ons

These are some plugins that make note-taking in Org-mode more enjoyable.

Org-download

Org-download lets you screenshot and yank images from the web into your notes:

images/org-download.gif

(use-package org-download
  :after org
  :bind
  (:map org-mode-map
        (("s-Y" . org-download-screenshot)
         ("s-y" . org-download-yank))))

mathpix.el

mathpix.el uses Mathpix’s API to convert clips into latex equations:

images/mathpix.gif

(use-package mathpix.el
  :straight (:host github :repo "jethrokuan/mathpix.el")
  :custom ((mathpix-app-id "app-id")
           (mathpix-app-key "app-key"))
  :bind
  ("C-x m" . mathpix-screenshot))

Org-noter / Interleave

Org-noter and Interleave are both projects that allow synchronised annotation of documents (PDF, EPUB etc.) within Org-mode.

Bibliography

org-roam-bibtex offers tight integration between org-ref, helm-bibtex and org-roam. This helps you manage your bibliographic notes under org-roam.

For example, though helm-bibtex provides the ability to visit notes for bibliographic entries, org-roam-bibtex extends it with the ability to visit the file with the right #+roam_key.

Spaced Repetition

Org-fc is a spaced repetition system that scales well with a large number of files. Other alternatives include org-drill, and pamparam.

To use Anki for spaced repetition, anki-editor allows you to write your cards in Org-mode, and sync your cards to Anki via anki-connect.

FAQ

How do I have more than one Org-roam directory?

Emacs supports directory-local variables, allowing the value of org-roam-directory to be different in different directories. It does this by checking for a file named .dir-locals.el.

To add support for multiple directories, override the org-roam-directory variable using directory-local variables. This is what .dir-locals.el may contain:

((nil . ((org-roam-directory . (expand-file-name "."))
         (org-roam-db-location . (expand-file-name "./org-roam.db")))))

All files within that directory will be treated as their own separate set of Org-roam files. Remember to run org-roam-db-build-cache from a file within that directory, at least once.

How do I migrate from Roam Research?

Fabio has produced a command-line tool that converts markdown files exported from Roam Research into Org-roam compatible markdown. More instructions are provided in the repository.

How do I create a note whose title already matches one of the candidates?

This situation arises when, for example, one would like to create a note titled “bar” when “barricade” already exists.

The solution is dependent on the mini-buffer completion framework in use. Here are the solutions:

Ivy
call ivy-immediate-done, typically bound to C-M-j. Alternatively, set ivy-use-selectable-prompt to t, so that “bar” is now selectable.
Helm
Org-roam should provide a selectable “[?] bar” candidate at the top of the candidate list.

Keystroke Index

Command Index

Function Index

Variable Index

Footnotes

[fn:1] Depending on your completion framework, you may need to press TAB to see the list. [fn:2] Two easy ways to evaluate elisp: 1) Place the cursor after the closing paren and run M-x eval-last-sexp RET or 2) Press C-c C-c with your cursor in an Org file code block (like #+BEGIN_SRC emacs-lisp). [fn:roam] To understand more about Roam, a collection of links are available in Note-taking Workflows.