Closed linsui closed 3 months ago
This seems to be a bug in the dvisvgm backend of LaTeX/XeLaTeX. It creates a pdf:image
special to reference the PNG file which dvisvgm doesn't support. Here's a excerpt of the XDV file:
xxx: 'dvisvgm:raw <g fill="#000">{?nl} '
xxx: 'dvisvgm:raw <g stroke="none"> '
push:
push:
xxx: 'pdf:image bbox 0 0 479.20183 289.91212 clip 0 width 28.45274pt (./test.png) '
pop:
pop:
right: 28.452744pt
xxx: 'dvisvgm:raw </g> '
xxx: 'dvisvgm:raw </g>{?nl} '
The missing image in the SVG is expected here and therefore not a bug in dvisvgm. The issue must be fixed in the dvisvgm driver provided by the LaTeX team.
TikZ provides its own dvisvgm
backend driver for graphics inclusion, which overrides the one (dvisvgm.def
) provided by the graphic[xs]
/graphics-def
package. (Disclaimer: I edited the current version 2020/03/22 v1.2
of dvisvgm.def
.)
The TikZ driver for dvisvgm
seems to be outdated regarding graphics inclusion. Maybe it is worth notifying its author, @hmenke, about this.
As a quick fix you can force using dvisvgm.def
:
\documentclass[tikz, margin=3pt, dvisvgm]{standalone}
\usepackage{graphicx}
% force dvisvgm.def from pkg graphics-def
\makeatletter
\input{dvisvgm.def}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [draw] {\includegraphics[width=1cm]{example-image.png}};
\end{tikzpicture}
\end{document}
Grrr. That's also a problem of standalone
with its nice implicit package loading (e.g. the tikz
package option). I'll see what needs to be fixed in PGF.
Thanks! The quick fix works well with my tikz picture. Without tikz (the second case) the image is still missing. Is this expected? I don't know how these tools work so this may be a stupid question.
Works for me (test.png
replaced with example-image.png
).
Make sure the PNG is in the current directory for the web browser to find it. Unlike PDF/PS, included PNG is not inlined in the output SVG.
I've investigated. It's not the fault of PGF but of xcolor
(which is loaded by PGF). MWE:
\documentclass[dvisvgm]{standalone}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\includegraphics[width=1cm]{example-image.png}
\end{document}
It looks like xcolor
doesn't inspect \Gin@driver
but just loads xetex.def
because that's the engine that has been detected.
Yes, I remember. I once found out this too. xcolor
doesn't know about dvisvgm
. I even contacted its author (in April 2020) and asked for including dvisvgm.def
in xcolor
's set-up, but he did not reply.
To make xcolor
aware of dvisvgm
, I suggested the following line to be updated in xcolor.sty
:
\@tfor\@@tmp:={dvipdf}{dvipdfm}{dvipdfmx}{dvips}{dvipsone}{dvisvgm}{dviwin}%
{emtex}{luatex}{pctex32}{pctexhp}{pctexps}{pctexwin}{pdftex}%
{tcidvi}{textures}{truetex}{vtex}{xetex}\do
Fooling xcolor
by loading it as the first package works as well. (There is a related topic on TeX.SX: https://tex.stackexchange.com/a/537711 )
\RequirePackage{xcolor}
\documentclass[tikz, margin=3pt, dvisvgm]{standalone}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\node [draw] {\includegraphics[width=1cm]{example-image.png}};
\end{tikzpicture}
\end{document}
The generate svg file is
The generate svg file is
I generate the svg with