ml_switcheroo.core.tikz ======================= .. py:module:: ml_switcheroo.core.tikz .. autoapi-nested-parse:: TikZ Concrete Syntax Tree (CST) Data Structures. This package provides a pure Python representation of TikZ/PGF code designed to represent neural network graphs with high fidelity. It supports: - Nodes with HTML-like label tables for layer metadata. - Edges representing data flow. - Trivia preservation (comments/whitespace) for round-trip stability. Submodules ---------- .. toctree:: :maxdepth: 1 /api/ml_switcheroo/core/tikz/analyser/index /api/ml_switcheroo/core/tikz/nodes/index /api/ml_switcheroo/core/tikz/parser/index Classes ------- .. autoapisummary:: ml_switcheroo.core.tikz.TikzBaseNode ml_switcheroo.core.tikz.TriviaNode ml_switcheroo.core.tikz.TikzComment ml_switcheroo.core.tikz.TikzOption ml_switcheroo.core.tikz.TikzTable ml_switcheroo.core.tikz.TikzNode ml_switcheroo.core.tikz.TikzEdge ml_switcheroo.core.tikz.TikzGraph Package Contents ---------------- .. py:class:: TikzBaseNode Bases: :py:obj:`abc.ABC` Abstract base class for all TikZ CST nodes. .. py:method:: to_text() -> str :abstractmethod: Render this node to its string representation. :returns: The TikZ/LaTeX source code for this construct. :rtype: str .. py:class:: TriviaNode Bases: :py:obj:`TikzBaseNode` Represents non-semantic textual elements (whitespace, newlines). .. py:attribute:: content :type: str The raw whitespace content. .. py:method:: to_text() -> str Returns the raw whitespace content. .. py:class:: TikzComment Bases: :py:obj:`TikzBaseNode` Represents a LaTeX comment (e.g. ``% My Comment``). Includes the percent sign in the content or adds it during export. .. py:attribute:: text :type: str The comment text. .. py:attribute:: trailing_newline :type: bool :value: True Whether to append a newline after the comment. .. py:method:: to_text() -> str Formats the comment with a leading percent sign. .. py:class:: TikzOption Bases: :py:obj:`TikzBaseNode` Represents a TikZ option like ``[draw=black]`` or ``[circle]``. .. py:attribute:: key :type: str Option key. .. py:attribute:: value :type: Optional[str] :value: None Optional value for key-value pairs. .. py:method:: to_text() -> str Returns ``key=value`` or just ``key``. .. py:class:: TikzTable Bases: :py:obj:`TikzBaseNode` Represents an HTML-like table structure used inside TikZ Node labels. Uses LaTeX tabular environment syntax. Example:: \begin{tabular}{c} \textbf{LayerName} \\ param: val \end{tabular} .. py:attribute:: rows :type: List[List[str]] :value: [] List of rows, where each row is a list of cell strings. .. py:attribute:: align :type: str :value: 'c' Column alignment (c=center, l=left, r=right). .. py:method:: to_text() -> str Renders the tabular environment string. .. py:class:: TikzNode Bases: :py:obj:`TikzBaseNode` Represents a ``\node`` command. Structure:: \node [options] (id) at (x, y) {label_content}; .. py:attribute:: node_id :type: str Unique identifier for the node (used for edges). .. py:attribute:: x :type: float X Coordinate. .. py:attribute:: y :type: float Y Coordinate. .. py:attribute:: content :type: Union[str, TikzTable] Inner content (Text or Table). .. py:attribute:: options :type: List[TikzOption] :value: [] List of TikZ options. .. py:attribute:: leading_trivia :type: List[TriviaNode] :value: [] Whitespace/Comments before the node command. .. py:method:: to_text() -> str Constructs the full node command string. .. py:class:: TikzEdge Bases: :py:obj:`TikzBaseNode` Represents a ``\draw`` command connecting two nodes. Structure:: \draw [options] (src) -- (tgt); .. py:attribute:: source_id :type: str Source node ID. .. py:attribute:: target_id :type: str Target node ID. .. py:attribute:: options :type: List[TikzOption] :value: [] List of styling options. .. py:attribute:: connector :type: str :value: '--' Connector style (e.g. ``--`` or ``->``). .. py:attribute:: leading_trivia :type: List[TriviaNode] :value: [] Whitespace before the draw command. .. py:method:: to_text() -> str Constructs the draw command string. .. py:class:: TikzGraph Bases: :py:obj:`TikzBaseNode` The root container representing the ``tikzpicture`` environment. Structure:: \begin{tikzpicture} ... children ... \end{tikzpicture} .. py:attribute:: children :type: List[TikzBaseNode] :value: [] List of nodes, edges, comments, and trivia. .. py:attribute:: options :type: List[TikzOption] :value: [] Global environment options. .. py:method:: to_text() -> str Constructs the complete environment string.