'Returns a cleaned string and a boolean flag.
The flag indicates if the given string *s* contains any mathtext,
determined by counting unescaped dollar signs. If no mathtext
is present, the cleaned string has its dollar signs unescaped.
If usetex is on, the flag always has the value "TeX".'

@staticmethod
def is_math_text(s, usetex=None):

    if (usetex is None):
        usetex = rcParams[u'text.usetex']
    if usetex:
        if (s == u'    '):
            s = u'\\    '
        return (s, u'TeX')
    if cbook.is_math_text(s):
        return (s, True)
    else:
        return (s.replace(u'\\$', u'$'), False)
