X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Fsvg2pdftex.py;h=74266e55cb94a984ad6d51b96e3d739dcfc98b4e;hb=975f304185eca53d62de8b36e6fc5f95b2da4fd9;hp=86564fac2f27b83f9b525b28cc76db8f65a2ca95;hpb=cac27076ead10684270520670adc6bd004793361;p=features.git diff --git a/lib/scripts/svg2pdftex.py b/lib/scripts/svg2pdftex.py index 86564fac2f..74266e55cb 100644 --- a/lib/scripts/svg2pdftex.py +++ b/lib/scripts/svg2pdftex.py @@ -15,11 +15,12 @@ # with pdflatex into high quality PDF. It requires Inkscape. # Usage: -# python svg2pdftex.py [inkscape_command] inputfile.svg outputfile.pdf_tex +# python svg2pdftex.py [--unstable] [inkscape_command] inputfile.svg outputfile.pdf_tex # This command generates # 1. outputfile.pdf -- the converted PDF file (text from SVG stripped) # 2. outputfile.pdf_tex -- a TeX file that can be included in your # LaTeX document using '\input{outputfile.pdf_text}' +# use --unstable for inkscape < 1.0 # # Note: # Do not use this command as @@ -43,16 +44,29 @@ def runCommand(cmd): InkscapeCmd = "inkscape" InputFile = "" OutputFile = "" +unstable = False -# We expect two or three args: the names of the input and output files -# and optionally the inkscape command (with path if needed). +# We expect two to four args: the names of the input and output files +# and optionally the inkscape command (with path if needed) and --unstable. args = len(sys.argv) if args == 3: # Two args: input and output file only InputFile, OutputFile = sys.argv[1:] elif args == 4: - # Three args: first arg is inkscape command - InkscapeCmd, InputFile, OutputFile = sys.argv[1:] + # Three args: check whether we have --unstable as first arg + if sys.argv[1] == "--unstable": + unstable = True + InputFile, OutputFile = sys.argv[2:] + else: + InkscapeCmd, InputFile, OutputFile = sys.argv[1:] +elif args == 5: + # Four args: check whether we have --unstable as first arg + if sys.argv[1] != "--unstable": + # Invalid number of args. Exit with error. + sys.exit(1) + else: + unstable = True + InkscapeCmd, InputFile, OutputFile = sys.argv[2:] else: # Invalid number of args. Exit with error. sys.exit(1) @@ -68,7 +82,10 @@ OutBase = os.path.splitext(OutputFile)[0] # while outsourcing the text to a LaTeX file ${OutBase}.pdf_tex which includes and overlays # the PDF image and can be \input to LaTeX files. We rename the latter file to ${OutputFile} # (although this is probably the name it already has). -runCommand([r'%s' % InkscapeCmd, '--file=%s' % InputFile, '--export-pdf=%s.pdf' % OutBase, '--export-latex']) +if unstable: + runCommand([r'%s' % InkscapeCmd, '--file=%s' % InputFile, '--export-pdf=%s.pdf' % OutBase, '--export-latex']) +else: + runCommand([r'%s' % InkscapeCmd, '%s' % InputFile, '--export-filename=%s.pdf' % OutBase, '--export-latex']) os.rename('%s.pdf_tex' % OutBase, OutputFile)