stormvogel.to_tikz¶
Generate TikZ/LaTeX source code for stormvogel models.
Attributes¶
Functions¶
|
Convert a probability to a LaTeX math string (fraction or decimal). |
|
Convert a plain string name to a LaTeX math label. |
|
Strip characters that are invalid in TikZ node names. |
|
Return the least-crowded TikZ initial-arrow placement direction. |
|
Generate a TikZ |
Module Contents¶
- stormvogel.to_tikz._LETTER_NUM_RE¶
- stormvogel.to_tikz._prob_to_latex(p) str¶
Convert a probability to a LaTeX math string (fraction or decimal).
Handles SymPy symbolic expressions (parametric models) via SymPy’s LaTeX printer when the
sympypackage is available.
- stormvogel.to_tikz._name_to_math_label(name: str) str¶
Convert a plain string name to a LaTeX math label.
"s0"→$s_0$,"state12"→$\text{state}_{12}$,"sink"→$\text{sink}$,"q"→$q$.
- stormvogel.to_tikz._safe_name(s: str) str¶
Strip characters that are invalid in TikZ node names.
- stormvogel.to_tikz._initial_where(init_pos: tuple, all_pos: list[tuple], allowed: tuple[str, ...] = ('above', 'below', 'left')) str¶
Return the least-crowded TikZ initial-arrow placement direction.
Picks from allowed (default: above/below/left, i.e. north/south/west) by choosing the direction most opposite to the average displacement from the initial state to all other states.
- stormvogel.to_tikz.model_to_tikz(model: stormvogel.model.Model, output_file: str | None = None, positions: dict | None = None, coord_scale: float = 2.5, rankdir: str = 'LR', self_loop_bend: int = 30, target_labels: list[str] | None = None, center: bool = True, layout_size: tuple[float, float] | None = None, ranksep: float | None = None, nodesep: float | None = None, badge_labels: list[str] | None = None) str¶
Generate a TikZ
tikzpicturefor model and return it as a string.Required in the LaTeX preamble:
\usepackage{tikz} \usetikzlibrary{automata,arrows.meta,calc} \tikzset{state/.append style={minimum size=1.2cm, circle, draw}}
The generated code uses absolute
at (x, y)coordinates derived from the Graphvizdotlayout, so no relative-positioning library is needed. Label positions default tomidway, above; adjust per-edge for publication-quality output.- Parameters:
model – The model to render.
output_file – If given, write the TikZ snippet to this path.
positions – Optional
dictmappingStateto(x, y)in inches (same format assuggest_positions()). Auto-computed via Graphvizdotwhen omitted.coord_scale – Multiply Graphviz inch coordinates by this factor to get centimetres in TikZ (default 2.5).
rankdir – Graphviz layout direction used when positions are omitted (default
"LR").self_loop_bend – Bend angle in degrees applied to edges from a self-loop action node back to its source state (default 30).
target_labels – List of state label strings (as used in
has_label()) that mark accepting/target states. Any state carrying one of these labels is rendered with the TikZacceptingstyle (double circle).center – If
True(default), wrap thetikzpicturein a\begin{center}...\end{center}block. Set toFalsewhen embedding the figure inside a minipage or other environment.badge_labels – Model label strings that should be rendered as small annotation badges outside the state circle. For each state carrying one of these labels a tiny labelled node is placed at successive compass positions (
north east,north west, …).layout_size – Optional
(width_cm, height_cm)pair passed to Graphviz as a bounding-box constraint. Ignored when positions are provided explicitly.ranksep – Graphviz
ranksep— minimum distance between ranks.nodesep – Graphviz
nodesep— minimum distance between nodes in the same rank.