Beispiel #1
0
 def ToWLT(self, pathout=None):
     if pathout is None:
         pathout = self.CreatePathout('.wlt')
     listout = []
     out = listout.append
     list1 = self.rawlist[1:-2]#assuming .wxm files start with this line:
     #/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
     #
     # and end with
     #
     #/* Maxima can't load/batch files which end with a comment! */
     #"Created with wxMaxima"$
     #
     # so that the first and last two lines need to be cut
     filt1 = '/* [wxMaxima: input   start ] */'
     filt2 = '/* [wxMaxima: input   end   ] */'
     filtlist = [filt1, filt2]
     filteredlines = [item for item in list1 if item not in filtlist]
     cleanlines = CleanList(filteredlines)
     self.cleanlines = cleanlines
     self.outlines = ChangeCommentsToPython(self.cleanlines)
     writefile(pathout, self.outlines)
     myout = wxmLitFile()
     myout.rawlist = copy.copy(self.outlines)
     myout.pathin = pathout
     return myout
Beispiel #2
0
 def ToWLT(self, pathout=None, **kwargs):
     """Dump the file to a wlt file, omitting the body of the text
     (i.e. maxima commands only)."""
     oldind = copy.copy(self.ind)
     if not hasattr(self, "blocks"):
         self.FindBlocks(**kwargs)
     self.ind = 0
     wltlines = []
     for block in self.blocks:
         chunk = self.PopNext(clear=False, listname="rawlist")
         envkey, codelist = self._CleanChunk(chunk)
         filtcode = stripcodelist(codelist)
         f2code = [item.strip() for item in filtcode]
         wltlines.extend(f2code)
     self.ind = oldind  # reset ind
     if pathout is None:
         pne, ext = os.path.splitext(self.path)
         pathout = pne + ".wlt"
     pytex.writefile(pathout, wltlines)
     wltfile = wxmlit.wxmLitFile(pathout)
     wltfile.ToWXM()
Beispiel #3
0
 def ExportPython(self):
     """Dump the file to a python file, omitting the body of the text
     (i.e. all python commands only)."""
     oldind = copy.copy(self.ind)
     self.ind = 0
     pylines = []
     keepgoing = True
     n = 0
     while keepgoing and (n < len(self.lines)):
         chunk = self.PopNext()
         if chunk:
             envkey, codelist = self._CleanChunk(chunk)
             for n, line in enumerate(codelist):
                 if line.find('label=') == 0:
                     line = '#'+line
                     codelist[n] = line
             pylines.extend(codelist)
         else:
             keepgoing = False
         n += 1
     pne, ext = os.path.splitext(self.path)
     pathout = pne+'_out.py'
     pytex.writefile(pathout, pylines)
     self.ind = oldind
Beispiel #4
0
 def SaveMaximaScript(self, scriptname="temp.mac"):
     if not hasattr(self, "maximalines"):
         self.BuildMaximaScript()
     self.scriptname = scriptname
     pytex.writefile(self.scriptname, self.maximalines)
     self.MakeMaximaEqnFolder()
Beispiel #5
0
    def ToWXM(self, pathout=None):
        ############################
        #
        #  note that multi-line trailing comments are not handled correctly
        #
        ############################
        if pathout is None:
            pathout = self.CreatePathout('.wxm')
        listout = []
        out = listout.append
        out('/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/')
        eqstart = '/* [wxMaxima: input   start ] */'
        eqend = '/* [wxMaxima: input   end   ] */'

        eqopen = False#flag to tell whether or not there is an equation environment open
        prevline = None
        haseq = False#flag to tell if the equation environment already has an equation

        com_re = re.compile('^\\s*'+self.comsym+'(.*)')

        N = len(self.rawlist)-1

        for n, curline in enumerate(self.rawlist):
#            print('curline='+curline)
#            print('eqopen='+str(eqopen))
#            print('haseq='+str(haseq))
            if not curline and eqopen:
                out(eqend)
                out('')
                eqopen = False
                haseq = False
            if curline and not eqopen:
                eqopen = True
                out(eqstart)
            q = com_re.search(curline)
            if q:
                if eqopen and haseq and n!=N and self.rawlist[n+1]:
                    out(eqend)
                    out('')
                    out(eqstart)
                    eqopen = True
                    haseq = False
                out('/* '+q.group(1)+' */')
                if n==N or not self.rawlist[n+1]:
                    out(eqend)
                    out('')
                    eqopen = False
                    haseq = False
            elif curline:
                #the line is not a comment
                if haseq:
                    #close the current and start a new one
                    out(eqend)
                    out('')
                    out(eqstart)
                if curline[-1]!=';':
                    curline+=';'
                out(curline)
                haseq = True
        if eqopen:
            out(eqend)
            out('')
        out("/* Maxima can't load/batch files which end with a comment! */")
        out('"Created with Python"$')
        self.wxmlist = listout
        writefile(pathout, listout)
        myout = wxmFile()
        myout.rawlist = copy.copy(self.wxmlist)
        myout.pathin = pathout
        return myout