def FixOneOver(strin,displaystyle=True):
    strout=strin
    oi=strout.find('\\over')
    if oi>-1:
        leftpart=rwkstr(strout[0:oi-1])#the -1 is because the syntax will always be {{num}\\over{den}} and I don't want the } before \\over
        linds=leftpart.findall('{{')
        linds=reverse(linds)
        for ti in linds:
            tempnum=leftpart[ti+2:]
            if checkonebalance(tempnum)==0:
                break
        num=tempnum
        b4=leftpart[0:ti]
        si=oi+len('\\over')+1
        rightpart=rwkstr(strout[si:])
        rinds=rightpart.findall('}}')
        for ri in rinds:
            tempden=rightpart[0:ri]
            if checkonebalance(tempden)==0:
                break
        den=tempden
        afterpart=rightpart[len(den)+2:]
        strout=b4
        if displaystyle:
            strout+=' \\displaystyle '
        strout+='\\frac{'+num+'}{'+den+'}'+afterpart
    return strout
Exemple #2
0
 def FindEndofEnv(self, matchline=None):
     if matchline is None:
         matchline = self.matchline
     n = -1
     match = False
     numleft = 0
     numright = 0
     while (not match) and (n < len(self.list)):
         n += 1
         curline = rwkstr(self.list[matchline+n])
         numleft += len(curline.findall('{'))
         numright += len(curline.findall('}'))
         if numright >= numleft:
             match = True
     if match:
         self.endline = matchline+n
         return self.endline
     else:
         return None
Exemple #3
0
def CountCurlies(strin):
    mystr = rwkstr(strin)
    numleft = len(mystr.findall('{'))
    numright = len(mystr.findall('}'))
    return numleft, numright
def checkonebalance(strin, openp='{',closep='}'):
    strin=rwkstr(strin)
    no=strin.findall(openp)
    nc=strin.findall(closep)
    return len(no)-len(nc)
Exemple #5
0
 def CleanItems(self, bullet='*'):
     self.string = self.string.strip()
     if self.string:
         while self.string[0] == bullet:
             self.string = self.string[1:]
     self.string = rwkmisc.rwkstr(self.string.strip())
Exemple #6
0
 def __init__(self, stringin, reveallevel=None):
     self.string = rwkmisc.rwkstr(stringin)
     self.reveal = reveallevel
     self.CleanItems()