import re


def decode_Tex_accents(in_str):
    """Converts a string containing LaTex accents (i.e. "{\\`{O}}") to ASCII
    (i.e. "O"). Useful for correcting author names when bib entries were
    queried from web via doi

    :param in_str: input str to decode
    :type in_str: str
    :return: corrected string
    :rtype: str
    """
    # replaces latex accents with ascii letter (no accent)
    pat = "\{\\\\'\{(\w)\}\}"
    out = in_str
    for x in re.finditer(pat, in_str):
        out = out.replace(x.group(), x.groups()[0])

    # replace latex {\textsinglequote} with underscore
    out = out.replace('{\\textquotesingle}', "_")

    # replace actual single quotes with underscore for bibtex compatibility
    out = out.replace("'", '_')

    return out