jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.73k stars 566 forks source link

Conversion to pdf with SVG fails at includegraphics #1517

Open chris-hld opened 3 years ago

chris-hld commented 3 years ago

When trying to convert a notebook with svg files in it, nbconvert calls Inkscape correctly. However, in the resulting latex file, the call remains as

\(0.5\)\includegraphics{figs/myfigure.svg}

Resulting in the error

LaTeX Error: Cannot determine size of graphic in figs/myfigure.svg (no Bounding Box).

Am I missing a step, or is some further pre-processor needed to replace that line in the latex file? \includegraphics is not capable of svg from what I can see.

Nbconvert version: 6.0.7 - conda

shreve commented 3 years ago

Is this issue still occurring? I would think that would be covered by this line: https://github.com/jupyter/nbconvert/blob/master/share/jupyter/nbconvert/templates/latex/document_contents.tex.j2#L45

rschroll commented 3 years ago

I'm seeing the same problem, also in nbconvert 6.0.7.

FWIW, I have a TinyTeX installation. Although I don't see any error messages about missing packages, that would be a possibility.

chris-hld commented 3 years ago

Yep, still fails. I think there is a fundamental issue. \includegraphic is not compatible with svg. However, from what I can see https://github.com/jupyter/nbconvert/blob/d7c286b9bd07a8670d8ab08469c2e266140522c1/share/jupyter/nbconvert/templates/latex/document_contents.tex.j2#L53 calls with filename, where it should be the output of the svg conversion instead.

Could that be it?

chris-hld commented 3 years ago

Some more details if I run jupyter-nbconvert --debug --to latex notebook.ipynb and then inspect the resulting .tex file I can also see that the include remains as \includegraphics{figs/myfig1.png} whereas I would expect it to look something like \includegraphics{notebook_files/notebook_slidenumber.png}

Similarly, the include to an svg remains as \includegraphics{figs/myfig2.svg} whereas I would expect it to point to the converted pdf \includegraphics{notebook_files/notebook_slidenumber.pdf}

felker commented 3 years ago

This is still an issue in nbconvert version 6.1.0

riziles commented 1 year ago

Is this issue still occurring? I would think that would be covered by this line: https://github.com/jupyter/nbconvert/blob/master/share/jupyter/nbconvert/templates/latex/document_contents.tex.j2#L45

@shreve , I am having this issue, and I was hoping your link would provide some hints as to how to resolve, but the link appears to be broken.

shreve commented 1 year ago

@riziles I believe it was this line: https://github.com/jupyter/nbconvert/blob/6.x/share/jupyter/nbconvert/templates/latex/document_contents.tex.j2#L45

Or the newer file location: https://github.com/jupyter/nbconvert/blob/main/share/templates/latex/document_contents.tex.j2

chris-hld commented 1 year ago

The issue came from the resulting latex call with \includegraphics{figs/myfig.svg}. Includegraphics can not handle svg files, therefore, there was a pre-processor script converting the svg files to pdf, which can be included with includegraphics. However, the resulting includegraphics command should now point to the converted pdf, not to the original svg. When I looked at the produced intermediate latex file it was clear that this path never got replaced/updated to the converted file. In fact, none of the figure path were actually pointing to the notebook_files/ folder where all graphics were copied into, but they all remained at the path given in the original jupyter notebook.

riziles commented 1 year ago

I will try upgrading and see if that solves. I actually just wrote a script to manually convert all the images because I couldn't find any other workaround.

decimad commented 2 months ago

This issue still persists. How can this not be addressed since more than 2 years?

riziles commented 1 month ago

@decimad , I'd recommend using MyST or Quarto to convert notebooks to LaTeX, Typst or PDF. Both of them support svgs.