Skip to main content

Convert diagrams.net/draw.io diagrams to TikZ via SVG.

Project description

drawio2tikz

drawio2tikz is a thin wrapper around svg2tikz that converts draw.io diagrams to TikZ code for embedding in LaTeX documents.

Features

  • Converts either a single draw.io page or all pages
  • Preserves label colors, bold text, font sizes, and simple line breaks
  • Ignores draw.io font family names, allowing output to use the host LaTeX document font
  • Removes draw.io SVG CSS that svg2tikz cannot parse, including light-dark(...) from draw.io's dark mode color scheme
  • Restores draw.io labels emitted as SVG foreignObject elements, which draw.io exports as HTML fragments

Requirements

  • Python 3.14 or newer
  • drawio CLI available on PATH (install from diagrams.net or via Homebrew: brew install --cask drawio)

Installation

Homebrew (macOS)

brew install drawio2tikz

pip / uv

Install from PyPI:

uv tool install drawio2tikz

Or with pip:

pip install drawio2tikz

Development Setup

Clone the repository and install in development mode:

git clone https://github.com/daikiokayama/drawio2tikz.git
cd drawio2tikz
uv sync
uv run drawio2tikz --help

Usage

Basic Usage

Convert a single page from a draw.io file to TikZ:

drawio2tikz path/to/figure.drawio -o output_dir

This generates figure.tikz in the output directory.

Convert All Pages

To convert all pages in a multi-page .drawio file:

drawio2tikz path/to/multipage.drawio --all-pages -o output_dir

Each page is saved as figure_page{N}.tikz.

Keep Intermediate SVG

To debug or inspect the intermediate SVG (after sanitization):

drawio2tikz path/to/figure.drawio -o output_dir --keep-svg --svg-dir output_dir/svg

View Help

drawio2tikz --help

LaTeX Setup

Add these packages to your LaTeX document preamble:

\usepackage{xcolor}
\usepackage{tikz}

Include the generated TikZ file:

\input{path/to/figure.tikz}

For support of arbitrary large font sizes, use a scalable font:

\usepackage{mlmodern}

Example LaTeX Document

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{mlmodern}

\begin{document}

\section{My Diagram}

\begin{figure}
  \centering
  \input{figures/diagram.tikz}
  \caption{A diagram created in draw.io}
\end{figure}

\end{document}

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests on GitHub.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drawio2tikz-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drawio2tikz-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file drawio2tikz-0.1.0.tar.gz.

File metadata

  • Download URL: drawio2tikz-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for drawio2tikz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dded072c91484c671e4a60b53336e2c6e8c7720345be469f4fe0f1ad35a10a42
MD5 cdccfaa841f26ac1e978747519680032
BLAKE2b-256 fccbb46edf9763e5dc49ee626b32964cb8164ae32e665cb5a535fba9471a9816

See more details on using hashes here.

Provenance

The following attestation bundles were made for drawio2tikz-0.1.0.tar.gz:

Publisher: release.yml on okayama-daiki/drawio2tikz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drawio2tikz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: drawio2tikz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for drawio2tikz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99daaee760b8ae8d28a60c1bb1a9da396b5a38ac713e59e4274eeb8c5eafe352
MD5 2be573664f6084a087a88129eac6cad5
BLAKE2b-256 d003c90e15216382c5078790daf36785459a912d6eefd2034be2a44e7a176080

See more details on using hashes here.

Provenance

The following attestation bundles were made for drawio2tikz-0.1.0-py3-none-any.whl:

Publisher: release.yml on okayama-daiki/drawio2tikz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page