def _migrate_unformatted_to_output(
    data: GTData, data_tbl: TblData, formats: list[FormatInfo], context: str
) -> GTData:
    """
    Escape unformatted cells so they are safe for a specific output context.
    """

    # TODO: This function will eventually be applied to all context types but for now
    # it's just used for LaTeX output
    if context != "latex":
        return data

    all_formatted_cells: list[list[tuple[str, int]]] = []

    for fmt in formats:
        eval_func = getattr(fmt.func, context, fmt.func.default)
        if eval_func is None:
            raise Exception("Internal Error")

        # Accumulate all formatted cells in the table
        all_formatted_cells.append(fmt.cells.resolve())

    # Deduplicate the list of formatted cells
    deduplicate_formatted_cells = list(set(_flatten_list(all_formatted_cells)))

    # Get all visible cells in the table
    all_visible_cells = _get_visible_cells(data=data_tbl)

    # Get the difference between the visible cells and the formatted cells
    all_unformatted_cells = list(set(all_visible_cells) - set(deduplicate_formatted_cells))

    # TODO: this currently will only be used for LaTeX (HTML escaping will be performed
    # in the future)

    for col, row in all_unformatted_cells:
        # Get the cell value and cast as string
        cell_value = _get_cell(data_tbl, row, col)
        cell_value_str = str(cell_value)

        result = _process_text(cell_value_str, context=context)

        _set_cell(data._body.body, row, col, result)

    return data

    Escape unformatted cells so they are safe for a specific output context.
    
great_tables/_utils.py