def convert_chemformula(string: str) -> str:
    """
    Convert a chemical formula string to a matplotlib parsable format (latex).

    Parameters
    ----------
    string or Adsorbate: str
        String to process.

    Returns
    -------
    str
        Processed string.
    """
    result = getattr(string, 'formula', None)
    if result is None:
        result = ""
        number_processing = False
        for i in string:
            if i.isdigit():
                if not number_processing:
                    result += '_{'
                    number_processing = True
            else:
                if number_processing:
                    result += '}'
                    number_processing = False
            result += i

        if number_processing:
            result += '}'

    return f'${result}$'