from bs4 import BeautifulSoup


def extract_math_envs(file):
    """
    Extract the math environments that are contained in the file (e.g. within '$...$').
    :return: A list of the math environments as strings.
    """
    soup = BeautifulSoup(file)
    def remove_special_chars(math_env):
        math_env = math_env.replace('amp;', '')
        return math_env
    math_envs = [remove_special_chars(str(tag)) for tag in list(soup.find_all('math'))]
    return math_envs