sft_wick.drawing_tikz — TikZ/PGF Diagram Backend¶
TikZ/PGF rendering for FeynmanDiagram objects.
This backend produces LaTeX source — a tikzpicture environment —
that you can drop straight into a paper with \input{fig.tex}.
It uses no external Python dependencies (pure string templates) and
shares the layout, label, and style abstractions with the
matplotlib backend in sft_wick.drawing.
Required LaTeX packages on the user’s side¶
The generated code uses standard TikZ features:
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
For a self-contained PDF (standalone=True) the document also
needs the standalone document class, which is part of any TeX
Live / MiKTeX install.
Quick start¶
from sft_wick import TikzRenderer, publication_style
renderer = TikzRenderer(style=publication_style())
tikz_code = renderer.to_string(fd)
renderer.save(fd, "fig/diag1.tex")
renderer.save(
fd, "fig/diag1_standalone.tex",
standalone=True, # produce a complete document
)
External-vertex labels follow the same override hierarchy as the
matplotlib backend (per-call dict > callable > default formatter);
see sft_wick.render_labels.
Limitations (v1)¶
rcparamsis ignored — TikZ output uses LaTeX-side typography.bboxon labels is ignored — TikZ labels render without a box by default; users can post-process by editing the generatedevery label/.style.No
pdflatexinvocation: the user runs LaTeX themselves.
- class sft_wick.drawing_tikz.TikzRenderer(style=None, external_label_fn=None, vertex_label_fn=None, label_format=None, scale=1.0, standalone=False)[source]¶
Bases:
objectRender a
FeynmanDiagramas a tikzpicture LaTeX string.- Parameters:
style (RenderStyle | None) – A
RenderStyle. Defaults todefault_style().external_label_fn (LabelCallable | None) – Optional callable
fn(node_id, node_attrs) -> str | Nonefor systematic external-label overrides.vertex_label_fn (LabelCallable | None) – Same shape, for interaction vertices.
label_format (str | None) – Default external-label format flag (overrides
style.label_formatwhen supplied).scale (float) – TikZ
scale=…factor — multiplies every position.standalone (bool) – When
True,to_string()andsave()wrap the figure in a complete\documentclass{standalone}document instead of a baretikzpictureenvironment.
- to_string(diagram, external_labels=None, vertex_labels=None, positions=None, standalone=None)[source]¶
Build the TikZ source for a single diagram.
- Parameters:
diagram (FeynmanDiagram) – The diagram to render.
external_labels (Mapping[str, str] | None) – Optional
{node_id: label}overrides.vertex_labels (Mapping[str, str] | None) – Same, for interaction vertices.
positions (Mapping[str, tuple[float, float]] | None) – Optional
{node_id: (x, y)}pin map.standalone (bool | None) – If given, override the constructor’s
standaloneflag for this call only.
- Returns:
A LaTeX source string. Always ends with a trailing newline.
- Return type:
- save(diagram, path, external_labels=None, vertex_labels=None, positions=None, standalone=None)[source]¶
Write the TikZ source to disk and return the path.
Creates parent directories as needed.
- save_all(diagrams, path_pattern, external_labels=None, vertex_labels=None, positions=None, standalone=None)[source]¶
Save many diagrams using a
str.format-style pattern.Example:
path_pattern="fig/order2_diag_{i:02d}.tex"writesfig/order2_diag_00.tex,fig/order2_diag_01.tex, …Per-diagram overrides are keyed by subplot index.
- Parameters:
- Return type: