]> git.lyx.org Git - features.git/commitdiff
Improve the svg2*tex.py scripts.
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 28 Aug 2017 06:00:56 +0000 (08:00 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 28 Aug 2017 06:05:29 +0000 (08:05 +0200)
The inkscape command was hardcoded, but it seems that we need the full
patch on Windows. Therefore we check in configure.py if inkscape is
installed and pass the proper name (and possibly path) to the scripts.

Should address problems mentioned in #10679

lib/configure.py
lib/scripts/svg2pdftex.py
lib/scripts/svg2pstex.py

index 8e7fedbb5ad0aba5c07ea3808455b28a5cae010b..a9f161ef7e2bbeff96e72a7174c67adf8a11c831 100644 (file)
@@ -970,11 +970,17 @@ def checkConverterEntries():
 \converter fig        ppm        "fig2dev -L ppm $$i $$o"      ""
 \converter fig        svg        "fig2dev -L svg $$i $$o"      ""
 \converter fig        png        "fig2dev -L png $$i $$o"      ""
-\converter svg        pdftex     "python -tt $$s/scripts/svg2pdftex.py $$i $$o" ""
-\converter svg        pstex      "python -tt $$s/scripts/svg2pstex.py $$i $$o" ""
 \converter fig        pdftex     "python -tt $$s/scripts/fig2pdftex.py $$i $$o"        ""
 \converter fig        pstex      "python -tt $$s/scripts/fig2pstex.py $$i $$o" ""''')
     #
+    checkProg('a SVG -> PDFTeX converter', [inkscape_name],
+        rc_entry = [ r'\converter svg        pdftex     "python -tt $$s/scripts/svg2pdftex.py %% $$i $$o" ""'],
+        path = [inkscape_path])
+    #
+    checkProg('a SVG -> PSTeX converter', [inkscape_name],
+        rc_entry = [ r'\converter svg        pstex     "python -tt $$s/scripts/svg2pstex.py %% $$i $$o" ""'],
+        path = [inkscape_path])
+    #
     checkProg('a TIFF -> PS converter', ['tiff2ps $$i > $$o'],
         rc_entry = [ r'\converter tiff       eps        "%%"   ""'])
     #
index 6cbd531d5f25b28e0a4b225c60c4ebed6ca7c334..06b542891ccbf642e3659e5ee1a70fa37d247d30 100644 (file)
@@ -7,23 +7,24 @@
 
 # author Daniel Gloger
 # author Martin Vermeer
+# author Jürgen Spitzmüller
 
 # Full author contact details are available in file CREDITS
 
-# This script converts an SVG image to something that pdflatex can process
-# into high quality PDF.
+# This script converts an SVG image to two files that can be processed
+# with pdflatex into high quality PDF. It requires Inkscape.
 
 # Usage:
-#   python svg2pdftex.py ${base}.svg ${base}.pdft
+#   python svg2pdftex.py [inkscape_command] inputfile.svg outputfile.pdf_tex
 # This command generates
-#   ${base}.pdf  the converted pdf file
-#   ${base}.pdft a tex file that can be included in your latex document
-#       using '\input{${base}.pdft}'
+#   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}'
 #
 # Note:
 #   Do not use this command as
-#     python svg2pdftex.py file.svg file.pdf
-#   the real pdf file will be overwritten by a tex file named file.pdf.
+#     python svg2pdftex.py [inkscape_command] inputfile.svg outputfile.pdf
+#   the real PDF file would be overwritten by a TeX file named outputfile.pdf.
 #
 
 import os, sys, re
@@ -36,23 +37,35 @@ def runCommand(cmd):
         print "Command '%s' fails." % cmd
         sys.exit(1)
 
-# We expect two args, the names of the input and output files.
-if len(sys.argv) != 3:
-    sys.exit(1)
+InkscapeCmd = "inkscape"
+InputFile = ""
+OutputFile = ""
 
-input, output = sys.argv[1:]
+# We expect two or three args: the names of the input and output files
+# and optionally the inkscape command (with path if needed).
+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:]
+else:
+    # Invalid number of args. Exit with error.
+    sys.exit(1)
 
 # Fail silently if the file doesn't exist
-if not os.path.isfile(input):
+if not os.path.isfile(InputFile):
     sys.exit(0)
 
-# Strip the extension from ${output}
-outbase = os.path.splitext(output)[0]
+# Strip the extension from ${OutputFile}
+OutBase = os.path.splitext(OutputFile)[0]
 
-# Inkscape 0.48 can output the image as a PDF file ${base}.pdf and place the text 
-# in a LaTeX file ${base}.pdf_tex, which is renamed to ${output}, for typesetting 
-# by pdflatex itself. 
-runCommand('inkscape --file=%s --export-pdf=%s.pdf --export-latex' % (input, outbase))
+# Inkscape (as of 0.48) can output SVG images as a PDF file without text, ${OutBase}.pdf,
+# 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('%s --file=%s --export-pdf=%s.pdf --export-latex' % (InkscapeCmd, InputFile, OutBase))
 
-os.rename('%s.pdf_tex' % outbase, output)
+os.rename('%s.pdf_tex' % OutBase, OutputFile)
 
index 601d2b93305fda067f6b1c1f41a048d4e05fabf9..238afb6eba12e5ca67da0decd4fcf081959aab8c 100644 (file)
@@ -7,25 +7,29 @@
 
 # author Daniel Gloger
 # author Martin Vermeer
-
-# This script converts an SVG image to something that latex can process
-# into high quality PostScript.
+# author Jürgen Spitzmüller
 
 # Full author contact details are available in file CREDITS
 
+# This script converts an SVG image to two files that can be processed
+# with latex into high quality DVI/PostScript. It requires Inkscape.
+
 # Usage:
-#   python svg2pstex.py ${base}.fig ${base}.pstex
+#   python svg2pstex.py [inkscape_command] inputfile.svg outputfile.eps_tex
 # This command generates
-#   ${base}.eps    the converted eps file
-#   ${base}.pstex  a tex file that can be included in your latex document
-#       using '\input{${output}}'.
+#   1. outputfile.eps     -- the converted EPS file (text from SVG stripped)
+#   2. outputfile.eps_tex -- a TeX file that can be included in your
+#                             LaTeX document using '\input{outputfile.eps_text}'
 #
 # Note:
 #   Do not use this command as
-#     python svg2pstex.py file.fig file.eps
-#   the real eps file will be overwritten by a tex file named file.eps.
+#     python svg2pstex.py [inkscape_command] inputfile.svg outputfile.pdf
+#   the real EPS file would be overwritten by a TeX file named outputfile.eps.
 #
 
+# This script converts an SVG image to something that latex can process
+# into high quality PostScript.
+
 import os, sys
 
 def runCommand(cmd):
@@ -36,21 +40,34 @@ def runCommand(cmd):
         print "Command '%s' fails." % cmd
         sys.exit(1)
 
-# We expect two args, the names of the input and output files.
-if len(sys.argv) != 3:
-    sys.exit(1)
+InkscapeCmd = "inkscape"
+InputFile = ""
+OutputFile = ""
 
-input, output = sys.argv[1:]
+# We expect two or three args: the names of the input and output files
+# and optionally the inkscape command (with path if needed).
+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:]
+else:
+    # Invalid number of args. Exit with error.
+    sys.exit(1)
 
 # Fail silently if the file doesn't exist
-if not os.path.isfile(input):
+if not os.path.isfile(InputFile):
     sys.exit(0)
 
-# Strip the extension from ${output}
-outbase = os.path.splitext(output)[0]
+# Strip the extension from ${OutputFile}
+OutBase = os.path.splitext(OutputFile)[0]
+
+# Inkscape (as of 0.48) can output SVG images as an EPS file without text, ${OutBase}.eps,
+# while outsourcing the text to a LaTeX file ${OutBase}.eps_tex which includes and overlays
+# the EPS 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('%s --file=%s --export-eps=%s.eps --export-latex' % (InkscapeCmd, InputFile, OutBase))
+os.rename('%s.eps_tex' % OutBase, OutputFile)
 
-# Inkscape 0.48 can output the image as a EPS file ${base}.pdf and place the text 
-# in a LaTeX file ${base}.eps_tex, which is renamed to ${output}, for typesetting 
-# by latex itself. 
-runCommand('inkscape --file=%s --export-eps=%s.eps --export-latex' % (input, outbase))
-os.rename('%s.eps_tex' % outbase, output)