import re


def _texify(s: str) -> str:
    """ Convert python GA operator notation to LaTeX """
    repl_pairs = [
        (r'\|', r'\cdot '),
        (r'\^(?!{)', r'\W '),
        (r'\*', ' '),
        (r'\brgrad\b', r'\bar{\boldsymbol{\nabla}} '),
        (r'\bgrad\b', r'\boldsymbol{\nabla} '),
        (r'>>', r' \times '),
        (r'<<', r' \bar{\times} '),
        (r'<', r'\rfloor '),
        (r'>', r'\lfloor '),
    ]

    def repl_func(m):
        # only one group will be present, use the corresponding match
        return next(
            r
            for (p, r), g in zip(repl_pairs, m.groups())
            if g is not None
        )
    pattern = '|'.join("({})".format(p) for p, _ in repl_pairs)
    return re.sub(pattern, repl_func, s)