使用 Inkscape shell-escape 自动导出 SVG 时出现问题

使用 Inkscape shell-escape 自动导出 SVG 时出现问题

我目前正在努力导出我在 Inkscape 中准备的 svg,非常感谢任何帮助或提示。我一直在使用 SVG 包文档中的 MWE (https://ctan.org/pkg/svg) 在第 4 章中。为了完整起见,我也会在这里提供它:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{svg}
\usepackage[off]{svg-extract}
\svgsetup{clean=true}
%\pdfsuppresswarningpagegroup=1
\usepackage{relsize}
\usepackage{subcaption}
\begin{document}
    \begin{figure}
        \begin{minipage}{.5\linewidth}
            \includesvg[width=\linewidth]{svg-example}%
            \subcaption{This text is too large!}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}%
            \subcaption{This text fits better.}
        \end{minipage}
        \caption{An example figure with \LaTeX~support}\label{fig:example}
    \end{figure}
    \begin{figure}\centering
        \includesvg[%
        width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}%
        ]{svg-example}%
        \caption{The same example figure without \LaTeX~support}
    \end{figure}
\end{document}

我不确定如何提供我使用的 svg,但我保证在与上述 tex 文件相同的目录中存在一个“svg-example.svg”。我将在此处将其作为 png 包含,但它在目录中是 svg 格式。

我的测试 svg 文件

