Skip to content

Instantly share code, notes, and snippets.

@avonmoll
Last active April 3, 2024 18:30
Show Gist options
  • Save avonmoll/e435f0e478fbdc6c1eee7557b221a7e2 to your computer and use it in GitHub Desktop.
Save avonmoll/e435f0e478fbdc6c1eee7557b221a7e2 to your computer and use it in GitHub Desktop.
A Guide on How to Use papis Sensibly

Installation

Easiest, if you have pip:

$ pip install papis

Adding Documents

Most of the time I add documents via their DOI. For example, I'll be on IEEExplore or ResearchGate and see a paper that I either want to read or know for sure I'll want to cite. So I simply copy the DOI and run

$ papis add --from doi PASTEDOIHERE

Some references may not have a DOI (like books and papers on arXiv). However, the metadata is almost always available in BiBTeX form (particularly when searcing in Google Scholar, and arXiv has an Export Citation link). In these cases, I copy the BiBTeX data into a new file (usually to ~/Downloads since this folder gets cleaned out and the file created in this step is useless once imported into papis). Then I run

$ papis add --from bibtex NEWREFERENCE.bib

Configuration

See the files config and header, below. These live in ~/.config/papis and they control the global behavior of papis. To modify these settings for a particular project or folder, you can create a file called .papis.config in said folder and override your global settings and/or set different ones. One of the biggest reasons I end up doing this is because the ieeeconf.cls template pretty much requires pdfLatex (whereas I normally use XeLaTeX). So all of the unicode characters in my databases (e.g. for accents in peoples' names) need to be converted to their LaTeX escape sequences. Fortunately, papis can do this, you just have to tell it to. Below is an example .papis.config file to achieve the desired result.

[settings]
bibtex-unicode = False

The header file simply controls how each document appears in the search list when running something like papis open or papis edit.

Organization

As shown in the config file, I have a single library called papers which lives in a directory called ~/papers. Every single document I cite (and many that I've just simply read) are in this single library. I cite a lot of the same references in many different papers. So there is a many-to-many relationship between references and projects. In order to associate a reference with a project I make use of the project YAML field which is a list.

Example

I am writing a new paper on pterodactyl migration patterns. I want to cite a paper by Dr. Alan Grant entitled Social Structure of Pterodactyls. So, I'll update the reference in papis by running papis edit grant. The grant part is the query. If the query returns more than one result, I'll have to select the correct paper using the picker. Then I'll edit the YAML file by adding

project:
- pterodactyl-migration

If I've already cited this paper, I can simply append - pterodactyl-migration to the list of projects.

Exporting to BiBTeX

In continuing the previous example, I'm now working on the manuscript and I need to generate a BiBTeX file for the pterodactyl migration project. So I run the following:

$ papis export --all --format bibtex project:pterodactyl-migration > bibliography.bib

So now I have a file called bibliography.bib in my current directory which has all of the references I've associated with the pterodactyl-migration project. I may need to add references to this project later on, in which case I would need to re-run the above command. To make this process easier, I put the command in a script and call it, e.g., updatebib. Make sure to run chmod +x updatebib afterwards so it will be executable. Then, whenever I need my bibliography.bib file to be freshened, just run ./updatebib.

General Research

When I'm actively writing, I often times am also re-reading some portions of papers that are particularly relevant. For example, I want to find a specific detail in Dr. Grant's paper, so I simply run papis open grant and select the reference of interest and it will open in a PDF reader.

# vim: set ft=ini
[settings]
# Open file with rifle, a nice python program
opentool = rifle
# Use nvim as a graphical editor
editor = nvim
# Use ranger as a file browser, too a nice python package
file-browser = ranger
# Ask for confirmation when doing papis add ...
add-confirm = True
# Edit the info.yaml file before adding a doc into the library
# papis add --edit
add-edit = True
# Open the files before adding a document into the library
# papis add --open
add-open = True
default-query-string = title:*
# Change the cite key format (papis "ref")
ref-format = {doc[author_list][0][family]}{doc[year]}
# Default folder name for newly added documents
add-folder-name = {doc[author_list][0][family]} - {doc[title]}
# Default file name
add-file-name = {doc[author_list][0][family]} - {doc[title]}
# Default web search provider
search-engine = "https://google.com"
header-format-file = ~/.config/papis/header
match-format = {doc[project]}{doc[title]}{doc[author]}{doc[year]}
extra-bibtex-keys = ["extra", "abstract"]
extra-bibtex-types = ["thesis"]
bibtex-unicode = True
database-backend = whoosh
whoosh-schema-fields = ['author', 'year', 'project', 'title']
[papers]
dir = ~/papers
<ansiwhite>{doc.html_escape[title]}</ansiwhite>
<ansigreen> {doc.html_escape[author]}</ansigreen>
<ansimagenta> ({doc[year]}) </ansimagenta><ansiyellow>{doc[project]}</ansiyellow>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment