Thursday, July 5, 2012

Camera Ready

Creating the camera ready version of papers is a nuisance. Today, I spend 2 hours to try to conform with all the requirements of an IEEE journal. Some of the frustrating aspects have to deal with the fact that they want to all images in EPS format and, as a mac user, I used pdf. It is easy to convert all the pdf to eps using pdftops. You can use the below find command to covert all files in a directory:

find . -name "*.pdf"  -exec pdftops -eps {} \;

The other difficulty was related doflattening the tex files and including the bibliography rather than the bib file. So I would not have to deal with this nonsense again, I wrote a short script to do this for me. I hope to expand this in the future to also handle the renaming of the figures in order of appearance; but for now that remains a manual step. The scrip is attached to the end this post



"""
This script helps generate the camera ready version of papers.
- it flattens the latex file by including all dependencies (recursively)
- it includes the bibliography from a bbl removing the need for a bib file

TODO:
- automatically rename the figures in order of their apparence in the paper
"""
import re
import sys


all_lines = []
r_input = re.compile("\\\\input\{([a-zA-Z].*)\}")

def add_line(line):
 #if (line.startswith("%") == False):
 # all_lines.append(line);
 all_lines.append(line);
  
def process_line(line):
 m = r_input.match(line)
 if (m != None):
  input_file = "%s.tex" % m.groups()[0]
  print "including tex from", input_file
   
  f = open(input_file, "r");
  lines = f.readlines() 
  f.close();
   
  for line in lines: process_line(line);
     
 elif (line.startswith("\\bibliography{")):
  print "including bib from", f_bib
  f = open(f_bib, "r")
  lines = f.readlines();
  f.close()
   
  for line in lines: process_line(line);
 else:
  #print "[%s]" % line, line.find("\\bibliography{"), line.startswith("\\bibliography{")
  add_line(line)

if __name__ == "__main__":
 if (len(sys.argv) != 3):
  print "Usage: %s  " % sys.argv[0]
  exit(-1)
 else:
  f_in = sys.argv[1]
  f_out = sys.argv[2]
  f_bib = "%s.bbl" % f_in.split(".")[0]
    
 f = open(f_in, "r");
 lines = f.readlines()
 f.close()
 

 
 for line in lines:
  process_line(line)
  
   
 f = open(f_out, "w");
 f.writelines(all_lines);
 f.close()
END

No comments:

Post a Comment