Skip to content

Instantly share code, notes, and snippets.

@andiac
Last active May 6, 2022 00:50
Show Gist options
  • Save andiac/2d45a382ac906e32f95890bcdd6dae3c to your computer and use it in GitHub Desktop.
Save andiac/2d45a382ac906e32f95890bcdd6dae3c to your computer and use it in GitHub Desktop.
svg path to tikz code
import svgpathtools
from svgpathtools import svg2paths2
paths, attributes, svg_attributes = svg2paths2('doubleset.svg')
SCALE = 10
print("\\begin{tikzpicture}")
for path in paths:
print("\\begin{scope}")
for b in path:
if isinstance(b, svgpathtools.CubicBezier):
print(f"\\draw ({b.start.real / SCALE}, {-b.start.imag / SCALE}) .. controls ({b.control1.real / SCALE}, {-b.control1.imag / SCALE}) and ({b.control2.real / SCALE}, {-b.control2.imag / SCALE}) .. ({b.end.real / SCALE}, {-b.end.imag / SCALE});")
if isinstance(b, svgpathtools.Line):
print(f"\\draw ({b.start.real / SCALE}, {-b.start.imag / SCALE}) -- ({b.end.real / SCALE}, {-b.end.imag / SCALE});")
print("\\end{scope}")
print("\\end{tikzpicture}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment