import time ta1=time.time() import rwkascii reload(rwkascii) ta2=time.time() print('import ascii time='+str(ta2-ta1)) import os import pdb from rwkos import FindFullPath ts=time.time() maximapath='maxima' latexcmd='latex' viewerext='.dvi' #latexcmd='pdflatex' #viewerext='.pdf' #pdb.set_trace() mydir=FindFullPath('GT\\Research\\Samii\\modeling\\Feedback') inname='noncolocated.tex' fno,ext=os.path.splitext(inname) outname=fno+'_out'+ext mylist=rwkascii.rwklatexlist([],outname) mylist.readfile(inname) #pdb.set_trace() b4lines,maximalines, endlines=mylist.findenvironments('maxima',0) maxpath=os.path.join(mydir,fno+'.max') eqdir=os.path.join(mydir,'noncolocated_eqs') if not os.path.exists(eqdir): os.mkdir(eqdir) #pdb.set_trace() outlines=rwkascii.BuildMaximaScript(maximalines, maxpath, eqdir, 'maxeq') maxpath_fs=maxpath.replace('\\','/') maximastr=maximapath+' -b '+maxpath_fs #os.system(maximastr) r,w=os.popen2(maximastr) #maxe=e.readlines() #e.close() maxo=w.readlines() w.close() #r.close() if rwkascii.searchlist(maxo,'Incorrect syntax'): for line in maxo: print(line.strip()) #pdb.set_trace() findlist=['Fa','xa'] replist=['F_a','x_a'] #pdb.set_trace() tr1=time.time() outbiglist=rwkascii.ReadMaximaOutput(outlines,findlist,replist) tr2=time.time() print('ReadMaxima time='+str(tr2-tr1)) newlist=rwkascii.rwklatexlist([],outname) newlist.list=mylist.reassemble(b4lines,outbiglist,endlines) #newlist.wrapeq() newlist.addheader() newlist.tofile() #latexstr1=latexcmd+' -interaction=batchmode '+outname latexstr2=latexcmd+' -interaction=nonstopmode '+outname r,w=os.popen2(latexstr2) texout=w.readlines() w.close() r.close() if rwkascii.searchlist(texout,'LaTeX Error'): for line in texout: print(line.strip()) if rwkascii.searchlist(texout,'Label(s) may have changed'): print('Running LaTeX a second time.') r,w=os.popen2(latexstr2) texout=w.readlines() w.close() r.close() outfno,ext=os.path.splitext(outname) ostr=outfno+viewerext os.startfile(ostr) te=time.time() print('run time='+str(te-ts))