def esc_format(text):
    """Return text with formatting escaped.

    Markdown requires a backslash before literal underscores or asterisk, to
    avoid formatting to bold or italics.

    >>> esc_format("Normal text")
    'Normal text'
    >>> esc_format("Text with **bold**") == r'Text with \\*\\*bold\\*\\*'
    True
    >>> esc_format("Text with _italics_") == r'Text with \\_italics\\_'
    True
    >>> esc_format("Text with _**complicated** format_") == r'Text with \\_\\*\\*complicated\\*\\* format\\_'
    True
    """
    return str(text).replace("_", r"\_").replace("*", r"\*")