[Tex/LaTex] How to put a bounding box around a poorly saved .SVG image

graphicssvg

! LaTeX Error: Cannot determine size of graphic in ./queen-diamond-red.svg (no
BoundingBox).

How do I put proper bounding boxes into an .SVG file? I tried

viewBox="0 0 156 156"

I attached the files in my test case of SVG include. I get a different answer for no postfix and with prefix. With a .svg postfix the log records "! LaTeX Error: Cannot determine size of graphic in ./queen-diamond-red.svg (no
BoundingBox).
"

Without the .svg postfix, the log file says it can't find the file with error:

"! LaTeX Error: File `queen-diamond-red.pdf_tex' not found."

\documentclass{article}
\usepackage[inkscape=/usr/bin/inkscape]{svg}
\usepackage{amsmath}
\begin{document}

\begin{figure}[test]
  \centering
  \includesvg[width=156px,height=156px]{queen-diamond-red.svg}
  \caption{svg image}
\end{figure}

\end{document}

svg-test.log

example SVG file with no bounding box?

Best Answer

I think you are using latex you need to use

pdflatex --shell-escape svg-test

and also it seems that you need to not put the extension in the file, and do not use px units, in fact there is no need to specify the height and width at all.

\documentclass{article}
\usepackage{svg}
\usepackage{amsmath}
\begin{document}

\begin{figure}
  \centering
  \includesvg{queen-diamond-red}
  \caption{svg image}
\end{figure}

\end{document}

Unrelated, but I removed [test] as figure does not take an optional argument of that form.

I have checked the above works with the svg file that you posted.

It would be much simpler of course to save the file as pdf from inkscape and use \includegraphics. As it is the original inkscape is being saved as pdf then pdflatex is instructing inkscape to convert it into pdf each time so that it can be included into the document.