Skip to content

Zensical and MkDocs

A docs site: every feynman block in your Markdown becomes a diagram.

  1. Load the script. Add feynjs to the page scripts, in the [project] table:

    [project]
    extra_javascript = ["https://cdn.jsdelivr.net/npm/feynjs@0.10/dist/feynjs.min.js"]
    
    extra_javascript:
      - https://cdn.jsdelivr.net/npm/feynjs@0.10/dist/feynjs.min.js
    
  2. Add the fence. It keeps a feynman block as written. Without it, the highlighter turns the block into plain text and feynjs can't find it. If you already list custom_fences (for Mermaid, say), add the line to that list.

    [project.markdown_extensions]
    pymdownx.superfences.custom_fences = [
      { name = "feynman", class = "feynman", format = "pymdownx.superfences.fence_div_format" },
      { name = "feynjs", class = "feynman", format = "pymdownx.superfences.fence_div_format" },
    ]
    
    markdown_extensions:
      - pymdownx.superfences:
          custom_fences:
            - name: feynman
              class: feynman
              format: !!python/name:pymdownx.superfences.fence_div_format
            - name: feynjs
              class: feynman
              format: !!python/name:pymdownx.superfences.fence_div_format
    
  3. Write a diagram in any page, in a feynman code block:

    ```feynman
    i1 [q] -- a -- i2 [qbar]
    a -- [Z'] b
    f1 [chi] -- b -- f2 [chibar]
    ```
    

feynjs draws the blocks once a page has loaded, and again after each instant page change.

Demo

This block, in a page of this site:

```feynman
i1 [q] -- a -- i2 [qbar]
a -- [Z'] b
f1 [chi] -- b -- f2 [chibar]
```

draws this diagram:

i1 [q] -- a -- i2 [qbar] a -- [Z'] b f1 [chi] -- b -- f2 [chibar]

Diagrams draw in currentColor, so they follow the light and dark palettes without being drawn again. A block can hold a process instead of edges:

```feynman
p p > gluino gluino
gluino > q q neutralino2
neutralino2 > Z neutralino1
```
p p > gluino gluino gluino > q q neutralino2 neutralino2 > Z neutralino1

Without the CDN

Download feynjs.min.js once, from the latest release or from the npm package:

curl -L -o feynjs.min.js https://github.com/hepjs/feynjs/releases/latest/download/feynjs.min.js
# or: npm install feynjs, then copy node_modules/feynjs/dist/feynjs.min.js

It is one file of about 350 KB, with no dependencies, so it works with no network: behind a firewall, offline, or on a site that loads nothing from other servers. To update, download it again.

Put it in docs/javascripts/ and list it in place of the CDN link (the path is relative to docs/):

[project]
extra_javascript = ["javascripts/feynjs.min.js"]
extra_javascript:
  - javascripts/feynjs.min.js

The site then carries its own copy, built and published with it.

Optional extras

Your own options. To pass options to every diagram (a download button, say), call run yourself from a small script listed after feynjs; feynjs leaves what you have drawn alone:

document$.subscribe(() => feynjs.run({ download: true }));

run takes every option in the JavaScript API.

Next