#!/usr/bin/python # a python script to convert a GAP # log file into a latex file # usage: # gap2latex.py gapsession.glog gapsession.tex # ** suggest using glog as gap log extension to avoid over-writing ** # ** log file when compiling latex file in same directory! ** # #wdj, 2-8-2005 import sys try: inputfile=sys.argv[1] outputfile=sys.argv[2] except: print "Usage: ",sys.argv[0]," " sys.exit() prompt=True begin=False ifile=open(inputfile,"r") ofile=open(outputfile,"w") ofile.write(""" \documentclass[12pt]{article} \usepackage{color} \usepackage{amssymb} \usepackage{amsmath} \def\\rrr{{\mathbb{R}}} \def\qqq{\mathbb{Q}} \def\ccc{\mathbb{C}} \def\zzz{\mathbb{Z}} \oddsidemargin -.25in \\textwidth 6.75in \\topmargin -.5in \\textheight 9in \\begin{document} \n \\noindent """) for line in ifile: firstpart=line[:4] if ">"==firstpart[:1]: prompt=True ofile.write("\\textcolor{red}{$>$}\\verb+ %s +\n\\newline\n" %line[2:len(line)-1]) if "gap>"==firstpart and prompt==True: prompt=True ofile.write("\\textcolor{red}{gap$>$}{\\verb+%s+}\n\\newline\n" %line[4:len(line)-1]) if "#"==firstpart[:1] and prompt==True: ofile.write("\\textcolor{blue}{$\#$}\\verb+ %s +\n\\newline\n" %line[2:len(line)-1]) if "brk>"==firstpart and prompt==True: prompt=True ofile.write("\\textcolor{orange}{brk$>$}\\verb+ %s +\n\\newline\n" %line[4:len(line)-1]) if "brk>"==firstpart and prompt==False: prompt=True begin=False ofile.write("\end{verbatim} }}\\noindent") ofile.write("\\textcolor{green}{brk$>$}\\verb+ %s +\n\\newline\n" %line[4:len(line)-1]) if not("#"==firstpart[:1]) and not("brk>"==firstpart) and not("gap>"==firstpart) and not(">"==firstpart[:1]) and prompt==True: ofile.write("\n {\small{\\begin{verbatim} \n") prompt=False begin=True if not("#"==firstpart[:1]) and not("brk>"==firstpart) and not("gap>"==firstpart) and not(">"==firstpart[:1]) and prompt==False: prompt=False ofile.write("%s \n" %line[:len(line)-1]) if "gap>"==firstpart and prompt==False: prompt=True begin=False ofile.write("\end{verbatim} }}\\noindent") ofile.write("\\textcolor{red}{gap$>$}\\verb+%s +\n\\newline\n" %line[4:len(line)-1]) if begin: ofile.write("\n \end{verbatim} }}\n\end{document}") if not(begin): ofile.write(""" \n \end{document} """) ifile.close() ofile.close()