我已启用 shell-escape(TeXStudio 中 pdflatex.exe 的参数为 --shell-escape),并在系统路径中启用了 Inkscape。日志底部包含错误消息,如下所示:

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7200 64-bit) (preloaded format=pdflatex 2019.10.7)  8 OCT 2019 09:30
entering extended mode
**./start.tex
(start.tex
LaTeX2e <2019-10-01>
("C:\Programme\MiKTeX 2.9\tex/latex/base\article.cls"
Document Class: article 2019/08/27 v1.4j Standard LaTeX document class
("C:\Programme\MiKTeX 2.9\tex/latex/base\size10.clo"
File: size10.clo 2019/08/27 v1.4j Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
("C:\Programme\MiKTeX 2.9\tex/latex/base\fontenc.sty"
Package: fontenc 2018/08/11 v2.0j Standard LaTeX package

("C:\Programme\MiKTeX 2.9\tex/latex/base\t1enc.def"
File: t1enc.def 2018/08/11 v2.0j Standard LaTeX file
LaTeX Font Info:    Redeclaring font encoding T1 on input line 48.
))
("C:\Programme\MiKTeX 2.9\tex/latex/svg\svg.sty"
Package: svg 2018/11/12 v2.02b (include SVG pictures)

("C:\Programme\MiKTeX 2.9\tex/latex/koma-script\scrbase.sty"
Package: scrbase 2019/02/01 v3.26b KOMA-Script package (KOMA-Script-independent
 basics and keyval usage)

("C:\Programme\MiKTeX 2.9\tex/latex/graphics\keyval.sty"
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks14
)
("C:\Programme\MiKTeX 2.9\tex/latex/koma-script\scrlfile.sty"
Package: scrlfile 2019/02/01 v3.26b KOMA-Script package (loading files)


LaTeX Warning: Command \InputIfFileExists  has changed.
               Check if current package is valid.

)) ("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\ifpdf.sty"
Package: ifpdf 2018/09/07 v3.3 Provides the ifpdf switch
)
("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\ifluatex.sty"
Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
("C:\Programme\MiKTeX 2.9\tex/generic/ifxetex\ifxetex.sty"
Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional
)
("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\pdftexcmds.sty"
Package: pdftexcmds 2019/07/25 v0.30 Utility functions of pdfTeX for LuaTeX (HO
)

("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\infwarerr.sty"
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
)
("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\ltxcmds.sty"
Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
)
("C:\Programme\MiKTeX 2.9\tex/latex/tools\shellesc.sty"
Package: shellesc 2016/06/07 v0.02b unified shell escape interface for LaTeX
Package shellesc Info: Unrestricted shell escape enabled on input line 70.
)
("C:\Programme\MiKTeX 2.9\tex/latex/trimspaces\trimspaces.sty"
Package: trimspaces 2009/09/17 v1.1 Trim spaces around a token list
)
("C:\Programme\MiKTeX 2.9\tex/latex/graphics\graphicx.sty"
Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)

("C:\Programme\MiKTeX 2.9\tex/latex/graphics\graphics.sty"
Package: graphics 2019/07/20 v1.3b Standard LaTeX Graphics (DPC,SPQR)

("C:\Programme\MiKTeX 2.9\tex/latex/graphics\trig.sty"
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
("C:\Programme\MiKTeX 2.9\tex/latex/graphics-cfg\graphics.cfg"
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 105.

("C:\Programme\MiKTeX 2.9\tex/latex/graphics-def\pdftex.def"
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
))
\Gin@req@height=\dimen103
\Gin@req@width=\dimen104
)
\svg@box=\box27
\c@svg@param@lastpage=\count88
\c@svg@param@currpage=\count89

("C:\Programme\MiKTeX 2.9\tex/latex/ifplatform\ifplatform.sty"
Package: ifplatform 2017/10/13 v0.4a Testing for the operating system

("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\catchfile.sty"
Package: catchfile 2016/05/16 v1.7 Catch the contents of a file (HO)

("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\etexcmds.sty"
Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
))))
("C:\Programme\MiKTeX 2.9\tex/latex/xcolor\xcolor.sty"
Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)

("C:\Programme\MiKTeX 2.9\tex/latex/graphics-cfg\color.cfg"
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package xcolor Info: Driver file: pdftex.def on input line 225.
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348.
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352.
Package xcolor Info: Model `RGB' extended on input line 1364.
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366.
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367.
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368.
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369.
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370.
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371.
)
("C:\Programme\MiKTeX 2.9\tex/latex/oberdiek\transparent.sty"
Package: transparent 2018/11/18 v1.3 Transparency via pdfTeX's color stack (HO)


("C:\Programme\MiKTeX 2.9\tex/latex/oberdiek\auxhook.sty"
Package: auxhook 2016/05/16 v1.4 Hooks for auxiliary files (HO)
))
("C:\Programme\MiKTeX 2.9\tex/latex/svg\svg-extract.sty"
Package: svg-extract 2018/11/12 v2.02b (extract independent graphics from SVG p
ictures)
\c@svgx@runs=\count90
\c@svgx@out@count=\count91


Package svg Warning: The option key `extract' can only
(svg)                be used with package `svg-extract', but
(svg)                you didn't load it on input line 720.

\svgx@stream@in=\read1
\svgx@stream@out=\write3
) ("C:\Programme\MiKTeX 2.9\tex/latex/relsize\relsize.sty"
Package: relsize 2013/03/29 ver 4.1
)
("C:\Programme\MiKTeX 2.9\tex/latex/caption\subcaption.sty"
Package: subcaption 2019/09/01 v1.3a Sub-captions (AR)

("C:\Programme\MiKTeX 2.9\tex/latex/caption\caption.sty"
Package: caption 2019/09/01 v3.3d Customizing captions (AR)

("C:\Programme\MiKTeX 2.9\tex/latex/caption\caption3.sty"
Package: caption3 2019/09/01 v1.8d caption3 kernel (AR)
Package caption3 Info: TeX engine: e-TeX on input line 64.
\captionmargin=\dimen105
\captionmargin@=\dimen106
\captionwidth=\dimen107
\caption@tempdima=\dimen108
\caption@indent=\dimen109
\caption@parindent=\dimen110
\caption@hangindent=\dimen111
)
\c@caption@flags=\count92
\c@ContinuedFloat=\count93
)
\c@subfigure=\count94
\c@subtable=\count95
) (start.aux)
\openout1 = `start.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.

("C:\Programme\MiKTeX 2.9\tex/context/base/mkii\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count96
\scratchdimen=\dimen112
\scratchbox=\box28
\nofMPsegments=\count97
\nofMParguments=\count98
\everyMPshowfont=\toks15
\MPscratchCnt=\count99
\MPscratchDim=\dimen113
\MPnumerator=\count100
\makeMPintoPDFobject=\count101
\everyMPtoPDFconversion=\toks16
) ("C:\Programme\MiKTeX 2.9\tex/latex/oberdiek\epstopdf-base.sty"
Package: epstopdf-base 2016/05/15 v2.6 Base part for package epstopdf

("C:\Programme\MiKTeX 2.9\tex/latex/oberdiek\grfext.sty"
Package: grfext 2016/05/16 v1.2 Manage graphics extensions (HO)

("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\kvdefinekeys.sty"
Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO)
))
("C:\Programme\MiKTeX 2.9\tex/latex/oberdiek\kvoptions.sty"
Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)

("C:\Programme\MiKTeX 2.9\tex/generic/oberdiek\kvsetkeys.sty"
Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)
))
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
38.
Package grfext Info: Graphics extension search list:
(grfext)             [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 456.
)
Package caption Info: Begin \AtBeginDocument code.
Package caption Info: End \AtBeginDocument code.
Package svg Info: Calling Inkscape on input line 12.
runsystem(inkscape -z -D --export-latex  --file="svg-example.svg.svg" --export-
pdf="svg-example.svg_svg-tex.pdf" )...executed.



Package svg Warning: The export with Inkscape failed for file
(svg)                `svg-example.svg.svg'
(svg)                Troubleshooting: Please check in the log file how
(svg)                the invocation of Inkscape took place and try to
(svg)                execute it yourself in the terminal on input line 12.


! Package svg Error: File `svg-example.svg_svg-tex.pdf' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12            \includesvg[width=\linewidth]{svg-example}
                                                  %
Did you run the export with Inkscape? There's no file
`./svg-inkscape/svg-example.svg_svg-tex.pdf'
although `svg-example.svg.svg' was found.


! Package svg Error: File `svg-example.svg_svg-tex.pdf_tex' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12            \includesvg[width=\linewidth]{svg-example}
                                                  %
Did you run the export with Inkscape? There's no file
`./svg-inkscape/svg-example.svg_svg-tex.pdf_tex'
although `svg-example.svg.svg' was found.

LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 14.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 14.
Package svg Info: Calling Inkscape on input line 16.
runsystem(inkscape -z -D --export-latex  --file="svg-example.svg.svg" --export-
pdf="svg-example.svg_svg-tex.pdf" )...executed.


Package svg Warning: The export with Inkscape failed for file
(svg)                `svg-example.svg.svg'
(svg)                Troubleshooting: Please check in the log file how
(svg)                the invocation of Inkscape took place and try to
(svg)                execute it yourself in the terminal on input line 16.


! Package svg Error: File `svg-example.svg_svg-tex.pdf' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.16 ...ewidth,pretex=\relscale{0.6}]{svg-example}
                                                  %
Did you run the export with Inkscape? There's no file
`./svg-inkscape/svg-example.svg_svg-tex.pdf'
although `svg-example.svg.svg' was found.


! Package svg Error: File `svg-example.svg_svg-tex.pdf_tex' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.16 ...ewidth,pretex=\relscale{0.6}]{svg-example}
                                                  %
Did you run the export with Inkscape? There's no file
`./svg-inkscape/svg-example.svg_svg-tex.pdf_tex'
although `svg-example.svg.svg' was found.


! Package svg Error: File `svg-example.svg_svg-raw.pdf' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.24        ]{svg-example}
                     %
Did you run the export with Inkscape? There's no file
`./svg-inkscape/svg-example.svg_svg-raw.pdf'
although `svg-example.svg.svg' was found.

[1{C:/Users/<censored>/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
(start.aux) ) 
Here is how much of TeX's memory you used:
 4411 strings out of 492452
 70714 string characters out of 3131664
 158995 words of memory out of 50000000
 8719 multiletter control sequences out of 15000+200000
 5936 words of font info for 17 fonts, out of 3000000 for 9000
 1141 hyphenation exceptions out of 8191
 48i,7n,65p,279b,446s stack positions out of 5000i,500n,10000p,200000b,50000s
 <C:\Users\<censored>\AppData\Local\MiKTeX\2.9\fonts/pk/ljfour/jknappen
/ec/dpi600\ecrm0700.pk> <C:\Users\<censored>\AppData\Local\MiKTeX\2.9\fonts/pk/ljfou
r/jknappen/ec/dpi600\ecrm1000.pk> <C:\Users\<censored>\AppData\Local\MiKTeX\2.9\font
s/pk/ljfour/jknappen/ec/dpi600\ecrm0900.pk>
Output written on start.pdf (1 page, 16378 bytes).
PDF statistics:
 63 PDF objects out of 1000 (max. 8388607)
 0 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)

我的猜测是,由于某种原因,它在文件名后面放置了“.svg.svg”(即两次文件扩展名),但我完全不知道它为什么这样做,也不知道如何修复它。

我尝试手动将 svg 文件转换为 pdf inkscape -z -D --export-latex --file="svg-example.svg" --export-pdf="svg-example.svg_svg-tex.pdf"(请注意,我将“.svg.svg”更改为“.svg”),此方法有效并正确创建了 pdf 文件。但是,将这两个文件放入子目录“svg-inkscape”时,它仍然不起作用,并且出现以下错误:

LaTeX Warning: File `{./svg-inkscape/"svg-example.svg"_svg-tex}.pdf' not found 
on input line 52.


! LaTeX Error: Unknown graphics extension: .svg_svg-tex}.pdf.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.52 ...\unitlength]{svg-example.svg_svg-tex.pdf}}
                                                  %
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

)
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 14.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 14.
Package svg Info: Last page of `./svg-inkscape/"svg-example.svg"_svg-tex.pdf' i
s 1 on input line 16.
 (svg-inkscape/svg-example.svg_svg-tex.pdf_tex

LaTeX Warning: File `{./svg-inkscape/"svg-example.svg"_svg-tex}.pdf' not found 
on input line 52.


! LaTeX Error: Unknown graphics extension: .svg_svg-tex}.pdf.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.52 ...\unitlength]{svg-example.svg_svg-tex.pdf}}
                                                  %
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

)

