<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def escape_latex(text):
 r"""Escape characters of given text. This function takes the given text and escapes characters that have a special meaning in LaTeX: # $ % ^ & _ { } ~ \ """

    text = unicode(text.decode('utf-8'))
    CHARS = {
        '&': r'\&',
        '%': r'\%',
        '$': r'\$',
        '#': r'\#',
        '_': r'\_',
        '{': r'\{',
        '}': r'\}',
        '~': r'\~{}',
        '^': r'\^{}',
        '\\': r'\textbackslash{}',
    }
    escaped = "".join([CHARS.get(char, char) for char in text])
    return escaped.encode('utf-8')