#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import re

# 手动替换latex公式
def remove_latex_keyword(html):
    html = html.replace(r'\overset', '')
    html = html.replace(r'\underset', '')
    html = html.replace('\dfrac', '')
    html = html.replace(r'\times', ' operator ')
    html = html.replace(r'\begin', '')
    html = html.replace('flalign', '')
    html = html.replace('align', ' ')
    html = html.replace('\end', '')
    html = html.replace(r'\xrightarrow ', ' arrow ')
    html = html.replace('\leftrightsquigarrow ', ' arrow ')
    html = html.replace('\longleftrightarrow ', ' arrow ')
    html = html.replace('\Longleftrightarrow ', ' arrow ')
    html = html.replace('\rightleftharpoons', ' arrow ')
    html = html.replace('\rightharpoondown', ' arrow ')
    html = html.replace('\downharpoonright', ' arrow ')
    html = html.replace('\leftharpoondown', ' arrow ')
    html = html.replace('\downharpoonleft', ' arrow ')
    html = html.replace('\nleftrightarrow ', ' arrow ')
    html = html.replace('\nLeftrightarrow ', ' arrow ')
    html = html.replace('\leftrightarrow ', ' arrow ')
    html = html.replace('\Leftrightarrow ', ' arrow ')
    html = html.replace('\longrightarrow ', ' arrow ')
    html = html.replace('\Longrightarrow ', ' arrow ')
    html = html.replace('\rightharpoonup', ' arrow ')
    html = html.replace('\upharpoonright', ' arrow ')
    html = html.replace('\sphericalangle', ' arrow ')
    html = html.replace('\overrightarrow ', ' arrow ')
    html = html.replace('\longleftarrow ', ' arrow ')
    html = html.replace('\Longleftarrow ', ' arrow ')
    html = html.replace('\leftharpoonup', ' arrow ')
    html = html.replace('\upharpoonleft', ' arrow ')
    html = html.replace('\measuredangle', ' symbol ')
    html = html.replace('\overleftarrow ', ' structure ')
    html = html.replace('\updownarrow ', ' arrow ')
    html = html.replace('\Updownarrow ', ' arrow ')
    html = html.replace('\nrightarrow ', ' arrow ')
    html = html.replace('\nRightarrow ', ' arrow ')
    html = html.replace('\diamondsuit', ' symbol ')
    html = html.replace('\varparallel', ' symbol ')
    html = html.replace('\varepsilon', ' greek ')
    html = html.replace('\varUpsilon', ' greek ')
    html = html.replace('\rightarrow ', ' arrow ')
    html = html.replace(r'\Rightarrow ', ' arrow ')
    html = html.replace('\nleftarrow ', ' arrow ')
    html = html.replace('\nLeftarrow ', ' arrow ')
    html = html.replace('\varnothing', ' symbol ')
    html = html.replace('\underbrace', ' symbol ')
    html = html.replace('\varLambda', ' GREEK ')
    html = html.replace('\bigotimes', ' operator ')
    html = html.replace('\vee', ' operator ')
    html = html.replace('\wedge', ' operator ')
    html = html.replace('\leftarrow ', ' arrow ')
    html = html.replace('\Leftarrow ', ' arrow ')
    html = html.replace('\downarrow ', ' arrow ')
    html = html.replace('\Downarrow ', ' arrow ')
    html = html.replace('\backslash', ' delimiter ')
    html = html.replace('\spadesuit', ' symbol ')
    html = html.replace('\heartsuit', ' symbol ')
    html = html.replace('\therefore', ' symbol ')
    html = html.replace('\nparallel', ' symbol ')
    html = html.replace('\underline', ' structure ')
    html = html.replace('\widetilde', ' structure ')
    html = html.replace('\overbrace', ' structure ')
    html = html.replace('\vartheta', ' greek ')
    html = html.replace('\varkappa', ' greek ')
    html = html.replace('\varsigma', ' greek ')
    html = html.replace('\varGamma', ' GREEK ')
    html = html.replace('\varDelta', ' GREEK ')
    html = html.replace('\varTheta', ' GREEK ')
    html = html.replace('\varSigma', ' GREEK ')
    html = html.replace('\varOmega', ' GREEK ')
    html = html.replace('\leqslant', ' relational ')
    html = html.replace('\geqslant', ' relational ')
    html = html.replace('\subseteq', ' relational ')
    html = html.replace('\supseteq', ' relational ')
    html = html.replace('\setminus', ' operator ')
    html = html.replace('\bigoplus', ' operator ')
    html = html.replace('\bigwedge', ' operator ')
    html = html.replace('\clubsuit', ' symbol ')
    html = html.replace('\triangle', ' symbol ')
    html = html.replace('\parallel', ' symbol ')
    html = html.replace('\overline', ' structure ')
    html = html.replace('\epsilon', ' greek ')
    html = html.replace('\omicron', ' greek ')
    html = html.replace('\upsilon', ' greek ')
    html = html.replace('\digamma', ' greek ')
    html = html.replace('\Upsilon', ' GREEK ')
    html = html.replace('\diamond', ' operator ')
    html = html.replace('\bigodot', ' operator ')
    html = html.replace('\uparrow ', ' arrow ')
    html = html.replace('\Uparrow ', ' arrow ')
    html = html.replace('\nearrow ', ' arrow ')
    html = html.replace('\searrow ', ' arrow ')
    html = html.replace('\swarrow ', ' arrow ')
    html = html.replace('\nwarrow ', ' arrow ')
    html = html.replace('\bigstar', ' symbol ')
    html = html.replace('\partial', ' symbol ')
    html = html.replace('\because', ' symbol ')
    html = html.replace('\widehat', ' structure ')
    html = html.replace('\lambda', ' greek ')
    html = html.replace('\varrho', ' greek ')
    html = html.replace('\varphi', ' greek ')
    html = html.replace('\Lambda', ' GREEK ')
    html = html.replace('\varPhi', ' GREEK ')
    html = html.replace('\varPsi', ' GREEK ')
    html = html.replace('\approx', ' approx ')
    html = html.replace('\subset', ' relational ')
    html = html.replace('\supset', ' relational ')
    html = html.replace('\bullet', ' operator ')
    html = html.replace('\ominus', ' operator ')
    html = html.replace('\otimes', ' operator ')
    html = html.replace('\oslash', ' operator ')
    html = html.replace('\bigvee', ' operator ')
    html = html.replace('\bigcup', ' operator ')
    html = html.replace('\bigcap', ' operator ')
    html = html.replace('\lbrack', ' delimiter ')
    html = html.replace('\rbrack', ' delimiter ')
    html = html.replace('\lfloor', ' delimiter ')
    html = html.replace('\rfloor', ' delimiter ')
