import re


def replace_roff_special_characters(text):
    """Replace some *roff(7) special characters in the input text"""

    if "\\" in text:
        # See https://www.freebsd.org/cgi/man.cgi?query=mandoc_char for a complete list
        text = re.sub(r"\\&", "", text)
        text = re.sub(r"\\\.", ".", text)
        text = re.sub(r"\\-", "-", text)
        text = re.sub(r"\\\(aq", "'", text)
        text = re.sub(r"\\\(em", "", text)
        text = re.sub(r"\\\(tm", "tm", text)
        text = re.sub(r"\\\([lr]q", '"', text)
        text = re.sub(r"\\\[rg\]", "(R)", text)

        # Don't process user defined strings (\*) beside the font style ones:
        text = re.sub(r"\\f\\\*\[[^\]]*\]", "", text)
        text = re.sub(r"\\f[^\*]", "", text)

        # End of line backslash:
        text = re.sub(r" *\\$", "", text)

        # "\ " is not processed as it may still be useful

    return text