Escape a latex string

def escape_latex_str_if_str(value):
    '''Escape a latex string'''
    if not isinstance(value, str):
        return value
    for regex, replace_text in REGEX_ESCAPE_CHARS:
        value = re.sub(regex, replace_text, value)
    value = re.sub(REGEX_BACKSLASH, r'\\\\', value)
    return value