File: fig2pstex.py

package info (click to toggle)
lyx 2.5.0~RC2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 138,212 kB
  • sloc: cpp: 244,227; ansic: 106,398; xml: 72,791; python: 39,384; sh: 7,666; makefile: 6,586; pascal: 2,143; perl: 2,101; objc: 1,084; tcl: 163; sed: 16
file content (47 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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(f'fig2dev -Lpstex {input} {outbase}.eps') != 0 or \
  os.system(f'fig2dev -Lpstex_t -p{outbase} {input} {output}') != 0:
  print ('fig2dev fails')
  sys.exit(1)