Repository: ManimCommunity/manim
File: manim/utils/tex_file_writing.py (Python)

Code before:

                            # Find where the line of the error is indicated in the log file
                            while not log[index_line].startswith("l."):
                                index_line += 1

                            # Find the index of the errored line in the tex file
                            tex_index = (
                                int(log[index_line].split(" ")[0].split(".")[1]) - 1
                            )

                            # Seek the environment scope that contains the error
                            environment = tex_index
                            while not tex[environment].startswith("\\begin"):
                                environment -= 1

                            # Print the entire environment including its end
                            while not tex[environment - 1].startswith("\\end"):
                                context += tex[environment]
                                if environment == tex_index:
                                    context += "^ this line\n"
                                environment += 1
                            logger.error(context)

                        # add insight for errors
                        for prog, get_insight in LATEX_ERROR_INSIGHTS:
                            match = re.search(prog, ''.join(log[log_index:index_line]))
                            if match is not None:
                                for insight in get_insight(match):
                                    logger.info(insight)

            raise ValueError(
                f"{tex_compiler} error converting to"
                f" {output_format[1:]}. See log output above or"
                f" the log file: {log_file}"
            )
    return result


def convert_to_svg(dvi_file, extension, page=1):
    """Converts a .dvi, .xdv, or .pdf file into an svg using dvisvgm.

    Parameters
    ----------
    dvi_file : :class:`str`
        File name of the input file to be converted.
    extension : :class:`str`
        String containing the file extension and thus indicating the file type, e.g. ``.dvi`` or ``.pdf``
    page : Optional[:class:`int`], optional
        Page to be converted if input file is multi-page.

    Returns

Review comment (suggestion):
```suggestion
                            match = re.search(prog, "".join(log[log_index:index_line]))
```

Code after:
                            while not log[index_line].startswith("l."):
                                index_line += 1

                            # Find the index of the errored line in the tex file
                            tex_index = (
                                int(log[index_line].split(" ")[0].split(".")[1]) - 1
                            )

                            # Seek the environment scope that contains the error
                            environment = tex_index
                            while not tex[environment].startswith("\\begin"):
                                environment -= 1

                            # Print the entire environment including its end
                            while not tex[environment - 1].startswith("\\end"):
                                context += tex[environment]
                                if environment == tex_index:
                                    context += "^ this line\n"
                                environment += 1
                            logger.error(context)

                        # add insight for errors
                        for prog, get_insight in LATEX_ERROR_INSIGHTS:
                            match = re.search(prog, "".join(log[log_index:index_line]))
                            if match is not None:
                                for insight in get_insight(match):
                                    logger.info(insight)

            raise ValueError(
                f"{tex_compiler} error converting to"
                f" {output_format[1:]}. See log output above or"
                f" the log file: {log_file}"
            )
    return result


def convert_to_svg(dvi_file, extension, page=1):
    """Converts a .dvi, .xdv, or .pdf file into an svg using dvisvgm.

    Parameters
    ----------
    dvi_file : :class:`str`
        File name of the input file to be converted.
    extension : :class:`str`
        String containing the file extension and thus indicating the file type, e.g. ``.dvi`` or ``.pdf``
    page : Optional[:class:`int`], optional
        Page to be converted if input file is multi-page.

    Returns
    -------
    :class:`str`