diff --git a/tools/lib/LaTeX.py b/tools/lib/LaTeX.py index c61a7b01..c0d27385 100644 --- a/tools/lib/LaTeX.py +++ b/tools/lib/LaTeX.py @@ -138,4 +138,20 @@ def tabularToData(table,commands=None): table=np.array(lnewtable,TexNode) return table else: - raise ValueError("Only tabular LaTeX environment is supported") \ No newline at end of file + raise ValueError("Only tabular LaTeX environment is supported") + +def extractMath(TexMath,Soup=False,commands=[]): + if not Soup and len(commands)>0: + raise ValueError("Commandw are only usable when Soup is True") + math=TexMath.find("$") + lst=list(math.contents) + mystr=str(lst[0]) + if not Soup: + return mystr + mathsoup=None + try: + mathsoup=TexSoup(mystr) + except: + raise ValueError(f"Error when parsing latex math: {mystr}") + newCommand.runAll(mathsoup,commands) + return mathsoup \ No newline at end of file diff --git a/tools/lib/data.py b/tools/lib/data.py index 20b79b42..30f4e934 100644 --- a/tools/lib/data.py +++ b/tools/lib/data.py @@ -1,6 +1,6 @@ from collections import OrderedDict from TexSoup import TexSoup -from .LaTeX import newCommand +from .LaTeX import newCommand,extractMath from .utils import getValFromCell,checkFloat from TexSoup import TexNode,TexEnv from enum import IntEnum,auto,unique,IntFlag @@ -67,17 +67,7 @@ class dataFileBase(object): def convertState(StateTablelist,initialState,default=DataType.ABS,commands=[]): tmplst=[] for TexState in StateTablelist: - math=TexState.find("$") - lst=list(math.contents) - mystr=str(lst[0]) - mathsoup=None - try: - mathsoup=TexSoup(mystr) - except: - print(f"Error when parsing latex state: {mystr}") - exit(-1) - newCommand.runAll(mathsoup,commands) - st=str(mathsoup) + st=str(extractMath(TexState,Soup=True,commands=commands)) m=re.match(r"^\^(?P\d)(?P[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P\w)(?:})\])?\s*(:?\((?P[^\)]*)\))?",st) seq=m.group("multiplicity","symm") mul=int(m.group("multiplicity"))