Skip to content

Commit

Permalink
LaTeX and PDF export: Support SVG image files via the svg package
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindh-krishnamoorthy committed Nov 12, 2024
1 parent 6e5fdb3 commit 68072a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 17 additions & 2 deletions share/templates/latex/base.tex.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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 *))
Expand Down

0 comments on commit 68072a0

Please sign in to comment.