From 5686430a862be296a82f516750348962695ad36c 2013-07-15 23:15:33 From: Jonathan Frederic Date: 2013-07-15 23:15:33 Subject: [PATCH] Mac OSX support for svg converter --- diff --git a/IPython/nbconvert/transformers/svg2pdf.py b/IPython/nbconvert/transformers/svg2pdf.py index a68e0a6..15a37a0 100644 --- a/IPython/nbconvert/transformers/svg2pdf.py +++ b/IPython/nbconvert/transformers/svg2pdf.py @@ -23,7 +23,8 @@ from .convertfigures import ConvertFiguresTransformer # Constants #----------------------------------------------------------------------------- -INKSCAPE_COMMAND = "inkscape --without-gui --export-pdf=\"{to_filename}\" \"{from_filename}\"" +INKSCAPE_COMMAND = 'inkscape --without-gui --export-pdf="{to_filename}" "{from_filename}"' +INKSCAPE_OSX_COMMAND = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape --without-gui --export-pdf="{to_filename}" "{from_filename}"' #----------------------------------------------------------------------------- @@ -56,10 +57,15 @@ class ConvertSvgTransformer(ConvertFiguresTransformer): with open(input_filename, 'w') as f: f.write(data) + #Determine command (different on Mac OSX) + command = INKSCAPE_COMMAND + if sys.platform == 'darwin': + command = INKSCAPE_OSX_COMMAND + #Call conversion application output_filename = os.path.join(tmpdir, 'figure.pdf') - shell = INKSCAPE_COMMAND.format(from_filename=input_filename, - to_filename=output_filename) + shell = command.format(from_filename=input_filename, + to_filename=output_filename) subprocess.call(shell, shell=True) #Shell=True okay since input is trusted. #Read output from drive