# xelatex and \DeclareGraphicsRule

In a previous question, motivated from my use of nbconvert, I asked about including a pdf file when the \includegraphics command explicitly referenced a svg file. Now nbconvert uses no more pdflatex but uses xelatex instead, and this is relevant...

Ulrike Fischer's accepted answer to the question referenced above,

...
\usepackage{etoolbox}
\makeatletter
\preto\Gin@extensions{svg,}
\DeclareGraphicsRule{.svg}{pdf}{.pdf}{\noexpand\Gin@base.pdf}
\makeatother
...


works like a charm with both pdflatex and lualatex but fails with xelatex, e.g.

$cat text1.tex \documentclass{standalone} \usepackage{graphicx,etoolbox} \makeatletter \preto\Gin@extensions{svg,} \DeclareGraphicsRule{.svg}{pdf}{.pdf}{\noexpand\Gin@base.pdf} \makeatother \begin{document} \includegraphics{trab1_conv.svg} \end{document}$ xelatex text1
...
! LaTeX Error: Cannot determine size of graphic in trab1_conv.pdf (no BoundingBox).
...
No pages of output.
Transcript written on text1.log.
$ To make me more confused, trab1_conv.pdf is a perfectly sane pdf, $ perl -pi.bak -e s/conv.svg/conv.pdf/ text1.tex
$xelatex text1 ... <use "trab1_conv.pdf" > [1] (./text1.aux) ) Output written on text1.pdf (1 page). Transcript written on text1.log.$


It is easy to circumvent the problem (just generate the .tex file and run pdflatex on it) but I'd like to understand what is happening between XeLaTeX an \declareGraphicsRule.

Tia — g

ps: the recipe to produce the external files is

latex trab1_conv.tex ; pdf2svg trab1_conv.pdf trab1_conv.svg


where trab1_conv.tex produces a standalone image of your liking.

• XeTeX doesn't produce PDF directly, unlike pdfTeX and LuaTeX. So you would need to take account of the backend you are using, I think, since all graphics-inclusion stuff is backend-dependent, as I understand it. And XeTeX can use at least two different backends, I think, so it might depend on which you are using. – cfr May 8 '17 at 22:12

XeTeX pass graphics type like pdf (or png) to the QuickTime library to get their bounding box. The problem is that it quite stubbornly insist to pass the original file and seems not to contain code to declare an alias extension to use instead to get the file size. You can try the following. I didn't test it extensively but imho it shouldn't disturb other graphic formats:

 \documentclass[a4paper,12pt]{book}

\usepackage{graphicx}
\usepackage{etoolbox}

\usepackage{ifxetex}

\makeatletter
\preto\Gin@extensions{svg,}

\ifxetex
\DeclareGraphicsRule{.svg}{QTm}{QTm}{\noexpand\Gin@base.pdf}