I'm using XeLatex and dvisvgm to produce a .svg file. I want to include a .png image with \includegraphics but it doesn't work: there is a replacement image instead of the one I want.

Here is what I use to compile (overleaf):

    END {
system("xelatex -no-pdf svgbeamer.tex && xelatex -no-pdf svgbeamer.tex && dvisvgm --font-format=ttf --exact --zoom=-1 -p1,- svgbeamer.xdv")

And here is my minimal example:


\setbeamersize{text margin left=0cm} %to get real fullscreen




The same code compiled with only XeLatex works alright.

Any clue?

PS: the image is

enter image description here

  • does dvisvgm make any warnings? Aug 23, 2022 at 17:21
  • I'm not sure where to look
    – FunkiePhil
    Aug 23, 2022 at 22:36
  • Works for me. Note that unlike PDF, PNG is not physically embedded into the output SVG, only linked. Therefore, it should be present in the same directory as the final SVG.
    – AlexG
    Aug 24, 2022 at 6:59
  • Ah I get It, is it the case for any image file type?
    – FunkiePhil
    Aug 24, 2022 at 8:55
  • Except PDF, yes. But it can be worked around. See answer.
    – AlexG
    Aug 24, 2022 at 9:26

1 Answer 1


PNG (and other web compatible bitmap formats like JPEG and GIF) is not physically embedded into the SVG output by dvisvgm, only referenced via external link. Only PostScript and PDF (into which most static bitmap formats may be converted or wrapped using an external converter, such as ImageMagick) are. They remain separate and must be found by the Web browser during run-time.

To make SVG self-sufficient, bitmap files must be base64 encoded and embedded as data:image/png;base64,... data blob. This can be done as follows, patching the graphicx backend driver for dvisvgm.

This requires the media4svg package at a recent version (>= v0.9 2022-08-12).

Typeset with

dvilualatex svgbeamer
dvisvgm --font-format=woff2 --bbox=papersize --zoom=-1 -p1,- svgbeamer


latex --shell-escape svgbeamer
dvisvgm --font-format=woff2 --bbox=papersize --zoom=-1 -p1,- svgbeamer


xelatex --no-pdf --shell-escape svgbeamer
dvisvgm --font-format=woff2 --bbox=papersize --zoom=-1 -p1,- svgbeamer.xdv

%\graphicspath{{myimages}} % add search dirs as needed

% patch graphics backend driver `dvisvgm.def' to physically embed
% bitmaps into DVI

\RequirePackage{media4svg} % provides base64-encode utility

\begin{frame}{Embedded PNG}

  • Would it be useful to add something for base64 encoding to l3kernel?
    – Joseph Wright
    Aug 24, 2022 at 9:46
  • Yes, I think such a tool could come in handy from time to time. Is it possible to read arbitrary binary files bytewise without Lua?
    – AlexG
    Aug 24, 2022 at 11:34

You must log in to answer this question.

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