From 68072a06e5bee6cee05f54847b884500527e53a2 Mon Sep 17 00:00:00 2001 From: Aravindh Krishnamoorthy Date: Tue, 12 Nov 2024 10:53:49 +0100 Subject: [PATCH 1/4] LaTeX and PDF export: Support SVG image files via the svg package --- nbconvert/exporters/pdf.py | 2 +- share/templates/latex/base.tex.j2 | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index 4226b44b7..97843536f 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -60,7 +60,7 @@ class PDFExporter(LatexExporter): latex_count = Integer(3, help="How many times latex will be called.").tag(config=True) latex_command = List( - ["xelatex", "{filename}", "-quiet"], help="Shell command used to compile latex." + ["xelatex", "-shell-escape", "{filename}", "-quiet"], help="Shell command used to compile latex." ).tag(config=True) bib_command = List(["bibtex", "{filename}"], help="Shell command used to run bibtex.").tag( diff --git a/share/templates/latex/base.tex.j2 b/share/templates/latex/base.tex.j2 index 493130b07..2b3c0a8a7 100644 --- a/share/templates/latex/base.tex.j2 +++ b/share/templates/latex/base.tex.j2 @@ -20,8 +20,6 @@ override this.-=)) \usepackage{graphicx} % Keep aspect ratio if custom image width or height is specified \setkeys{Gin}{keepaspectratio} - % Maintain compatibility with old templates. Remove in nbconvert 6.0 - \let\Oldincludegraphics\includegraphics % Ensure that by default, figures have no caption (until we provide a % proper Figure object with a Caption API and a way to capture that % in the conversion process - todo). @@ -93,6 +91,23 @@ override this.-=)) % normalem makes italics be italics, not underlines \usepackage{soul} % strikethrough (\st) support for pandoc >= 3.0.0 \usepackage{mathrsfs} + \usepackage{svg} % enable support for rendering SVGs via Inkscape + \makeatletter + % Hook to includgraphics to pass SVGs to \includesvg + \let\includegraphics@original\includegraphics + % Hook + \renewcommand{\includegraphics}[2][]{% + \def\svgextension{svg} + \filename@parse{#2}% + \ifx\filename@ext\svgextension + \includesvg[#1]{#2} + \else + \includegraphics@original[#1]{#2} + \fi + }% + \makeatother + % Maintain compatibility with old templates. Remove in nbconvert 6.0 + \let\Oldincludegraphics\includegraphics ((* endblock packages *)) ((* block definitions *)) From 5af045677696ddacac6cfe32cc1cba548f6459a7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:05:57 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nbconvert/exporters/pdf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index 97843536f..9936814e8 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -60,7 +60,8 @@ class PDFExporter(LatexExporter): latex_count = Integer(3, help="How many times latex will be called.").tag(config=True) latex_command = List( - ["xelatex", "-shell-escape", "{filename}", "-quiet"], help="Shell command used to compile latex." + ["xelatex", "-shell-escape", "{filename}", "-quiet"], + help="Shell command used to compile latex.", ).tag(config=True) bib_command = List(["bibtex", "{filename}"], help="Shell command used to run bibtex.").tag( From 26565ef3d13fe64ca750b2c171a7222037c173a4 Mon Sep 17 00:00:00 2001 From: Aravindh Krishnamoorthy Date: Wed, 13 Nov 2024 19:26:49 +0100 Subject: [PATCH 3/4] Include width string for \includsvg --- share/templates/latex/base.tex.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/templates/latex/base.tex.j2 b/share/templates/latex/base.tex.j2 index 2b3c0a8a7..7938feaf8 100644 --- a/share/templates/latex/base.tex.j2 +++ b/share/templates/latex/base.tex.j2 @@ -100,7 +100,7 @@ override this.-=)) \def\svgextension{svg} \filename@parse{#2}% \ifx\filename@ext\svgextension - \includesvg[#1]{#2} + \includesvg[width=\textwidth,#1]{#2} \else \includegraphics@original[#1]{#2} \fi From 662649cf777bb3b446d0f77049aaceb01e420cd6 Mon Sep 17 00:00:00 2001 From: Aravindh Krishnamoorthy Date: Wed, 13 Nov 2024 21:28:42 +0100 Subject: [PATCH 4/4] Revert changes to pdf.py --- nbconvert/exporters/pdf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index 9936814e8..4226b44b7 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -60,8 +60,7 @@ class PDFExporter(LatexExporter): latex_count = Integer(3, help="How many times latex will be called.").tag(config=True) latex_command = List( - ["xelatex", "-shell-escape", "{filename}", "-quiet"], - help="Shell command used to compile latex.", + ["xelatex", "{filename}", "-quiet"], help="Shell command used to compile latex." ).tag(config=True) bib_command = List(["bibtex", "{filename}"], help="Shell command used to run bibtex.").tag(