Skip to main content

Convert Latex Tikz code into yed graphml

Project description

Tikz2GraphML: P2 File conversion

CircleCI

tikz2graphml is TikZ (tex) to Graphml convertor which can be viewed in yEd software. It allows you to select the tex file (with TikZ code) and writes corresponding graphml file in the output directory. For the sake of cleanliness, each Tikz Block is analyzed separately to generate different GraphML files. tikz2graphml works on Linux and Windows. It can be used from commandline as well as GUI. tikz2graphml is very simple to use, powerful and supports many TikZ constructs. It also lets you scale the coordinates in graphml for better visualization of graphml in yEd.

Requirements

Python Version 3.7.0

This software requires following Python packages. If you install tikz2graphml using pip3, you don't need to install these requirements manually.

  • colour==0.1.5
  • numpy==1.16.2
  • networkx==2.3
  • matplotlib==3.0.3
  • pylatexenc==1.4
  • antlr4-python3-runtime==4.7.2

Installation

Ubuntu

It is recommended to create a python virtual environment to prevent breaking dependencies.

Creating a Python Virtual Environment

> sudo apt-get install python3-pip
> (sudo) pip3 install virtualenv 
> virtualenv -p python3 venv
> source venv/bin/activate           # Activate virtual environment

To deactivate virtual environment, type deactivate in shell.

Installing tikz2graphml

> sudo apt-get install python3-tk python3-pip
> (sudo) pip3 install tikz2graphml
> tikz2graphml

Windows

pip install tikz2graphml  
tikz2graphml

GUI

GUI Screenshot

Tikz Constructs Supported

We have handled these Tikz Constructs

  • Node
  • Shapes: Circle, Ellipse, Rectangle, Diamond
  • Size
  • Color
  • NodeID
  • Label
  • Edge Color
  • Lable
  • Edge
  • Width
  • Edge arrows: ->, <->,<-,-!-. -
  • Coordinates
  • Polar: (Angle, r (in cm))
  • Cartesian: (x,y)
  • Rotation of the Entire Graph
  • Handling Loop constructs(Foreach)
  • Global properties(applied to each tikz construct)

Examples

Sample TikZ code

\begin{tikzpicture}
    \draw (6,6) ellipse (3cm and 6cm);
    \draw (6,6) ellipse (2.5cm and 5cm);
    \draw (6,6) ellipse (2cm and 4cm);
    \draw (6,6) ellipse (1.5cm and 3cm);
    \draw (6,6) ellipse (1cm and 2cm);
    \draw (0,12) rectangle (12,0);
    \node (a) [fill=green, shape=diamond] at (0,6) {};
    \node (b) [fill=blue] at (12,6) {};
    \node (c) [fill=red] at (6,0) {};
    \node (d) [fill=black] at (6,12) {};
    \draw (6,6) circle (6cm);
    \draw [<->] (a) -- (b);
    \draw [->] (d) -- (c);
    \draw (6,6) ellipse (6cm and 2cm);
    \draw (6,6) ellipse (6cm and 6cm);
    \draw (6,6) ellipse (6cm and 5cm);
    \draw (6,6) ellipse (6cm and 4cm);
    \draw (6,6) ellipse (6cm and 3cm);
\end{tikzpicture}

GraphML output in yEd

Sample Output

Generation of GraphML file (Design)

Conversion Process

  • Read Input (tex file)
  • Detect TikZ code in File. If multiple TikZ block found, store them in list.
  • For each TikZ block detected above, do following
    • Detect Foreach Instruction and Unroll it.
    • Parse File using this grammar with Antlr4 tool
    • For each rule in Antlr grammar, we add corresponding rules which detects and store the properties of instruction in either of node or edge list TikZAntlrListener
    • Once parsing is done. We call get_graph which first rotates the graph (if rotate property is there) and then add the nodes and edges to pyyed graph.
    • We get the XML output from pyyed (using pyyed.graph.get_graph()) and write it in *.graphml file.

Current Status of the software

  • All the possible Tikz constructs are handled efficiently with the consideration of all the possible test-cases(invalid and valid test cases included)
  • The tool has been installed as a pip library
  • It works cross-platform(both Linux and Windows)
  • The original aim was to make it a command line tool. But in addition to this, we have also added a GUI interface which can take in input file and scaling parameter and output the corresponding GraphML file.

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

tikz2graphml-1.1.2.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

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

tikz2graphml-1.1.2-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file tikz2graphml-1.1.2.tar.gz.

File metadata

  • Download URL: tikz2graphml-1.1.2.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2

File hashes

Hashes for tikz2graphml-1.1.2.tar.gz
Algorithm Hash digest
SHA256 04adbb24a17f48a5768c368db25fff8ae868a7c2c6f1d49f009ca56d4a9b94cc
MD5 730b6fab32d61ed331c118cdf60e6ead
BLAKE2b-256 66764d035bcfe818d46f636fd04e74dbcf92ef0cc4976909434554c78d01f2a7

See more details on using hashes here.

File details

Details for the file tikz2graphml-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: tikz2graphml-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2

File hashes

Hashes for tikz2graphml-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19e1b38d63abf667a865d8e6744f45fbd68edaaae321ec043924418bbca4dea1
MD5 8398f3d0377a20d2ca4dca94f7516c51
BLAKE2b-256 e90072e1569056b3023ba138fe899b2b7a6dcab2981d26da5cbbfd419d051ca7

See more details on using hashes here.

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