X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Ffig2pstex.py;h=aaf3a1bd3afa5323d0b80f7013548d2829400168;hb=aa0afef0c903367f14a9022d48b2a09497c0b142;hp=741665736f3f97cfb785bf64027df7bcd7ea6605;hpb=08ad6acd9a4de15fcc3631631915eff9a2cd03dc;p=lyx.git diff --git a/lib/scripts/fig2pstex.py b/lib/scripts/fig2pstex.py index 741665736f..aaf3a1bd3a 100644 --- a/lib/scripts/fig2pstex.py +++ b/lib/scripts/fig2pstex.py @@ -1,23 +1,49 @@ -#! /usr/bin/env python -# This script converts a xfig file into Postscript/LaTeX files - -import sys -import os - -filename = sys.argv[1] -basename = os.path.splitext(filename)[0] -parameters = sys.argv[2:] - -pid = os.fork() -if pid == 0: - os.execvp("fig2dev", ["fig2dev", "-Lpstex"] + parameters + [filename, basename + ".eps"]) - print "fig2dev did not work" - os.exit(1) -os.wait() - -pid = os.fork() -if pid == 0: - os.execvp("fig2dev", ["fig2dev", "-Lpstex_t", "-p" + basename] + parameters + [filename, basename + ".pstex_t"]) - print "fig2dev did not work the second time" - os.exit(1) -os.wait() +# -*- coding: utf-8 -*- + +# file fig2pstex.py +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. +# +# \author Angus Leeming +# \author Bo Peng +# +# Full author contact details are available in file CREDITS + + +# This script converts an XFIG image to something that latex can process +# into high quality PostScript. + +# Usage: +# python fig2pstex.py ${base}.fig ${base}.pstex +# 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}}'. +# +# Note: +# Do not use this command as +# python fig2pstex.py file.fig file.eps +# the real eps file will be overwritten by a tex file named file.eps. +# + +import os, sys + +# We expect two args, the names of the input and output files. +if len(sys.argv) != 3: + sys.exit(1) + +input, output = sys.argv[1:] + +# Fail silently if the file doesn't exist +if not os.path.isfile(input): + sys.exit(0) + +# Strip the extension from ${output} +outbase = os.path.splitext(output)[0] + +# Generate the EPS file +# Generate the PSTEX_T file +if os.system('fig2dev -Lpstex %s %s.eps' % (input, outbase)) != 0 or \ + os.system('fig2dev -Lpstex_t -p%s %s %s' % (outbase, input, output)) != 0: + print 'fig2dev fails' + sys.exit(1)