Skip to main content

Citation Manager for JupyterLab with Zotero integration

Project description

jupyterlab-citation-manager

Github Actions Status CodeQL Binder PyPI version

Status: Work In Progress. Not ready for production environments, may contains bugs. Feedback on any aspect of this extension is welcome.

Citation Manager for JupyterLab:

  • enables adding citations to Jupyter notebooks in Markdown cells,
  • keeps the bibliography in sync with the citations in the document,
  • supports thousands of citation styles,
  • offers a way to efficiently search through your collection of references,
  • integrates with the Zotero® service (Connector for Zotero) by default,
  • is modular in design, allowing for integration of other reference managers in the future.

The data of each reference (a.k.a. citable item) is stored in the notebook metadata, while a mapping between citation ID and the citable items is stored in the cell metadata.

  • storing full data of each citable item in the notebook enables:
    • collaboration between multiple users with separate Zotero collections,
    • retaining the data for citation which got removed from private collection.
  • storing mapping between citation and citable items in the cell metadata allows to copy cells between notebooks.

Usage

Authenticate with Zotero

To enable you to access your reference list you will need to obtain an access API key from your Zotero account. The most basic, read-only key is sufficient (and recommended). The key will be stored in your settings, so you will only need to enter it once.

Insert citation

Insert citation by clicking on the insert citation button in the toolbar of your notebook (add citation icon) or pressing Alt + C (hint: shortcut are customizable in Advanced Settings Editor). Start typing to filter references by title, authors or year.

animation of inserting citations

Insert bibliography

Insert bibliography by clicking on the (add bibliography icon) or pressing Alt + B.

animation of inserting bibliography

Change style

To change the citation style go to the sidebar (sidebar icon) and click on (change style icon) or press Alt + S. Only a subset of generic styles will be shown initially; start typing a name to find more specialised styles.

animation of changing style

Synchronise references

To synchronise your collection of references go to the sidebar (sidebar icon) and click on (refresh collection icon) or press Alt + U. Updating can take a few seconds; a progress bar will appear on the status bar to keep you updated (if you have it enabled).

Explore your collection

To get the details on references in your collections without leaving JupyterLab open the sidebar (sidebar icon), and start typing to find item of interest. You will be able to preview the abstract, check metadata and even open the article inside JupyterLab (or in a new browser tab - depending on your preference).

References with citations in the current document will be show on top when opening the explorer and enable a quick preview of citation context and navigation to the relevant place in the document (by clicking on the citation context).

Auto-migrate existing citations

