Skip to main content

A Sphinx extension that renders selected figures as sticky margin sidebars while scrolling.

Project description

Sphinx Sticky Margin

sphinx-sticky-margin is a Sphinx extension that adds a sticky margin copy for figures marked with the :class: sticky-margin option.

When the original figure scrolls above the header, a duplicate appears in the right margin (on wide screens). When the original figure comes back into view, the margin copy is hidden.

Installation

pip install sphinx-sticky-margin

Enable Extension

In conf.py:

extensions = [
    "sphinx_sticky_margin",
]

For Jupyter Book (_config.yml):

sphinx:
  extra_extensions:
    - sphinx_sticky_margin

Usage

Add the :class: sticky-margin class to figures that should get a sticky margin clone.

Insert a hide-sticky-margin directive to insert a marker after which to fade out the last sticky figure during scrolling.

The sticky margin figure will appear when the original figure scrolls out of view, and will disappear when the original figure comes back into view.

In case of multiple sticky margin figures, all will be shown in the margin.

If a hide marker scrolls out of view at the top when scrolling down, all sticky figures defined before that marker will be hidden.

When scrolling back up, the sticky margin figures above a hide marker (but after any previous hide marker) will reappear when that hide marker scrolls back below the header.

MyST Example

```{figure} path/to/image.png
:class: sticky-margin

Figure caption.
```

reStructuredText Example

.. figure:: path/to/image.png
   :class: sticky-margin

   Figure caption.

Hide Marker (MyST)

```{hide-sticky-margin}
```

When the marker scrolls above the header, the previous sticky margin figure is hidden with a fade-out.

Notes

  • The sticky margin display is active from 1200px viewport width and up.
  • The extension injects sticky-margin.css and sticky-margin.js.
  • MathJax content inside sticky figures is re-typeset when needed.
  • The extension removes explicit line endings (<br>, double space in markdown) from figure captions to prevent layout issues in the margin.

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

sphinx_sticky_margin-1.1.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_sticky_margin-1.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_sticky_margin-1.1.1.tar.gz.

File metadata

  • Download URL: sphinx_sticky_margin-1.1.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sphinx_sticky_margin-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7134c316dd81731742eac5632c37bbb2cb97f1124d56e6525d85235fd3945bcb
MD5 c90f2393d8008bd288e78e3115062d0b
BLAKE2b-256 d4e264e6032f90992b4d43423985721122fa4854bfe2c40b4e52a3aff867b725

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_sticky_margin-1.1.1.tar.gz:

Publisher: python-publish.yml on TeachBooks/Sphinx-Sticky-Margin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinx_sticky_margin-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_sticky_margin-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e57604d84047082440ef2b4fc56e4d372c2de5b065a9bb9ea68d07f6ae2f2d1
MD5 617a20ea10794d8501617666a4917b03
BLAKE2b-256 c80070c43fe8e762e7ce7a3ca102e9914815288db981b2de71a22daa3cbc15bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_sticky_margin-1.1.1-py3-none-any.whl:

Publisher: python-publish.yml on TeachBooks/Sphinx-Sticky-Margin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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