1

I'm trying to make SVG versions of my TikZ pictures with the dvisvgm driver described in the manual, but I'm stuck on pictures that include PDF images.

Example:

Content of red_circle.tex, to make the PDF to be included:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw [red,line width=2mm] (0,0) circle [radius=1];
\end{tikzpicture} 
\end{document}

Content of picture.tex:

\documentclass[tikz,dvisvgm]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw [line width=4mm] (0,0) -- (1.5,1.5);
    \node [draw,blue!50!white,line width=2mm,opacity=0.5]
          {\includegraphics{red_circle}};
\end{tikzpicture}
\end{document}

The first file is just an example to get something to include in the second file. Here I build red_circle.pdf with pdflatex.

Now I try to build the SVG from the second file like this:

latex picture
dvisvgm picture

but the first command fails with LaTeX Error: File red_circle not found.

The only way I found to compile this file is by first converting red_circle.pdf to EPS. But the result looks awful: the circle is badly rasterized and transparency is lost:

Bad result

instead of

Expected result

Is there a way to make such inclusion work?

Edit: as suggested by David I can convert red_circle.pdf to SVG or PNG. This works if I write the extension explicitly in the \includegraphics call. There are two issues however:

  • the node opacity is not applied to the included image
  • the image is included by reference to another file: picture.svg includes code such as <image height='83.14932' width='83.14932' xlink:href='red_circle.svg'/> which is a bit messy and doesn't work in all viewers (for example I cannot post-process the file with convert from ImageMagick).

Edit 2: As noted by AlexG I just need to specify .pdf in the \includegraphics call.

6
  • 2
    you could (perhaps) convert the pdf to svg then reference the svg file, the dvisvgm manual says svg png and jpg are supported (so not eps or pdf) Nov 19, 2021 at 14:23
  • @DavidCarlisle thanks for the suggestion! It sort of works but is far from optimal (see edit at the bottom of the question).
    – jeremie
    Nov 19, 2021 at 14:58
  • 1
    If I append .pdf I get the expected result.
    – AlexG
    Nov 19, 2021 at 15:15
  • Hehe how could I miss that :) thanks!
    – jeremie
    Nov 19, 2021 at 15:26
  • Should this question be deleted? I guess it can still be useful for people who make the same mistake...
    – jeremie
    Nov 19, 2021 at 15:28

1 Answer 1

1

The file extension .pdfis missing in the list of extensions

\def\Gin@extensions{.svg,.eps,.png,.jpg,.jpeg}

in the graphic[sx] driver file dvisvgm.def.

Also, the extension list from dvisvgm.def gets overwritten with an outdated setting by other driver packages in the loading sequence. Therefore, svg, png, jpeg are forgotten as well.

To re-enable support for those graphics formats, re-read dvisvgm.def in the preamble and manually add .pdf:

\documentclass[tikz,dvisvgm]{standalone}

\makeatletter
\input{dvisvgm.def}
\makeatother

\DeclareGraphicsExtensions{.pdf}

\begin{document}
\begin{tikzpicture}
    \draw [line width=4mm] (0,0) -- (1.5,1.5);
    \node [draw,blue!50!white,line width=2mm,opacity=0.5]
          {\includegraphics{red_circle}};
\end{tikzpicture}
\end{document}

This is a bug and should be reported to the LaTeX team.

5
  • These fixes don't seem to work on my system (TeX Live 2020): either fixing dvisvgm.def or adding the line in the preamble, I still get LaTeX Error: File red_circle not found. Note that without explicit extension it also fails to find SVG, PNG and JPEG files. It seems only EPS is found by default.
    – jeremie
    Nov 19, 2021 at 16:10
  • Fixing dvisvgm.def alone does not seem to be enough, as \Gin@extensions gets overwritten by other driver packages. However, \DeclareGraphicsExtensions{.pdf} added to the preamble (just before \begin{document}) gets it right. I tested this with TL20 and TL21.
    – AlexG
    Nov 19, 2021 at 16:36
  • Ah sorry the preamble line is working indeed. But if the correct fix was to change \Gin@extensions, it should work already for PNG, JPEG and SVG files. So there must be another issue too (or does it work for you when you include e.g. a PNG without explicit extension?)
    – jeremie
    Nov 19, 2021 at 16:48
  • As I said, \Gin@extensions gets overwritten with an outdated list by other pkgs. See edited answer.
    – AlexG
    Nov 19, 2021 at 17:01
  • I see, thanks for looking into the details.
    – jeremie
    Nov 19, 2021 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .