在 MacOS 上将 .svg 导出为 TikZ 代码时出现问题

在 MacOS 上将 .svg 导出为 TikZ 代码时出现问题

我正在尝试svg使用 Inkscape 和svg2tikz从中下载的扩展将文件转换为 tikz 代码https://github.com/kjellmf/svg2tikz。我以前在 Windows 10 下做过这个,但这次我使用的是 MacOS。没有.tex生成文件,我得到了以下输出:

tikz_export.py:645: DeprecationWarning: Effect.OptionParser or `optparse` has been deprecated and replaced with `argparser`.You must change `self.OptionParser.add_option` to `self.arg_parser.add_argument`; the arguments are similar.
  parser = self.OptionParser
Traceback (most recent call last):
  File "tikz_export.py", line 1478, in <module>
    main_inkscape()
  File "tikz_export.py", line 1461, in main_inkscape
    effect = TikZPathExporter(inkscape_mode=True)
  File "tikz_export.py", line 629, in __init__
    self._set_up_options()
  File "tikz_export.py", line 646, in _set_up_options
    parser.set_defaults(codeoutput='standalone', crop=False, clipboard=False,
AttributeError: 'TikZPathExporter' object has no attribute 'set_defaults'

以下是该文件的内容svg

<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="1200px" height="1200px" viewBox="0 0 12000 12000" preserveAspectRatio="xMidYMid meet"><g fill="#14120b"><path d="M0 6000 l0-6000 6000 0 6000 0 0 6000 0 6000-6000 0-6000 0 0-6000z"/></g><g fill="#ffffff"><path d="M0 6000 l0-6000 6000 0 6000 0 0 6000 0 6000-6000 0-6000 0 0-6000z m11506 4617 c82-46 89-81 27-138-47-45-105-68-316-125-457-124-692-201-1047-341-146-58-305-121-355-140-272-108-644-321-1298-743-272-176-885-635-1207-904-206-173-564-532-802-806-271-312-348-405-348-419 0-6 56-100 123-209 354-565 729-1243 892-1612 153-345 302-791 370-1102 51-237 20-367-73-302-31 22-47 55-108 236-81 238-120 316-306 615-48 79-152 254-229 390-252 441-447 758-720 1169-147 221-271 404-277 408-5 3-93-88-194-202-191-214-643-684-866-900-208-202-293-265-512-382-74-40-153-85-175-100-22-15-50-30-63-34-12-4-20-12-17-17 4-5-8-9-24-9-37 0-42 27-10 56 11 10 27 32 34 49 21 50 105 161 236 315 142 165 210 252 402 505 74 99 222 286 328 415 182 223 518 654 548 704 14 22 9 30-99 172-469 616-943 1137-1367 1501-421 362-756 600-1028 733-152 75-210 93-410 130-191 35-215 43-215 69 0 11-3 26-6 34-7 18 81 108 145 149 25 16 77 38 115 50 195 59 538-38 937-265 559-317 1140-786 1588-1283 176-194 416-488 561-686 63-86 118-157 122-157 3-1 71 79 149 177 386 480 562 675 854 948 306 286 437 396 802 670 468 353 962 648 1345 803 267 108 661 240 948 317 113 31 300 82 415 114 335 94 556 145 750 173 17 3 98 4 180 3 145-1 152-2 201-29z m-9786-6023 c394-45 809-137 2000-444 852-219 1684-397 2615-560 1605-281 1819-312 2680-399 1181-119 1420-134 1914-121 305 8 357 7 382-5 75-40 85-177 17-259-41-50-130-93-265-127-274-69-435-67-1453 17-538 44-713 63-1140 124-466 67-1789 303-2385 425-148 31-349 72-445 91-583 116-2033 471-2713 665-773 219-1385 320-1761 290-156-13-308-41-391-72-74-27-167-91-196-134-23-33-40-38-68-21-20 13-6 79 32 150 104 195 352 341 652 385 100 14 381 12 525-5z m4608-2340 c101-42 152-148 122-253-16-56-57-106-169-207-230-207-526-363-831-438-136-33-502-96-560-96-91 0-121 59-52 104 20 14 101 55 180 91 297 137 478 265 734 517 216 214 350 296 486 297 29 1 69-6 90-15z"/></g></svg>

答案1

顺便说一下,TiZ 通过svg.path库直接支持 svg 路径因此只需复制粘贴即可获得:

在此处输入图片描述

代码如下:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{svg.path}
\definecolor{PathColor}{HTML}{14120b}
\begin{document}
\begin{tikzpicture}[fill=PathColor]
\pgfpathsvg{M0 6000 l0-6000 6000 0 6000 0 0 6000 0 6000-6000 0-6000 0 0-6000z m11506 4617 c82-46 89-81 27-138-47-45-105-68-316-125-457-124-692-201-1047-341-146-58-305-121-355-140-272-108-644-321-1298-743-272-176-885-635-1207-904-206-173-564-532-802-806-271-312-348-405-348-419 0-6 56-100 123-209 354-565 729-1243 892-1612 153-345 302-791 370-1102 51-237 20-367-73-302-31 22-47 55-108 236-81 238-120 316-306 615-48 79-152 254-229 390-252 441-447 758-720 1169-147 221-271 404-277 408-5 3-93-88-194-202-191-214-643-684-866-900-208-202-293-265-512-382-74-40-153-85-175-100-22-15-50-30-63-34-12-4-20-12-17-17 4-5-8-9-24-9-37 0-42 27-10 56 11 10 27 32 34 49 21 50 105 161 236 315 142 165 210 252 402 505 74 99 222 286 328 415 182 223 518 654 548 704 14 22 9 30-99 172-469 616-943 1137-1367 1501-421 362-756 600-1028 733-152 75-210 93-410 130-191 35-215 43-215 69 0 11-3 26-6 34-7 18 81 108 145 149 25 16 77 38 115 50 195 59 538-38 937-265 559-317 1140-786 1588-1283 176-194 416-488 561-686 63-86 118-157 122-157 3-1 71 79 149 177 386 480 562 675 854 948 306 286 437 396 802 670 468 353 962 648 1345 803 267 108 661 240 948 317 113 31 300 82 415 114 335 94 556 145 750 173 17 3 98 4 180 3 145-1 152-2 201-29z m-9786-6023 c394-45 809-137 2000-444 852-219 1684-397 2615-560 1605-281 1819-312 2680-399 1181-119 1420-134 1914-121 305 8 357 7 382-5 75-40 85-177 17-259-41-50-130-93-265-127-274-69-435-67-1453 17-538 44-713 63-1140 124-466 67-1789 303-2385 425-148 31-349 72-445 91-583 116-2033 471-2713 665-773 219-1385 320-1761 290-156-13-308-41-391-72-74-27-167-91-196-134-23-33-40-38-68-21-20 13-6 79 32 150 104 195 352 341 652 385 100 14 381 12 525-5z m4608-2340 c101-42 152-148 122-253-16-56-57-106-169-207-230-207-526-363-831-438-136-33-502-96-560-96-91 0-121 59-52 104 20 14 101 55 180 91 297 137 478 265 734 517 216 214 350 296 486 297 29 1 69-6 90-15z}
\pgfusepath{fill}
\end{tikzpicture}
\end{document}

上下颠倒编辑

\documentclass[tikz,border=3mm]{standalone}
    \usetikzlibrary{svg.path}
    \definecolor{PathColor}{HTML}{14120b}
    \begin{document}
    \begin{tikzpicture}[fill=PathColor,yscale=-1]
    \pgfpathsvg{M0 6000 l0-6000 6000 0 6000 0 0 6000 0 6000-6000 0-6000 0 0-6000z m11506 4617 c82-46 89-81 27-138-47-45-105-68-316-125-457-124-692-201-1047-341-146-58-305-121-355-140-272-108-644-321-1298-743-272-176-885-635-1207-904-206-173-564-532-802-806-271-312-348-405-348-419 0-6 56-100 123-209 354-565 729-1243 892-1612 153-345 302-791 370-1102 51-237 20-367-73-302-31 22-47 55-108 236-81 238-120 316-306 615-48 79-152 254-229 390-252 441-447 758-720 1169-147 221-271 404-277 408-5 3-93-88-194-202-191-214-643-684-866-900-208-202-293-265-512-382-74-40-153-85-175-100-22-15-50-30-63-34-12-4-20-12-17-17 4-5-8-9-24-9-37 0-42 27-10 56 11 10 27 32 34 49 21 50 105 161 236 315 142 165 210 252 402 505 74 99 222 286 328 415 182 223 518 654 548 704 14 22 9 30-99 172-469 616-943 1137-1367 1501-421 362-756 600-1028 733-152 75-210 93-410 130-191 35-215 43-215 69 0 11-3 26-6 34-7 18 81 108 145 149 25 16 77 38 115 50 195 59 538-38 937-265 559-317 1140-786 1588-1283 176-194 416-488 561-686 63-86 118-157 122-157 3-1 71 79 149 177 386 480 562 675 854 948 306 286 437 396 802 670 468 353 962 648 1345 803 267 108 661 240 948 317 113 31 300 82 415 114 335 94 556 145 750 173 17 3 98 4 180 3 145-1 152-2 201-29z m-9786-6023 c394-45 809-137 2000-444 852-219 1684-397 2615-560 1605-281 1819-312 2680-399 1181-119 1420-134 1914-121 305 8 357 7 382-5 75-40 85-177 17-259-41-50-130-93-265-127-274-69-435-67-1453 17-538 44-713 63-1140 124-466 67-1789 303-2385 425-148 31-349 72-445 91-583 116-2033 471-2713 665-773 219-1385 320-1761 290-156-13-308-41-391-72-74-27-167-91-196-134-23-33-40-38-68-21-20 13-6 79 32 150 104 195 352 341 652 385 100 14 381 12 525-5z m4608-2340 c101-42 152-148 122-253-16-56-57-106-169-207-230-207-526-363-831-438-136-33-502-96-560-96-91 0-121 59-52 104 20 14 101 55 180 91 297 137 478 265 734 517 216 214 350 296 486 297 29 1 69-6 90-15z}
    \pgfusepath{fill}
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

编辑背景颜色

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{svg.path}
\definecolor{PathColor}{HTML}{14120b}
\begin{document}
\begin{tikzpicture}[fill=PathColor,yscale=-1]
\pgfpathsvg{M0 6000 l0-6000 6000 0 6000 0 0 6000 0 6000-6000 0-6000 0 0-6000z}
\pgfusepath{discard}
\pgfpathsvg{M0 6000 m11506 4617 c82-46 89-81 27-138-47-45-105-68-316-125-457-124-692-201-1047-341-146-58-305-121-355-140-272-108-644-321-1298-743-272-176-885-635-1207-904-206-173-564-532-802-806-271-312-348-405-348-419 0-6 56-100 123-209 354-565 729-1243 892-1612 153-345 302-791 370-1102 51-237 20-367-73-302-31 22-47 55-108 236-81 238-120 316-306 615-48 79-152 254-229 390-252 441-447 758-720 1169-147 221-271 404-277 408-5 3-93-88-194-202-191-214-643-684-866-900-208-202-293-265-512-382-74-40-153-85-175-100-22-15-50-30-63-34-12-4-20-12-17-17 4-5-8-9-24-9-37 0-42 27-10 56 11 10 27 32 34 49 21 50 105 161 236 315 142 165 210 252 402 505 74 99 222 286 328 415 182 223 518 654 548 704 14 22 9 30-99 172-469 616-943 1137-1367 1501-421 362-756 600-1028 733-152 75-210 93-410 130-191 35-215 43-215 69 0 11-3 26-6 34-7 18 81 108 145 149 25 16 77 38 115 50 195 59 538-38 937-265 559-317 1140-786 1588-1283 176-194 416-488 561-686 63-86 118-157 122-157 3-1 71 79 149 177 386 480 562 675 854 948 306 286 437 396 802 670 468 353 962 648 1345 803 267 108 661 240 948 317 113 31 300 82 415 114 335 94 556 145 750 173 17 3 98 4 180 3 145-1 152-2 201-29z m-9786-6023 c394-45 809-137 2000-444 852-219 1684-397 2615-560 1605-281 1819-312 2680-399 1181-119 1420-134 1914-121 305 8 357 7 382-5 75-40 85-177 17-259-41-50-130-93-265-127-274-69-435-67-1453 17-538 44-713 63-1140 124-466 67-1789 303-2385 425-148 31-349 72-445 91-583 116-2033 471-2713 665-773 219-1385 320-1761 290-156-13-308-41-391-72-74-27-167-91-196-134-23-33-40-38-68-21-20 13-6 79 32 150 104 195 352 341 652 385 100 14 381 12 525-5z m4608-2340 c101-42 152-148 122-253-16-56-57-106-169-207-230-207-526-363-831-438-136-33-502-96-560-96-91 0-121 59-52 104 20 14 101 55 180 91 297 137 478 265 734 517 216 214 350 296 486 297 29 1 69-6 90-15z}
\pgfusepath{fill}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容