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.0.tar.gz (13.4 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.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sphinx_sticky_margin-1.1.0.tar.gz
  • Upload date:
  • Size: 13.4 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.0.tar.gz
Algorithm Hash digest
SHA256 d0199dbbf90142c695b51df37f26303bbf2d61a44ec200e9264711128a5d9da5
MD5 3ead5c813758bbef976ee9666b5e1227
BLAKE2b-256 1e3e885f970a07153d209896982d754fbbb0d463f2d981bcd55f0a6953a2fae5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_sticky_margin-1.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_sticky_margin-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e4c648d64791668e5f9a7146bcf9def069dcf5cf785434ad9a1aa8a8e6c9823
MD5 eb73201febfb8395d3d3d1bd3f568e9f
BLAKE2b-256 6c42b0ca7a11b9aa08a9ae67d71acfd189d7ad08bdb002f6627a80a4157ee347

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_sticky_margin-1.1.0-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