export#

Export utilities for rendering planar diagrams to PDF.

This module provides two helpers:

  • export_pdf: render one or many diagrams, one per page.

  • export_pdf_groups: render groups of diagrams in grids, one grid per page.

Both functions rely on knotpy.drawing.draw.draw for rendering and add light error handling so that problematic diagrams still produce a page with a visible error marker.

Functions

export_pdf(diagrams, filename[, rotation, ...])

Render planar diagram(s) to a multi-page PDF (one diagram per page).

export_pdf_groups(groups, filename[, ...])

Render groups of diagrams in grids; one grid per PDF page.

export_pdf(diagrams, filename, rotation=0.0, arc_color='tab:blue', arc_width=4.0, arc_style='solid', arc_alpha=None, arc_stroke_color='white', arc_stroke_width=None, arc_stroke_alpha=None, gap=0.1, cmap=None, vertex_color='black', vertex_size=0.15, vertex_alpha=None, vertex_stroke_color='black', vertex_stroke_width=0, vertex_stroke_alpha=None, arrow_color=None, arrow_width=0.15, arrow_length=0.12, arrow_style='open', arrow_cap_style='round', arrow_position='middle', arrow_alpha=None, label_endpoints=False, label_arcs=False, label_nodes=False, label_color='black', label_font_size=14, label_font_family='serif', label_horizontal_alignment='left', label_vertical_alignment='top', label_alpha=None, title=(False,), title_color='black', title_font_size=(16,), title_font_family='serif', title_alpha=None, show_circle_packing=False, padding_fraction=0.05, show_axis=False, show_progress=True, ignore_errors=False)#

Render planar diagram(s) to a multi-page PDF (one diagram per page).

If any diagram cannot be drawn (e.g., contains unsupported features), a placeholder page with an “X” and a brief error message is written instead.

Parameters:
  • diagrams – A PlanarDiagram or an iterable of PlanarDiagram objects.

  • filename (str) – Output PDF path.

  • draw_circles – If True, also draws auxiliary packing circles (debugging).

  • with_labels – If True, draw node/endpoint/arc labels.

  • with_title – If True, add a title: uses k.name if present, otherwise uses the diagram’s KnotPy notation.

  • show_progress – If True and 10+ diagrams, shows a progress bar.

Returns:

None

Return type:

None

export_pdf_groups(groups, filename, draw_circles=False, with_labels=False, with_title=False, show_progress=True)#

Render groups of diagrams in grids; one grid per PDF page.

Each item in groups is a sequence (list/tuple/set) of diagrams. For each group, a near-square grid (rows × cols) is chosen and the diagrams are drawn into that grid on a single page.

Parameters:
  • groups – Iterable of diagram groups, where each group is an iterable of PlanarDiagram objects.

  • filename (str) – Output PDF path.

  • draw_circles (bool) – If True, also draws auxiliary packing circles (debugging).

  • with_labels (bool) – If True, draw node/endpoint/arc labels.

  • with_title (bool) – If True, add per-diagram titles as in export_pdf.

  • show_progress (bool) – If True and total diagrams across all groups ≥ 10, show a progress bar.

Returns:

None

Raises:

TypeError – If groups is not a sequence of sequences.

Return type:

None