MyST-NB
MyST-NB copied to clipboard
SVG outputs are rendered as strings in LaTeX
Describe the problem
If the output of an command is of type image/svg+xml
it is included as string output in LaTeX file
Link to your repository or website
No response
Steps to reproduce
- Create notebook with code cell like this
import chess
import chess.svg
board = chess.Board()
board.push(chess.Move.from_uci("d2d4"))
chess.svg.board(board, size=350)
- Generate Output
- Try to create pdf
The version of Python you're using
No response
Your operating system
No response
Versions of your packages
No response
Additional context
This will probably be fixed by fixing #178
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:
@JensHeinrich are you able to add the following to your _config.yml
(jupyter-book)
sphinx:
config:
nb_render_priority:
latex:
- "application/pdf"
- "image/svg+xml"
- "image/png"
- "image/jpeg"
- "text/latex"
- "text/markdown"
- "text/plain"
or conf.py
(sphinx)
nb_render_priority = {
"latex": (
"application/pdf",
"image/svg+xml",
"image/png",
"image/jpeg",
"text/latex",
"text/markdown",
"text/plain",
)
}
Thank you very much This works nicely
Since #380, this is easy to configure for with https://www.sphinx-doc.org/en/master/usage/extensions/imgconverter.html:
extensions = ["sphinx.ext.imgconverter"]
nb_mime_priority_overrides = [
# builder name, mime type, priority
("latex", "image/svg+xml", 15)
]
sphinx.ext.imgconverter
is not enabled by default though, so latex should also not be.
Also, as noted in the link, there are alternative options for SVG -> latex conversion, like https://github.com/missinglinkelectronics/sphinxcontrib-svg2pdfconverter
this could/should be added as a tip to the documentation
For the _config.yml
(jupyter-book) this would be:
sphinx:
config:
nb_mime_priority_overrides:
- - latex
- "image/svg+xml"
- 15
And it seems that the higher the number (15) the higher the priority will be.
Indeed, it is detailed here: https://myst-nb.readthedocs.io/en/latest/render/format_code_cells.html#outputs-mime-priority
I'm trying to render SVGs in pdflatex output from jupyter book and after spending many hours on it I still can't seem to find a solution. I tried putting the following inside _config.yml
but it does not seem to have an effect:
sphinx:
config:
nb_render_priority:
latex:
- "application/pdf"
- "image/svg+xml"
- "image/png"
- "image/jpeg"
- "text/latex"
- "text/markdown"
- "text/plain"
Next I tried adding the following
sphinx:
config:
nb_mime_priority_overrides:
- - latex
- "image/svg+xml"
- 15
which does insert svg as rasters, but the resolution is so low that it is unusable. Is there any way to pass a dpi argument to the imagemagick converter in the yaml config file?
I also tried using https://github.com/missinglinkelectronics/sphinxcontrib-svg2pdfconverter but I don't understand how to write my config file for jupyter book to enable this extension, any tips would be helpful (I tried adding the cairo convert under "extra extensions", but my svgs still odn't show up. (I can't use inkscape or resvg)).
I attach the notebook file I have been trying to render svg-test.ipynb.txt
These are my versions:
Jupyter Book : 0.15.1
External ToC : 0.3.1
MyST-Parser : 0.18.1
MyST-NB : 0.17.2
Sphinx Book Theme : 1.0.1
Jupyter-Cache : 0.6.1
NbClient : 0.7.4
Can confirm, I also get empty output in my pdf where svgs should be...