Attached. Please test.

Method:
python fig2pstex.py file.fig file.pstex
python fig2pdftex.py file1.fig file1.pdftex

You should get valid file.eps, file.pstex, file1.pdf, file1.pdftex.

Bo
Index: lib/scripts/fig2pdftex.py
===================================================================
--- lib/scripts/fig2pdftex.py	(revision 0)
+++ lib/scripts/fig2pdftex.py	(revision 0)
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+# -*- coding: iso-8859-15 -*-
+
+# file fig2pdf.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 pdflatex can process
+# into high quality PDF.
+
+# Usage: python fig2pdf.py ${base}.fig ${base}.pdftex_t
+# Thereafter, you need only '\input{${base}.pdftex_t}' in your latex document.
+
+import os, sys, re
+
+
+def runCommand(cmd):
+    ''' Utility function:
+        run a command, quit if fails
+    '''
+    if os.system(cmd) != 0:
+        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)
+
+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 = '.'.join(output.split('.')[:-1])
+
+# Ascertain whether fig2dev is "modern enough".
+# If it is, then the help info will mention "pdftex_t" as one of the
+# available outputs.
+fout = os.popen('fig2dev -h')
+output = fout.read()
+fout.close()
+
+
+if 'pdftex_t' in output:
+    # Modern versions of xfig can output the image without "special" text as
+    # a PDF file ${base}.pdf and place the text in a LaTeX file
+    # ${base}.pdftex_t for typesetting by pdflatex itself.
+    runCommand('fig2dev -Lpdftex -p1 %s %s.pdf' % (input, outbase))
+    runCommand('fig2dev -Lpdftex_t -p%s %s %s.pdftex_t' % (outbase, input, outbase))
+else:
+    # Older versions of xfig cannot do this, so we emulate the behaviour using
+    # pstex and pstex_t output.
+    runCommand('fig2dev -Lpstex %s %s.pstex' % (input, outbase))
+    runCommand('fig2dev -Lpstex_t -p %s %s %s.pdftex_t' % (outbase, input, outbase))
+
+    # manipulates the Bounding Box info to enable gs to produce
+    # the appropriate PDF file from an EPS one.
+    # The generated PostScript commands are extracted from epstopdf, distributed
+    # with tetex.
+    epsfile = outbase + '.pstex'
+    tmp = open(epsfile + '.??', 'w')
+    boundingboxline = re.compile('%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
+    for line in open(epsfile).xreadlines():
+        if line[:13] == '%%BoundingBox':
+            (llx, lly, urx, ury) = map(int, boundingboxline.search(line).groups())
+            width = urx - llx
+            height = ury - lly
+            xoffset = - llx
+            yoffset = - lly
+            tmp.write('''%%%%BoundingBox: 0 0 %d %d
+<< /PageSize  [%d %d] >> setpagedevice
+gsave %d %d translate
+''' % (width, height, width, height, xoffset, yoffset))
+        else:
+            tmp.write(line)
+    tmp.close()
+    os.rename(epsfile + '.??', epsfile)
+
+    # Convert the ${pstex} EPS file (free of "special" text) to PDF format
+    # using gs
+    runCommand('gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=%s.pdf %s.pstex'\
+      % (outbase, outbase))
+    os.unlink(epsfile)

Property changes on: lib/scripts/fig2pdftex.py
___________________________________________________________________
Name: svn:executable
   + *

Index: lib/scripts/fig2pstex.py
===================================================================
--- lib/scripts/fig2pstex.py	(revision 0)
+++ lib/scripts/fig2pstex.py	(revision 0)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# -*- coding: iso-8859-15 -*-
+
+# 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 ${input} ${output}
+# to generate the pstex_t file ${output}.
+# In turn this file will \includegraphics{${output_base}}.
+# The necessary ${output_base}.eps is also generated by this script.
+#
+# Thereafter, you need only '\input{${output}}' in your latex document.
+
+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 = '.'.join(output.split('.')[:-1])
+
+# 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)

Property changes on: lib/scripts/fig2pstex.py
___________________________________________________________________
Name: svn:executable
   + *

Index: lib/configure.py
===================================================================
--- lib/configure.py	(revision 14261)
+++ lib/configure.py	(working copy)
@@ -391,8 +391,8 @@
 \converter date       dateout    "date +%d-%m-%Y > $$o"	""
 \converter docbook    docbook-xml "cp $$i $$o"	"xml"
 \converter fen        asciichess "python $$s/scripts/fen2ascii.py $$i $$o"	""
-\converter fig        pdftex     "sh $$s/scripts/fig2pdftex.sh $$i $$o"	""
-\converter fig        pstex      "sh $$s/scripts/fig2pstex.sh $$i $$o"	""
+\converter fig        pdftex     "python $$s/scripts/fig2pdftex.py $$i $$o"	""
+\converter fig        pstex      "python $$s/scripts/fig2pstex.py $$i $$o"	""
 \converter lyx        lyx13x     "python $$s/lyx2lyx/lyx2lyx -t 221 $$i > $$o"	""
 ''')
 

Reply via email to