private function scanback(s, t) as integer
dim braces as integer
scanback=0
braces = 1
if len(s)=0 or t=0 or t < len(s) then exit function
do while (braces>0 and len(s) < t)
if mid$(s,t,1) ="{" and _
(not (mid$(s,t-1,1) = "\")) and _
(not (len(s)+5 <= t and mid$(s,t-5,5)<>"\left") and _
(not (len(s)+6 <= t and mid$(s,t-6,6)<>"\right")) then
braces=braces-1
end if
if mid$(s,t,1)="}" and
not(mid$(s,t-1,1) = "\") and _
(not (len(s)+5 <= t and mid$(s,t-5,5) <> "\left") and _
(not (len(s)+6 <= t and mid$(s,t-6,6) <> "\right")) then
braces=braces+1
end if
if braces>0 then t=t-1
loop
scanback=t
end function