#     html = html.replace('\lbrace', ' lbrace ')
    html = html.replace('\lbrace', ' delimiter ')
    html = html.replace(r'\rbrace', ' delimiter ')
    html = html.replace('\langle', ' delimiter ')
    html = html.replace('\rangle', ' delimiter ')
    html = html.replace('\iiiint', ' symbol ')
    html = html.replace('\iddots', ' symbol ')
    html = html.replace('\propto', ' symbol ')
    html = html.replace('\forall', ' symbol ')
    html = html.replace('\exists', ' symbol ')
    html = html.replace('\square', ' symbol ')
    html = html.replace('\arccos', ' function ')
    html = html.replace('\limsup', ' function ')
    html = html.replace('\alpha', ' greek ')
    html = html.replace('\gamma', ' greek ')
    html = html.replace('\delta', ' greek ')
    html = html.replace('\theta', ' greek ')
    html = html.replace('\kappa', ' greek ')
    html = html.replace('\sigma', ' greek ')
    html = html.replace('\omega', ' greek ')
    html = html.replace('\varpi', ' greek ')
    html = html.replace('\Gamma', ' GREEK ')
    html = html.replace('\Delta', ' GREEK ')
    html = html.replace('\Theta', ' GREEK ')
    html = html.replace('\Sigma', ' GREEK ')
    html = html.replace('\Omega', ' GREEK ')
    html = html.replace('\varXi', ' GREEK ')
    html = html.replace('\varPi', ' GREEK ')
    html = html.replace('\equiv', ' relational ')
    html = html.replace('\notin', ' relational ')
    html = html.replace('\times', ' operator ')
    html = html.replace('\oplus', ' operator ')
    html = html.replace('\lceil', ' delimiter ')
    html = html.replace('\rceil', ' delimiter ')
    html = html.replace('\iiint', ' symbol ')
    html = html.replace('\nabla', ' symbol ')
    html = html.replace('\ldots', ' symbol ')
    html = html.replace('\cdots', ' symbol ')
    html = html.replace('\vdots', ' symbol ')
    html = html.replace('\ddots', ' symbol ')
    html = html.replace('\infty', ' symbol ')
    html = html.replace('\imath', ' symbol ')
    html = html.replace('\jmath', ' symbol ')
    html = html.replace('\aleph', ' symbol ')
    html = html.replace('\angle', ' symbol ')
    html = html.replace('\beta', ' greek ')
    html = html.replace('\zeta', ' greek ')
    html = html.replace('\iota', ' greek ')
    html = html.replace('\nmid', ' relational ')
    html = html.replace('\cong', ' relational ')
    html = html.replace('\cdot', ' operator ')
    html = html.replace('\star', ' operator ')
    html = html.replace('\circ', ' operator ')
    html = html.replace('\odot', ' operator ')
    html = html.replace('\gets', ' arrow ')
    html = html.replace('\vert', ' delimiter ')
    html = html.replace('\Vert', ' delimiter ')
    html = html.replace('\oint', ' symbol ')
    html = html.replace('\iint', ' symbol ')
    html = html.replace('\hbar', ' symbol ')
    html = html.replace('\lnot', ' symbol ')
    html = html.replace('\land', ' symbol ')
    html = html.replace('\odot', ' symbol ')
    html = html.replace('\perp', ' symbol ')
    html = html.replace('\frac', ' structure ')
    html = html.replace('\sinh', ' function ')
    html = html.replace('\cosh', ' function ')
    html = html.replace('\eta', ' greek ')
    html = html.replace('\rho', ' greek ')
    html = html.replace('\tau', ' greek ')
    html = html.replace('\phi', ' greek ')
    html = html.replace('\chi', ' greek ')
    html = html.replace('\psi', ' greek ')
    html = html.replace('\Phi', ' GREEK ')
    html = html.replace('\Psi', ' GREEK ')
    html = html.replace('\leq', ' relational ')
    html = html.replace('\geq', ' relational ')
    html = html.replace('\neq', ' relational ')
    html = html.replace('\mid', ' relational ')
    html = html.replace('\sim', ' relational ')
    html = html.replace('\div', ' operator ')
    html = html.replace('\ast', ' operator ')
    html = html.replace('\cup', ' operator ')
    html = html.replace('\cap', ' operator ')
    html = html.replace('\int', ' symbol ')
    html = html.replace('\dif', ' symbol ')
    html = html.replace('\ell', ' symbol ')
    html = html.replace('\lor', ' symbol ')
    html = html.replace('\cos', ' function ')
    html = html.replace('\csc', ' function ')
    html = html.replace('\exp', ' function ')
    html = html.replace('\ker', ' function ')
    html = html.replace('\min', ' function ')
    html = html.replace('\arc', ' function ')
    html = html.replace('\deg', ' function ')
    html = html.replace('\gcd', ' function ')
    html = html.replace('\mu', ' greek ')
    html = html.replace('\nu', ' greek ')
    html = html.replace(r'\xi', ' greek ')
    html = html.replace('\pi', ' greek ')
    html = html.replace(r'\Xi', ' GREEK ')
    html = html.replace('\Pi', ' GREEK ')
    html = html.replace('\lt', ' relational ')
#     html = html.replace('\le', ' le ')
    html = html.replace('\gt', ' relational ')
    html = html.replace('\ge', ' relational ')
    html = html.replace('\ne', ' relational ')
    html = html.replace('\in', ' relational ')
    html = html.replace('\ni', ' relational ')
    html = html.replace('\pm', ' operator ')
    html = html.replace('\mp', ' operator ')
    html = html.replace('\to', ' arrow ')
    html = html.replace('\Re', ' symbol ')
    html = html.replace('\Im', ' symbol ')
    html = html.replace('\wp', ' symbol ')
    html = html.replace('\lg', ' function ')
    html = html.replace('\ln', ' function ')
    # html = html.replace('\', '  ')
    html = html.replace('\right', '(')
    html = html.replace('\left', ')')
    html = html.replace('log', 'log ')


    mol = re.compile('[0-9]mol')
    html = mol.sub(' mol ', html)

    num = re.compile('(\t| )\d(?=[a-zA-Z])')
    html = num.sub(' ', html)

    g = re.compile('[0-9]g')
    html = g.sub(' g ', html)


    mL = re.compile('mL')
    html = mL.sub(' mL ', html)

    html = html.replace('___', ' input ')



    # 手动替换latex字符
    return html