I'm generating an .epub with tex4ebook. Most of the graphics I want to include are svg. If I include them with \includesvg, and specify the graphics path with \svgpath, I can compile the document with pdflatex without any issues. When I tried to compile with tex4ebook, tex4ht couldn't find the .svg files. When I changed \svgpath to \graphicspath, tex4ht was able to include the graphics, but the svgs were not resized according to the dimensions given to \includesvg.

I tried this workaround, but the images were still not resized correctly:


Then I replaced \includesvg with \includegraphics, and the svg was included with the correct dimensions. The dimensions for the svgs were correct even though only one dimension was provided in many cases, and there was no .xbb file.

The recommendations that I've found suggest generating an .xbb file (after converting svg to jpg, pdf, or png) to give tex4ht the dimensions for the graphic, but the fact that this isn't necessary for includegraphics suggests that I could tell tex4ht how to get the dimensions from \includesvg in a .cfg file. If someone could suggest how I could do that, I would really appreciate it.

Below I've included an mwe demonstrating how tex4ebook handles svgs provided with \includesvg and \includegraphics.

Here's a screenshot of the .epub:




\caption{Image generated with includegraphics}

\caption{Image generated with includesvg}




   {\ifvmode\IgnorePar\fi\EndP\HCode{<div class="figure">}%
    \bgroup \Configure{float}{\ShowPar}{}{}%

\Css{div.caption {text-align:center;font-size:83\%;text-indent:0em; margin-left:2em; margin-right:2em; }}





<?xml version='1.0' encoding='utf-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns='http://www.w3.org/1999/xhtml'> 
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='originator' /> 
<!--  charset=utf-8,epub,uni-html4,html,xhtml  --> 
<meta content='mwe.tex' name='src' /> 
<link href='mwe.css' type='text/css' rel='stylesheet' /> 
   <div class='figure'>                                                                  
<a id='x1-21'></a>                                                                 
<br /> <div class='caption'><span class='id'>Figure 1: </span><span class='content'>Image generated with includegraphics</span></div><!-- tex4ht:label?: x1-21  -->
<img style='width:50%;max-height:50%;' src='./images/simplefrog.svg' alt='PIC' />                                                                  
   <div class='figure'>                                                                  
<a id='x1-32'></a>                                                                  
<br /> <div class='caption'><span class='id'>Figure 2: </span><span class='content'>Image generated with includesvg</span></div><!-- tex4ht:label?: x1-32  -->
<img style='width:20.95%;max-height:20.95%;' src='./images/simplefrog.svg' alt='PIC' />                                                                  

The log file is very long, so I decided to only include the parts that I thought were relevant for graphics processing.

Package: graphicx 2020/09/09 v1.2b Enhanced LaTeX Graphics (DPC,SPQR)
version 2020-10-17-13:53
) (/usr/share/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2020/08/30 v1.4c Standard LaTeX Graphics (DPC,SPQR)
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
) (/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
Package graphics Info: Driver file: dvips.def on input line 105.
File: dvips.def 2017/06/20 v3.1d Graphics/color driver for dvips
)) (/usr/share/texmf-dist/tex/latex/base/inputenc.sty
Package: inputenc 2020/08/01 v1.3d Input encoding file
) (/usr/share/texmf-dist/tex/latex/svg/svg.sty
Package: svg 2020/11/26 v2.02k (include SVG pictures)

) (/usr/share/texmf-dist/tex/latex/pgf/systemlayer/pgfsys.sty (/usr/share/texmf
-dist/tex/latex/pgf/utilities/pgfrcs.sty (/usr/share/texmf-dist/tex/generic/pgf
(/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-lists.tex)) (/u
) (/usr/share/texmf-dist/tex/generic/pgf/utilities/pgfrcs.code.tex (/usr/share/
Package: pgfrcs 2020/12/01 v3.1.7a (3.1.7a)
)) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsys.code.tex
Package: pgfsys 2020/12/01 v3.1.7a (3.1.7a)
File: pgf.cfg 2020/12/01 v3.1.7a (3.1.7a)
Driver file for pgf: pgfsys-tex4ht.def
File: pgfsys-tex4ht.def 2020/12/01 v3.1.7a (3.1.7a)
File: pgfsys-common-svg.def 2020/12/01 v3.1.7a (3.1.7a)
version 2020-10-17-13:53
))) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsyssoftpath.code.tex
File: pgfsyssoftpath.code.tex 2020/12/01 v3.1.7a (3.1.7a)
) (/usr/share/texmf-dist/tex/generic/pgf/systemlayer/pgfsysprotocol.code.tex
File: pgfsysprotocol.code.tex 2020/12/01 v3.1.7a (3.1.7a)
)) (./mwe.cfg (/usr/share/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
version 2020-03-12-14:03
l.13 --- TeX4ht warning --- File `"./images/simplefrog.xbb"' not found ---
l.13 --- TeX4ht warning --- Cannot determine size of graphic in "./images/simpl
efrog.xbb" (no BoundingBox) ---
l. 13 --- needs --- ./images/simplefrog.svg ---

] [4

] [5

l.20 --- TeX4ht warning --- File `"./images/simplefrog.xbb"' not found ---
l.20 --- TeX4ht warning --- Cannot determine size of graphic in "./images/simpl
efrog.xbb" (no BoundingBox) ---
l. 20 --- needs --- ./images/simplefrog.svg ---

Since the bounding box is not available, I changed \Configure{Gin-dim} to \Configure{Gin-dim+}, and I got this error when I tried to compile:

[ERROR]   htlatex: ./mwe.cfg    19   LaTeX Error: Missing \begin{document} in `mwe.cfg'.

1 Answer 1


The problem is that the current version of TeX4ht configuration file for svg.sty doesn't pass dimension parameters to \includegraphics, so images are displayed at their original size.

Here is a better version, which constructs correct dimensions for \includegraphics and it also support \svgpath. Save this code as svg.4ht:

% svg.4ht (2018-12-30-09:31), generated from tex4ht-4ht.tex
% Copyright 2018 TeX Users Group
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
% This work has the LPPL maintenance status "maintained".
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2018-12-30-09:31}

  % get file name with \svgpath support
  % set keys
    % convert supported parameters from \includesvg for use with \includegraphics
    \typeout{SVG file #1 cannot be found}


It redefines the \includesvg command. It gets the SVG filename thanks to \svg@get@path. Most of the code constructs dimensions for \includegraphics using code that comes from svg.sty. Only width, height and angle parameters are supported. TeX4ht version of \includegraphics supports direct inclusion of SVG files, so nothing more is needed.

Here is a modified example:



\caption{Image generated with includegraphics}

\caption{Image generated with includesvg}


And this is the rendered HTML file:

enter image description here

  • That works, thanks! Also, the dancing frogs are great :D
    – avren
    Feb 10, 2021 at 22:38
  • 1
    @avren I've updated TeX4ht sources, so it should be available in TL soon :)
    – michal.h21
    Feb 10, 2021 at 22:57

You must log in to answer this question.

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