版本信息
语境
mtx-context | ConTeXt Process Management 0.63
mtx-context |
mtx-context | main context file:
/opt/context/tex/texmf-context/tex/context/base/mkiv/context.mkiv
mtx-context | current version: 2016.07.18 16:46
Inkscape
Inkscape 0.92pre1 unknown (Jul 30 2016)
我不确定此版本Inkscape 有问题。
最小工作示例
ConTeXt 代码(./test.tex)
\setupexternalfigures[
order={svg,pdf,png},
location={local,default,global},
directory={images},
frameoffset=.5em,
maxwidth=\makeupwidth,
width=\makeupwidth,
]
\starttext
\placefigure{}{\externalfigure[images/drawing.svg]}
\stoptext
SVG 文件 (./images/drawing.svg)
任何 SVG 文件都可以。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
id="svg8"
version="1.1"
viewBox="0 0 210 297"
height="297mm"
width="210mm">
<defs
id="defs2" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1">
<rect
y="8.2261906"
x="12.851191"
height="137.58333"
width="178.40475"
id="rect4231"
style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:#ffd5d5;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate"
/>
</g>
</svg>
错误信息
运行context test.tex
产生:
... logging ...
** (inkscape:19807): WARNING **: File path
"--export-pdf=/home/username/temp/images/m_k_i_v_drawing.svg.pdf"
includes directory that doesn't exist.
... more logging ...
解决方法
通过首先将图像从 SVG 转换为 PDF,可以避免错误并产生预期的输出:
$ cd images
$ inkscape -z drawing.svg \
--export-pdf=/home/username/temp/images/m_k_i_v_drawing.svg.pdf
然后:
$ cd ..
$ context test.tex
没有错误。
问题
有什么想法可以解决,而无需先手动转换每个文件?
答案1
要调试正在发生的事情,请运行:
context --trackers=graphics.conversion test.tex
控制台输出显示:
...
graphics > inclusion > checking conversion of 'images/drawing.svg', fullname 'images/drawing.svg', old format 'svg', new format 'pdf', conversion 'default', resolution 'default', arguments ''
graphics > inclusion > converting 'images/drawing.svg' ('images/drawing.svg') from 'svg' to 'pdf'
graphics > inclusion > running command: inkscape "/tmp/images/drawing.svg" --export-dpi=600 -A --export-pdf="/tmp/images/m_k_i_v_drawing.svg.pdf"
** (inkscape:7970): WARNING **: File path "--export-pdf=/tmp/images/m_k_i_v_drawing.svg.pdf" includes directory that doesn't exist.
graphics > inclusion > file 'images/drawing.svg' is bugged
...
因此,正在运行的命令是:
inkscape "/tmp/images/drawing.svg" --export-dpi=600 -A --export-pdf="/tmp/images/m_k_i_v_drawing.svg.pdf"
通过命令行运行此命令也会出现相同的错误消息。基于这个 stackexchange 问题,看起来-A
和--export-pdf
指定了相同的选项。因此,当inkscape -A --export-pdf="..."
使用时,inkscape
认为这--export-pdf="..."
是文件的名称。因此,inkscape
应该在不带-A
参数的情况下调用。
为此,请在.tex
文件顶部添加以下内容:
\startluacode
figures.programs.inkscape = {
command = "inkscape",
pdfargument = [[
"%oldname%"
--export-dpi=600
--export-pdf="%newname%"
]],
pngargument = [[
"%oldname%"
--export-dpi=600
--export-png="%newname%"
]],
}
\stopluacode
我还会向 ConTeXt 邮件列表发送一个错误修复。