<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def overwrite_tex(tex_fn, nb_outliers, script_options):
 """Overwrites the TeX summary file with new values. :param tex_fn: the name of the TeX summary file to overwrite. :param nb_outliers: the number of outliers. :param script_options: the script options. :type tex_fn: str :type nb_outliers: int :type options: argparse.Namespace """

    # Getting the content of the TeX file
    content = None
    with open(tex_fn, "r") as i_file:
        content = i_file.read()

    # Is there a figure
    has_figure = re.search("includegraphics", content) is not None

    # Changing the first sentence
    content, n = re.subn(
        r"(Using\s[0-9,]+\smarkers?\sand\sa\smultiplier\sof\s)[0-9.]+"
        r"(,\sthere\swas\sa\stotal\sof\s)[0-9,]+(\soutliers?\sof\sthe\s)"
        r"\w+(\spopulation.)",
        r"\g<1>{}\g<2>{:,d}\g<3>{}\g<4>".format(
            script_options.multiplier,
            nb_outliers,
            script_options.outliers_of,
        ),
        content
    )
    if n != 1:
        raise ProgramError("{}: invalid TeX summary file".format(tex_fn))

    # Do we need to change the principal components in the text?
    c1_c2 = {"C1", "C2"}
    if has_figure and ({script_options.xaxis, script_options.yaxis} != c1_c2):
        content, n = re.subn(
            r"(shows\s)the\sfirst\stwo\sprincipal\scomponents(\sof\sthe\sMDS"
            r"\sanalysis)",
            r"\g<1>components {} versus {}\g<2>".format(
                script_options.yaxis.replace("C", ""),
                script_options.xaxis.replace("C", ""),
            ),
            content,
        )
        if n != 1:
            raise ProgramError("{}: invalid TeX summary file".format(tex_fn))

        content, n = re.subn(
            r"(MDS\splots\sshowing\s)the\sfirst\stwo\sprincipal\scomponents"
            r"(\sof\sthe\ssource\sdataset\swith\sthe\sreference\spanels.)",
            r"\g<1>components {} versus {}\g<2>".format(
                script_options.yaxis.replace("C", ""),
                script_options.xaxis.replace("C", ""),
            ),
            content,
        )
        if n != 1:
            raise ProgramError("{}: invalid TeX summary file".format(tex_fn))

    if has_figure:
        # Changing the population in the figure description
        content, n = re.subn(
            r"(where\soutliers\sof\sthe\s)\w+(\spopulation\sare\sshown\s"
            r"in\sgrey.)",
            r"\g<1>{}\g<2>".format(script_options.outliers_of),
            content,
        )
        if n != 1:
            raise ProgramError("{}: invalid TeX summary file".format(tex_fn))

        content, n = re.subn(
            r"(The\soutliers\sof\sthe\s)\w+(\spopulation\sare\sshown\sin\s"
            r"grey,\swhile\ssamples\sof\sthe\ssource\sdataset\sthat\s"
            r"resemble\sthe\s)\w+(\spopulation\sare\sshown\sin\sorange.\sA\s"
            r"multiplier\sof\s)[0-9.]+(\swas\sused\sto\sfind\sthe\s)[0-9,]+(\s"
            r"outliers?.)",
            r"\g<1>{pop}\g<2>{pop}\g<3>{mult}\g<4>{nb:,d}\g<5>".format(
                pop=script_options.outliers_of,
                mult=script_options.multiplier,
                nb=nb_outliers,
            ),
            content,
        )
        if n != 1:
            raise ProgramError("{}: invalid TeX summary file".format(tex_fn))

        # Changing the figure (path)
        content, n = re.subn(
            r"(\s\\includegraphics\[.+\]\{)\{ethnicity.outliers\}.png(\}\s)",
            r"\g<1>{}\g<2>".format(
                "{" + script_options.out + ".outliers}." +
                script_options.format
            ),
            content,
        )
        if n != 1:
            raise ProgramError("{}: invalid TeX summary file".format(tex_fn))

    # Saving the new content
    with open(tex_fn, "w") as o_file:
        o_file.write(content)