When opening a notebook, the extension will automatically detect citations in the following formats:

  • cite2c, e.g. <cite data-cite="itemID"></cite> with associated notebook-level metadata,
  • DOI-links, e.g. [(Krassowski et al, 2021)](https://doi.org/10.3389/fcell.2021.626821) (the parentheses in the link label are used as an indicator distinguishing citations from non-citation DOI links)

and ask for your permission to migrate them to Citation Manager format. Only citations inside of markdown cells will be detected.

The migrated citations are stored separately from the citations from other providers (such as Zotero), unless an exact match for given ID, DOI, URL or title and list of authors is found among items available from reference providers (like Zotero), in which case the item from the provider is used.

animation of migrating from cite2c and from DOIs

Exporting to LaTeX

Citation Manager supports LaTeX as one of the output formats. For now the citations are embedded as plain-text, while the bibliography uses semantic thebibliography LaTeX environment. To configure notebook to export citations to LaTeX:

  1. Go to Advanced Settings Editor -> Citation Manager and change the default outputFormat to latex.
  2. Insert bibliography in a cell, but instead of using Markdown cell, use Raw cell
  3. Open Property Inspector sidebar and change Raw NBConvert Format to LaTeX (you need to have the Raw cell selected for the dropdown to appear)
  4. From File menu select Save and Export Notebook As… and choose LaTeX
  5. Compile the resulting .tex to desired output such as PDF with preferred tool (e.g. pdflatex on Linux)

LaTeX setup overview

Requirements

  • JupyterLab >= 3.2
  • Modern browser (with ES 2019 support, e.g. Firefox 64+, or Chrome 73+)
  • Zotero account

Install

To install the extension, execute:

pip install jupyterlab-citation-manager

Uninstall

To remove the extension, execute:

pip uninstall jupyterlab-citation-manager

Advanced Usage

Citation clusters

This extension enables creation of citation clusters, this is a group of citations that are rendered together, following the chosen citation style. You can create a citation cluster manually by editing cell metadata.

Support for creation and edition of citation cluster from the graphical interface is planned.

Citation styles

This extension includes thousands citation styles form the official repository of Citation Language Styles (CSL) project.

If you want to add a custom citation style, you can do so by placing a .csl file in csl-styles folder in one of the data locations as returned by:

jupyter --paths

The .csl file should follow CSL v1.0.1 specification (see official CSL specification).

Example

If jupyter --paths looks like:

config:
    /home/your_name/.jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /home/your_name/.local/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /home/your_name/.local/share/jupyter/runtime

and you want to add your modified version of APA style, you would put my-custom-apa.csl in /home/your_name/.local/share/jupyter/csl-styles (you will need to create this folder), so that the final structure looks similar to:

/home/your_name/.local/share/jupyter
├── csl-styles
│   └── my-custom-apa.csl
├── nbsignatures.db
├── notebook_secret
└── runtime

Contributing

Development install

Note: You will need NodeJS to build the extension package.

The jlpm command is JupyterLab's pinned version of yarn that is installed with JupyterLab. You may use yarn or npm in lieu of jlpm below.

# Clone the repo to your local environment
# Change directory to the jupyterlab-citation-manager directory
# Fetch build requirements
jlpm run bootstrap
# Install package in development mode
pip install -e .
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the jlpm run build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

jupyter lab build --minimize=False

Development uninstall

pip uninstall jupyterlab-citation-manager

In development mode, you will also need to remove the symlink created by jupyter labextension develop command. To find its location, you can run jupyter labextension list to figure out where the labextensions folder is located. Then you can remove the symlink named jupyterlab-citation-manager within that folder.

Updating citation styles

The citation styles are retrieved from the CSL repository using git submodules and reside in the jupyterlab-citation-data repository.

You can update the submodule to fetch the most recent citation styles:

# fetch the latest styles from the currently tracked CSL version branch
git submodule update csl-styles
# store the information about the most recent commit in version control
git commit csl-styles

To update the version branch:

# replace v1.0.1 with the version to track
git submodule set-branch --branch v1.0.1 csl-styles
git commit csl-styles

Legal notes

Connector for Zotero

Zotero is a registered trademark of the Corporation for Digital Scholarship; our extension (Connector for Zotero) is not affiliated with the Corporation in any way.

CSL styles

The CSL styles are contributed by individual authors to the CSL project; all the styles distributed with this extension come from the Citation Language Styles and are released under the Creative Commons Attribution-ShareAlike 3.0 Unported license.

Icons

Please see the style/icons/README.md for information on the creators and licences of icons included in the distribution.

citeproc-js

jupyterlab-citation-manager uses citeproc-js to format citations and bibliography text; citeproc-js is dual-licenced under CPAL 1.0 (or newer) or AGPLv3 (or newer); in order to allow for the distribution of this extension with other works the CPAL 1.0 licence was adopted for re-distribution of cireproc-js together with this extension. The Exhibit A of citeproc-js CPAL 1.0 licence is presented below for informational purposes:

EXHIBIT A. Common Public Attribution License Version 1.0. “The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://opensource.org/licenses/CPAL-1.0. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. Software distributed under the License is distributed on an “AS IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is citeproc-js. The Original Developer is not the Initial Developer and is __________. If left blank, the Original Developer is the Initial Developer. The Initial Developer of the Original Code is Frank Bennett. All portions of the code written by Frank Bennett are Copyright (c) 2009-2015. All Rights Reserved. Contributor ______________________. Alternatively, the contents of this file may be used under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE (the AGPLv3 License), in which case the provisions of AGPLv3 License are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the AGPLv3 License and not to allow others to use your version of this file under the CPAL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the AGPLv3 License. If you do not delete the provisions above, a recipient may use your version of this file under either the CPAL or the AGPLv3 License.”

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlab-citation-manager-0.2.0.tar.gz (2.9 MB view details)

Uploaded Source

Built Distribution

jupyterlab_citation_manager-0.2.0-py3-none-any.whl (318.8 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab-citation-manager-0.2.0.tar.gz.

File metadata

  • Download URL: jupyterlab-citation-manager-0.2.0.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for jupyterlab-citation-manager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9a6df09cc3fcc3e2f00f17aaa3f790ac98406cfb9ba147cc3f685da91cc5704f
MD5 7214e7c5f806165f0f49237a35ec438c
BLAKE2b-256 8a3866b81292ecffe695a97a8d58fa2698deddff7317610c8a8518fc999ddb2f

See more details on using hashes here.

File details

Details for the file jupyterlab_citation_manager-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jupyterlab_citation_manager-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 318.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for jupyterlab_citation_manager-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d9b713486dab8f00bb22367b7e2f843019733d83b35a4e6ea5a0dacc8e0868f
MD5 8a28fa304a200084bfb3f83bb648cf58
BLAKE2b-256 f1159146ca495fdd7186a34d3106fcef33e52216ab95d87ad90d8eb5d379a341

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page