! Package svg Error: File `svg-example.svg_svg-raw.pdf' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.24        ]{svg-example}
                     %
Did you run the export with Inkscape? There's no file
`./svg-inkscape/svg-example.svg_svg-raw.pdf'
although `svg-example.svg.svg' was found.

但是,Inkscape 生成的文件位于正确的文件夹中!我猜这是由于引号、花括号或其他东西造成的,但我真的不知道是什么原因造成的,也不知道该如何修复它。

这是我在 Stackexchange 上的第一篇文章,所以如果我忘记提供一些信息,请告诉我!我非常感谢任何帮助,这样我就可以继续写我的论文,而不必在这上面浪费大量时间!

此致,

特里佩迪奥

答案1

这不是一个答案,但我想发布代码,一旦最终修复完毕,我将在这里发布完整的答案。

您可以使用 svg 来测试一下吗?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{svg}
\usepackage[off]{svg-extract}
\svgsetup{clean=true}
%\pdfsuppresswarningpagegroup=1
\usepackage{relsize}
\usepackage{subcaption}
\makeatletter
\def\set@curr@file#1{\def\@curr@file{#1}}
\makeatother
\begin{document}
    \begin{figure}
        \begin{minipage}{.5\linewidth}
            \includesvg[width=\linewidth]{svg-example}%
            \subcaption{This text is too large!}
        \end{minipage}%
        \begin{minipage}{.5\linewidth}
            \includesvg[width=\linewidth,pretex=\relscale{0.6}]{svg-example}%
            \subcaption{This text fits better.}
        \end{minipage}
        \caption{An example figure with \LaTeX~support}\label{fig:example}
    \end{figure}
    \begin{figure}\centering
        \includesvg[%
        width=.5\linewidth,inkscapelatex=false,extractformat={pdf,eps}%
        ]{svg-example}%
        \caption{The same example figure without \LaTeX~support}
    \end{figure}
\end{document}

相关内容