GithubHelp home page GithubHelp logo

svg2tikz's Introduction

svg2tikz

Convert SVG figures generated by inkscape to TiKZ

Usage

python3 svg2tikz.py

A program to generate TiKZ code from inkscape-generated SVGs
Future plans include generalising to SVG without depending on Inkscape

positional arguments:
  INFILE                Input file

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -d, --debug           Enable debugging messages (repeat for more messages)
  -a, --auto            Create output name from source
  -o OUTPUT, --output OUTPUT
                        Write to file(default is stdout)
  -b BORDER, --border BORDER
                        Set standalone border (default:1mm)
  -r DPI, --dpi DPI     Resolution (assume 72dpi)
  -R, --round           Round numbers to the nearest integer (default is 1
                        decimal)
  -M, --multi           Make a multi-slide LaTEX file
  -s, --standalone      Make a standalone LaTEX file
  -X XFORM, --xform XFORM
                        transformation applied to the SVG code (default:
                        yscale=-1)
  --code CODE           Output file coding

This script converts SVG to TiKZ drawings. In standalone mode, the result can then be converted to PDF using pdflatex (see Makefile). Otherwise, the result is a TeX file that is included into LaTEX documents (using the \input{} command)

MAIN SCOPE: The main scope of this script is files generated with Inkscape. I will make my best to parse other SVGs

Multi slide HOWTO

In order to create an animation from an Inkscape file

  1. Create an inkscape figure.
  2. Group objects you want to appear on each slide incrementally
  3. Using the XML Editor in Inkscape, order the groups by order of appearance
  4. Group all pages in one object. The structure should look like
 +-<defs>
 +-<g>
    +-<g>
    +-<g>
     ...
  1. Add --multi when calling svg2tikz
  2. In your Beamer presentation, \input{generated_tikz}

Tested with Inkscape up to v1.0beta2

Example: make multi will convert mount-ns.svg and compile test-multi.tex to create a multi-slide presentation

Limitations: Multi-slide standalone TiKZ files are not supported.

TODO

  • arcs:
  • Better support for rotation
  • migrate to predefived XPath functions

Dependencies:

  • Python 3
  • LXML to parse the SVG files

svg2tikz's People

Contributors

mclaughlinconnor avatar paaguti avatar vladrich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

svg2tikz's Issues

Path does not show

Attaching an example where svg2tikz doesn't properly convert a path. The output tikz image has a \draw directive but no curve controls

test.zip

svg2tikz gives output:

[None] -->> M 0,0 V 0 C -0.146,3.553 2.641,6.58 6.193,6.727 9.747,6.873 12.773,4.086 12.92,0.533 13.066,-3.021 10.279,-6.047 6.727,-6.194 3.173,-6.34 0.146,-3.553 0,0
 -- [M ] >> M 
[M] -->> V 0 C -0.146,3.553 2.641,6.58 6.193,6.727 9.747,6.873 12.773,4.086 12.92,0.533 13.066,-3.021 10.279,-6.047 6.727,-6.194 3.173,-6.34 0.146,-3.553 0,0
ERROR: 'V 0 C -0.146,3.553 2.641,6.58 6.193,6.727 9.747,6.873 12.773,4.086 12.92,0.533 13.066,-3.021 10.279,-6.047 6.727,-6.194 3.173,-6.34 0.146,-3.553 0,0' does not have aAcCqQlLmM element

Not able to convert

Hi,

I have a problem to convert this svg into tikz. It was generated the other way around (tikz -> svg)
http://blog.wikunia.de/user/pages/blog/2015-05-18-first-steps/xor.svg

My error messages:

python2 svg2tikz.py -a xor.svg 
 xor.svg --> xor.tex 
WARNING: <use ../> not processed
WARNING: <use ../> not processed
WARNING: <use ../> not processed
WARNING: <use ../> not processed
Traceback (most recent call last):
  File "svg2tikz.py", line 613, in <module>
    main()
  File "svg2tikz.py", line 608, in main
    processor.mkTikz(root)
  File "svg2tikz.py", line 560, in mkTikz
    self.process_g(elem)
  File "svg2tikz.py", line 540, in process_g
    xlate[x](child)
  File "svg2tikz.py", line 530, in <lambda>
    'path':    lambda e: self.process_path(e)
  File "svg2tikz.py", line 362, in process_path
    pid = elem.attrib['id']
  File "lxml.etree.pyx", line 2366, in lxml.etree._Attrib.__getitem__ (src/lxml/lxml.etree.c:62258)
KeyError: 'id'

Unable to convert svg

I tried with this example and i got the following error:

rnn

line 946, in mkTikz
    self._unit = svg.xpath('string(//svg:svg/sodipodi:namedview/@units)',namespaces=self._nsmap)
  File "src/lxml/etree.pyx", line 2314, in lxml.etree._ElementTree.xpath
  File "src/lxml/xpath.pxi", line 357, in lxml.etree.XPathDocumentEvaluator.__call__
  File "src/lxml/xpath.pxi", line 225, in lxml.etree._XPathEvaluatorBase._handle_result
lxml.etree.XPathEvalError: Undefined namespace prefix

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.