+ return success
+
+
+def color_pdf(latex_file, bg_color):
+ use_preview_pdf_re = re.compile("(\s*\\\\usepackage\[[^]]+)(pdftex\]{preview})")
+
+ tmp = mkstemp()
+
+ success = 0
+ try:
+ for line in open(latex_file, 'r').readlines():
+ match = use_preview_pdf_re.match(line)
+ if match == None:
+ tmp.write(line)
+ continue
+ success = 1
+ tmp.write(" \\usepackage{color}\n" \
+ " \\pagecolor[rgb]{%s}\n" \
+ "%s\n" \
+ % (bg_color, match.group()))
+ continue
+
+ except:
+ # Unable to open the file, but do nothing here because
+ # the calling function will act on the value of 'success'.
+ warning('Warning in color_pdf! Unable to open "%s"' % latex_file)
+ warning(`sys.exc_type` + ',' + `sys.exc_value`)
+
+ if success:
+ copyfileobj(tmp, open(latex_file,"wb"), 1)