doc2json/tex2json/xml_to_json.py
def process_equations_from_tex(sp: BeautifulSoup) -> Dict:
    """
    Generate equation dict and replace with id tokens
    :param sp:
    :return:
    """
    equation_map = dict()

    for eq in sp.find_all('formula'):
        try:
            if eq.get('type', None) == 'display':
                if eq.get('id', None):
                    ref_id = eq.get('id').replace('uid', 'EQREF')
                    try:
                        mathml = latex2mathml.converter.convert(eq.texmath.text.strip())
                    except Exception:
                        mathml = ""
                    equation_map[ref_id] = {
                        "num": eq.get('id-text', None),
                        "text": eq.math.text.strip(),
                        "mathml": mathml,
                        "latex": eq.texmath.text.strip(),
                        "ref_id": ref_id
                    }
                replace_item = sp.new_tag('p')
                equation_copy = copy.copy(eq)
                equation_copy['type'] = 'inline'
                replace_item.insert(0, equation_copy)

                # replace with <p> containing equation as inline
                eq.replace_with(replace_item)

        except AttributeError:
            continue

    return equation_map

    Generate equation dict and replace with id tokens
    :param sp:
    :return:
    
Generate equation dict and replace with id tokens
Generate equation dict and replace with id tokens
def process_equations_from_tex(sp: BeautifulSoup) -> Dict:
    equation_map = dict()
    for eq in sp.find_all('formula'):
        try:
            if eq.get('type', None) == 'display':
                if eq.get('id', None):
                    ref_id = eq.get('id').replace('uid', 'EQREF')
                    try:
                        mathml = latex2mathml.converter.convert(eq.texmath.text.strip())
                    except Exception:
                        mathml = ""
                    equation_map[ref_id] = {
                        "num": eq.get('id-text', None),
                        "text": eq.math.text.strip(),
                        "mathml": mathml,
                        "latex": eq.texmath.text.strip(),
                        "ref_id": ref_id
                    }
                replace_item = sp.new_tag('p')
                equation_copy = copy.copy(eq)
                equation_copy['type'] = 'inline'
                replace_item.insert(0, equation_copy)
                eq.replace_with(replace_item)
        except AttributeError:
            continue
    return equation_map
def process_equations_from_tex ( sp : BeautifulSoup ) -> Dict : equation_map = dict ( ) for eq in sp . find_all ( 'formula' ) : try : if eq . get ( 'type' , None ) == 'display' : if eq . get ( 'id' , None ) : ref_id = eq . get ( 'id' ) . replace ( 'uid' , 'EQREF' ) try : mathml = latex2mathml . converter . convert ( eq . texmath . text . strip ( ) ) except Exception : mathml = "" equation_map [ ref_id ] = { "num" : eq . get ( 'id-text' , None ) , "text" : eq . math . text . strip ( ) , "mathml" : mathml , "latex" : eq . texmath . text . strip ( ) , "ref_id" : ref_id } replace_item = sp . new_tag ( 'p' ) equation_copy = copy . copy ( eq ) equation_copy [ 'type' ] = 'inline' replace_item . insert ( 0 , equation_copy ) eq . replace_with ( replace_item ) except AttributeError : continue return equation_map
Generate equation dict and replace with id tokens
Generate equation dict and replace with id tokens
"""
    Generate equation dict and replace with id tokens
    :param sp:
    :return:
    """ # replace with <p> containing equation as inline
None
sp
BeautifulSoup
None