5 This file is part of LyX, the document processor.
6 Licence details can be found in the file COPYING
7 or at http://www.lyx.org/about/licence.php3
10 Full author contact details are available in the file CREDITS
11 or at http://www.lyx.org/about/credits.php
14 python clean_dvi.py infile.dvi outfile.dvi
16 clean_dvi modifies the input .dvi file so that
17 dvips and yap (a dvi viewer on Windows) can find
18 any embedded PostScript files whose names are protected
22 1 translating the machine readable .dvi file to human
24 2 manipulating any references to external files
25 3 translating the .dtl file back to .dvi format.
27 It requires dv2dt and dt2dv from the DTL dviware package
28 http://www.ctan.org/tex-archive/dviware/dtl/
34 return 'Usage: %s in.dvi out.dvi\n' \
35 % os.path.basename(prog_name)
39 sys.stderr.write(message + '\n')
43 sys.stderr.write(message + '\n')
47 def manipulated_dtl(data):
48 psfile_re = re.compile(r'(.*PSfile=")(.*)(" llx=.*)')
50 lines = data.split('\n')
51 for i in range(len(lines)):
53 match = psfile_re.search(line)
55 file = match.group(2).replace('"', '')
57 % ( match.group(1), file, match.group(3) )
59 return '\n'.join(lines)
63 # First establish that the expected information has
64 # been input on the command line and whether the
65 # required executables exist.
72 if not os.path.exists(infile):
73 error('Unable to read "%s"\n' % infile)
75 # Convert the input .dvi file to .dtl format.
76 dv2dt_call = 'dv2dt "%s"' % infile
77 dv2dt_stdin, dv2dt_stdout, dv2dt_stderr = \
78 os.popen3(dv2dt_call, 't')
81 dv2dt_data = dv2dt_stdout.read()
82 dv2dt_status = dv2dt_stdout.close()
84 if dv2dt_status != None or len(dv2dt_data) == 0:
85 dv2dt_err = dv2dt_stderr.read()
86 error("Failed: %s\n%s\n" % ( dv2dt_call, dv2dt_err) )
88 # Manipulate the .dtl file.
89 dtl_data = manipulated_dtl(dv2dt_data)
91 error("Failed to manipulate the dtl file")
93 # Convert this .dtl file back to .dvi format.
94 dt2dv_call = 'dt2dv -si "%s"' % outfile
95 dt2dv_stdin = os.popen(dt2dv_call, 'w')
96 dt2dv_stdin.write(dtl_data)
99 if __name__ == "__main__":