1# -*- coding: utf-8 -*-
2
3# file fig2pstex.py
4# This file is part of LyX, the document processor.
5# Licence details can be found in the file COPYING.
6#
7# \author Angus Leeming
8# \author Bo Peng
9#
10# Full author contact details are available in file CREDITS
11
12
13# This script converts an XFIG image to something that latex can process
14# into high quality PostScript.
15
16# Usage:
17#   python fig2pstex.py ${base}.fig ${base}.pstex
18# This command generates
19#   ${base}.eps    the converted eps file
20#   ${base}.pstex  a tex file that can be included in your latex document
21#       using '\input{${output}}'.
22#
23# Note:
24#   Do not use this command as
25#     python fig2pstex.py file.fig file.eps
26#   the real eps file will be overwritten by a tex file named file.eps.
27#
28
29from __future__ import print_function
30import os, sys
31
32# We expect two args, the names of the input and output files.
33if len(sys.argv) != 3:
34    sys.exit(1)
35
36input, output = sys.argv[1:]
37
38# Fail silently if the file doesn't exist
39if not os.path.isfile(input):
40    sys.exit(0)
41
42# Strip the extension from ${output}
43outbase = os.path.splitext(output)[0]
44
45# Generate the EPS file
46# Generate the PSTEX_T file
47if os.system('fig2dev -Lpstex %s %s.eps' % (input, outbase)) != 0 or \
48  os.system('fig2dev -Lpstex_t -p%s %s %s' % (outbase, input, output)) != 0:
49  print ('fig2dev fails')
50  sys.exit(1)
51