Skip to main content

JupyterLab extension for running LaTeX

Project description

JupyterLab LaTeX

binder-badge ci-badge npm-version-badge pypi-version-badge PyPI - Downloads Version Conda Downloads

A JupyterLab extension for live-editing of LaTeX documents.

Usage

To use, right-click on an open .tex document within JupyterLab, and select Show LaTeX Preview: preview This will compile the .tex file and open the rendered PDF document. Subsequent saves of the file will automatically update the PDF. If the PDF fails to compile (possibly due to a syntax error), an error panel will open detailing the LaTeX error.

For more advanced usage documentation, see here.

Requirements

  • JupyterLab >= 4.0
    • older versions are supported in previous releases available on PyPI and npm, check releases
  • Python >= 3.8
  • An application that can compile .tex files to PDF (e.g., pdflatex, xelatex; use pdflatex.exe on Windows with MiKTeX). This application must be available as a command in the same environment as the notebook server.
  • An application that can process .bib files for producing bibliographies. As with the LaTeX command, this must be available in the same environment as the notebook server.

Installation

This extension includes both a notebook server extension (which interfaces with the LaTeX compiler) and a lab extension (which provides the UI for the LaTeX preview). The Python package named jupyterlab-latex provides both of them as a prebuilt extension.

To install the extension, run the following in your terminal:

  • For pip
    pip install jupyterlab-latex
    
  • For conda
    conda install conda-forge::jupyterlab-latex
    

Check installation

To ensure that extension is properly installed, you could check server and lab extensions:

jupyter server extension list

and see the block like this in the output

jupyterlab_latex enabled
    - Validating jupyterlab_latex...
Package jupyterlab_latex took 0.0010s to import
      jupyterlab_latex 4.1.3 OK

then

jupyter labextension list

and see the block like this in the output

@jupyterlab/latex v4.1.3 enabled OK (python, jupyterlab-latex)

Customization

The extension defaults to running xelatex on the server. This command may be customized (e.g., to use pdflatex instead) by customizing your jupyter_notebook_config.py file:

c.LatexConfig.latex_command = 'pdflatex'

The extension defaults to running bibtex for generating a bibliography if a .bib file is found. You can also configure the bibliography command by setting

c.LatexConfig.bib_command = '<custom_bib_command>'

To render references (\ref{...}), such as equation or chapter numbers, you would need to compile in multiple passes by setting

c.LatexConfig.run_times = 2

Security and customizing shell escapes

LaTeX files have the ability to run arbitrary code by triggering external shell commands. This is a security risk, and so most LaTeX distributions restrict the commands that you can run in the shell.

You can customize the behavior by setting the LatexConfig.shell_escape value. It can take three values: "restricted" (default) to allow only commands considered safe to be executed, "allow" to allow all commands, and "disallow" to disallow all commands. For example, to force your LaTeX distribution to run any command, use:

c.LatexConfig.shell_escape = "allow"

Contributing

If you would like to contribute to the project, please read our contributor documentation.

JupyterLab follows the official Jupyter Code of Conduct.

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.

To simplify the development setup, you can use the following Conda environment:

conda create -n jupyterlab-latex-env -c conda-forge python=3.10 jupyterlab=4.0.0 hatchling=1.17.0 nodejs=18
conda activate jupyterlab-latex-env
# Clone the repo to your local environment
git clone https://github.com/jupyterlab/jupyterlab-latex.git
# Change directory to the jupyterlab-latex directory
cd jupyterlab-latex
# Install package in development mode
pip install -e .

# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jupyterlab_latex
# 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).

Changes

For information on the changes with different versions of the jupyterlab-latex library, see our changelog.

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_latex-4.1.4.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

jupyterlab_latex-4.1.4-py3-none-any.whl (374.1 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab_latex-4.1.4.tar.gz.

File metadata

  • Download URL: jupyterlab_latex-4.1.4.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for jupyterlab_latex-4.1.4.tar.gz
Algorithm Hash digest
SHA256 e592e33fa8e3ec97b979fc58ac8728d938410dc6c50ed03cc1c9da1508f4147c
MD5 817008742ba69c6ea8297aeab9926c1a
BLAKE2b-256 c248b51a42e2184621235d21b5bc60c41c887006baa5b9fac5f339f9e0565699

See more details on using hashes here.

File details

Details for the file jupyterlab_latex-4.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterlab_latex-4.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 543d202124000ce1c561a330f7dd386b8f42218144a85fb1ea5d2cbd83fcfda2
MD5 c5a29565c912a666834d89c30114c0e1
BLAKE2b-256 c3c061652e455d650a6e67f1ed0513461e6ce3cadfbc31a0765faf538cce2a7d

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