Installation
From a checkout of this repository, install MarkFeyn into your documentation project by passing the checkout path to uv. Choose the extra for your engine.
Omit the extra if the engine is already installed.
Install Material for MkDocs when using the Material theme:
For local development from this repository:
MkDocs
Enable the plugin in mkdocs.yml:
ProperDocs
Enable the same plugin in properdocs.yml:
The plugin adds this generated site asset automatically:
For ProperDocs with theme: material, do not add search explicitly; Material's search plugin is MkDocs-only.
To use a different output path:
script_path is interpreted relative to the generated site directory. Parent-directory traversal such as ../feynman.js is rejected.
By default the plugin loads the renderer lazily: it injects a tiny loader script (feynman-diagrams-loader.js, written next to script_path) and the full renderer is only downloaded on pages that contain a feynman block. Set lazy_load: false to load the renderer on every page instead:
Manual JavaScript Mode
If a project does not want to load a plugin, copy the renderer. Manual mode loads the full renderer directly on every page:
(Source checkouts can also copy src/markfeyn/assets/feynman-diagrams.js directly.)
Then configure MkDocs or ProperDocs:
Python-Markdown and other HTML renderers
Any HTML page can render a feynman fence if its Markdown engine emits
<pre><code class="language-feynman">…</code></pre> and the page loads the
MarkFeyn bundle. Python-Markdown's fenced_code extension does this by default.
Save this as build.py and run python build.py. Open the generated
index.html alongside the copied bundle.
If your application inserts Markdown-generated HTML after page load, call
renderAll on the container after updating it. Load the bundle before this
code runs and pass HTML from a trusted source or your application's sanitizer.
If a syntax highlighter takes over unknown code languages, configure it to
preserve language-feynman on the code or pre element and leave the
diagram source intact.
Export a standalone SVG
For a source checkout, run npm ci and npm run build:js before installing
MarkFeyn. Put Node.js 22 or newer on PATH. The export command
uses the renderer and MathJax bundled in the Python package, so it runs
offline without a browser or an npm install.
Save one diagram's source in diagram.feynman without the Markdown fences.
Use - as the input path to read stdin. SVG goes to stdout unless you pass
-o. Invalid diagram source or math labels produce a diagnostic on stderr
and a nonzero exit status. Embed the resulting file in Markdown as
.
SVGs have a white background by default. Use --background transparent
to show the page or slide behind the diagram.