Metadata-Version: 2.4
Name: drawio2tikz
Version: 0.4.0
Summary: Convert diagrams.net/draw.io diagrams to TikZ via SVG.
Keywords: drawio,diagrams.net,svg,tikz,latex
Author: Daiki Okayama
Author-email: Daiki Okayama <lawliet.d.k.m@gmail.com>
License-Expression: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Operating System :: OS Independent
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Vector-Based
Classifier: Topic :: Text Processing :: Markup :: LaTeX
Requires-Dist: rich>=15.0
Requires-Dist: svg2tikz>=3.3.4
Requires-Dist: typer>=0.15
Requires-Python: >=3.14
Project-URL: Homepage, https://github.com/daikiokayama/drawio2tikz
Project-URL: Issues, https://github.com/daikiokayama/drawio2tikz/issues
Description-Content-Type: text/markdown

# drawio2tikz

`drawio2tikz` is a thin wrapper around [`svg2tikz`](https://github.com/xyz2tex/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](https://diagrams.net) or via Homebrew: `brew install --cask drawio`)

## Installation

### pip / uv

Install from PyPI:

```bash
uv tool install drawio2tikz
```

Or with pip:

```bash
pip install drawio2tikz
```

### Development Setup

Clone the repository and install in development mode:

```bash
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:

```bash
drawio2tikz path/to/figure.drawio -o output_dir
```

This generates `figure.tex` in the output directory.

### Convert All Pages

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

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

Each page is saved as `multipage-01.tex`, `multipage-02.tex`, and so on.

### Keep Intermediate SVG

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

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

### View Help

```bash
drawio2tikz --help
```

## LaTeX Setup

Add these packages to your LaTeX document preamble:

```tex
\usepackage{xcolor}
\usepackage{tikz}
```

Include the generated TikZ file:

```tex
\input{path/to/figure.tex}
```

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

```tex
\usepackage{mlmodern}
```

### Example LaTeX Document

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

\begin{document}

\section{My Diagram}

\begin{figure}
  \centering
  \input{figures/diagram.tex}
  \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](https://github.com/daikiokayama/drawio2tikz).

## License

MIT
