Metadata-Version: 2.5
Name: sphinx-eu-ai-label
Version: 1.0.0
Summary: Sphinx extension for adding the European Commission's AI-generated content labels to documentation
Project-URL: Homepage, https://github.com/doismellburning/sphinx-eu-ai-label
Project-URL: Documentation, https://doismellburning.github.io/sphinx-eu-ai-label/
Project-URL: Source, https://github.com/doismellburning/sphinx-eu-ai-label
Project-URL: Issues, https://github.com/doismellburning/sphinx-eu-ai-label/issues
Author: Kristian Glass
License-Expression: MIT
License-File: LICENSE
Keywords: ai,ai-act,documentation,eu,label,sphinx,sphinx-extension,transparency
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Sphinx
Classifier: Framework :: Sphinx :: Extension
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Documentation
Classifier: Topic :: Documentation :: Sphinx
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: sphinx>=8
Description-Content-Type: text/markdown

# sphinx-eu-ai-label

A [Sphinx](https://www.sphinx-doc.org/) extension for adding the European Commission's
[icons for labelling AI-generated content](https://digital-strategy.ec.europa.eu/en/policies/eu-icons-labelling-ai-generated-content)
to your documentation.

See it in action at <https://doismellburning.github.io/sphinx-eu-ai-label/>.

> [!IMPORTANT]
> This is an unofficial project. It is not affiliated with or endorsed by the European
> Commission or the AI Office. Using these icons does not make you compliant with
> Article 50 of the EU AI Act. You are still responsible for meeting its disclosure
> requirements. Using the icons also does not signal that you have signed the
> Code of Practice on marking and labelling of AI-generated content.

## The icons

The Commission publishes three icons:

| Kind | Use it when | The icon says |
| --- | --- | --- |
| `basic` | AI was involved in creating the content, or you want to write your own label text | "AI" |
| `generated` | The content was fully generated by AI, with no human-created elements or editorial control apart from prompting | "AI GENERATED" |
| `modified` | Existing human-made content was partially modified with AI | "AI MODIFIED" |

Each icon comes in four colour variants: `black`, `white`, `black-50` and `white-50`
(the last two are 50% transparent). The white variants are for dark backgrounds.

Because the icons carry their own wording, labels show the icon on its own unless you
add text.

## Installation

Install it from [PyPI](https://pypi.org/project/sphinx-eu-ai-label/):

```console
pip install sphinx-eu-ai-label
```

It needs Python 3.10 or later and Sphinx 8 or later.

Then add it to your `conf.py`:

```python
extensions = [
    # ...
    "sphinx_eu_ai_label",
]
```

## Usage

### Directive

Use the directive to put a block-level label at the top of a page or section.
With no argument it uses the `basic` icon.

```rst
.. ai-label:: generated
```

For the `basic` icon, the text goes before the icon, so this reads "Summary generated
with [AI]". For the other icons, the text goes after the icon.

```rst
.. ai-label:: basic
   :text: Summary generated with
   :variant: white
   :align: right
```

The text can contain inline markup, such as a link to a page about how you use AI:

```rst
.. ai-label:: basic
   :text: Summary generated with `help <ai-policy.html>`_ from
```

MyST Markdown:

````markdown
```{ai-label} modified
:text: Illustrations modified with AI
```
````

| Option | Values | Default |
| --- | --- | --- |
| *(argument)* | `basic`, `generated`, `modified` | `basic` |
| `:text:` | Text to show next to the icon. It can contain inline markup, such as a link to your AI policy. Pass an empty value to show the icon on its own, even if `eu_ai_label_texts` sets text | `eu_ai_label_texts`, or none |
| `:variant:` | `auto`, `black`, `white`, `black-50`, `white-50` | `eu_ai_label_variant` |
| `:align:` | `left`, `center`, `right` | `left` |
| `:class:` | Extra CSS classes | |
| `:name:` | A name to cross-reference the label with, using `:ref:` with explicit text, e.g. ``:ref:`the summary label <summary-label>` `` | |

### Role

Use the role to put a label inline:

```rst
This paragraph was :ai-label:`generated`.
```

Add a variant after the kind, and put text before it in angle brackets, as with links:

```rst
This summary was :ai-label:`generated white`.

:ai-label:`Paragraph written with <basic>`

:ai-label:`Illustrations modified with AI <modified black-50>`
```

Text goes in the same place as with the directive, but it can't contain markup.
Without text, the role uses `eu_ai_label_texts`, and without a variant it uses
`eu_ai_label_variant`.

In MyST Markdown, use `` {ai-label}`Paragraph written with <basic>` ``.

### Page labels

To label a whole page, set `ai-label` in the page's metadata. The label goes at the top
of the page, under its title. The value is a kind, optionally followed by a variant, as
with the role.

```rst
:ai-label: generated

My page
=======
```

In MyST Markdown, use front matter:

```markdown
---
ai-label: modified white
---

# My page
```

To label every page, set `eu_ai_label_page`. A page can still set its own label, or opt
out with `:ai-label: none`.

```python
eu_ai_label_page = "generated"
```

Page labels use the text from `eu_ai_label_texts`, if any. For other text, or to put a
label somewhere else on the page, use the directive.

## Configuration

These values go in `conf.py`:

| Setting | Default | Description |
| --- | --- | --- |
| `eu_ai_label_variant` | `"auto"` | Default colour variant. `auto` uses `black` in light mode and `white` in dark mode, using `prefers-color-scheme` |
| `eu_ai_label_size` | `"2.5em"` | Icon height for directive labels, as any CSS length. The icons have wide margins built in, so the visible mark is smaller than this |
| `eu_ai_label_inline_size` | `"1.75em"` | Icon height for role labels. It's smaller so that labels in running text don't stretch the line as much |
| `eu_ai_label_texts` | `{}` | Text to show next to each kind's icon, for example `{"generated": "Généré par IA"}` |
| `eu_ai_label_page` | `None` | A label for every page, such as `"generated"` or `"modified white"`. See [Page labels](#page-labels) |
| `eu_ai_label_latex_size` | `"2.5em"` | Icon height for directive labels in LaTeX output, as a LaTeX length |
| `eu_ai_label_latex_inline_size` | `"1.75em"` | Icon height for role labels in LaTeX output, as a LaTeX length |

`auto` follows the reader's operating system or browser setting. It also follows a
theme's own light/dark switch if the theme sets a `data-theme="light"` or
`data-theme="dark"` attribute on `<html>` or `<body>`, as Furo, PyData and Book do. For
other themes with a switch, set a fixed variant.

The extension also adds a small stylesheet, `_static/eu_ai_label/eu_ai_label.css`.
Labels have the CSS classes `eu-ai-label`, `eu-ai-label-{kind}`, and either
`eu-ai-label-block` with `eu-ai-label-align-{align}`, or `eu-ai-label-inline`.

## Other output formats

The icons appear in HTML output (including EPUB) and LaTeX/PDF output. LaTeX uses the
`black` variant for `auto`, since print has no dark mode, and ignores `:class:`.

Other builders, such as man and plain text, show the label as text instead: the label
text if you set any, including its markup (with "AI" after it for `basic`), otherwise
what the icon says.

## Translation

Text from the directive's `:text:` option is included in the gettext catalogues, so you
can translate it like any other text, markup included. Text from `eu_ai_label_texts`
isn't, because you can set that per language in `conf.py`. The alt text always says
what the icon says, so it isn't translated either.

## Accessibility

The Commission's guidance encourages accessible labels. The extension follows it in
these ways:

- Each icon's alt text is what the icon says: "AI", "AI-generated" or "AI-modified".
  This does not change when you add text, so `basic` with "Summary generated with"
  reads as "Summary generated with AI".
- Any label text is real HTML text, so screen readers can read it and it scales with
  the reader's font size.
- The icon heights are in `em` by default, so they scale with the text too.

## Placement

The Commission's guidance says a label should be visible no later than the moment a
reader first sees the content. It should also not be covered by other page elements.
In practice, put the directive at the top of the page or section it applies to, or use
[page labels](#page-labels). For the full placement specifications, see Section 2 of the
[Code of Practice](https://digital-strategy.ec.europa.eu/en/policies/code-practice-ai-generated-content).

## Licence

This project's code is under the MIT licence. See [`LICENSE`](https://github.com/doismellburning/sphinx-eu-ai-label/blob/main/LICENSE).
The icons are published by the European Commission, which says they are "made publicly
available for everyone to use freely, without the need for attribution". This package
includes the SVG files unmodified, apart from their file names, and PDF conversions of
them for LaTeX output.

## Development

```console
make bootstrap  # Install dependencies with uv
make            # check, then test
make check      # Format check, lint and type check
make test       # Tests, with a 100% coverage requirement
make fix        # Auto-format and apply lint fixes
make docs       # Build the showcase site into docs/_build/html
make icons      # Regenerate the PDF icons for LaTeX from the SVGs
```

### Releasing

The version comes from git tags, so there's nothing to bump. To release,
[create a GitHub Release](https://github.com/doismellburning/sphinx-eu-ai-label/releases/new)
with a new tag on `main` named `v` followed by the version (e.g. `v0.2.0`).
Pushing the tag runs the publish workflow, which builds the package and uploads it to PyPI.
