mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-11-04 05:03:53 +01:00
Add extractMath function
This commit is contained in:
parent
e37fa5aaca
commit
bdd0982b92
@ -139,3 +139,19 @@ def tabularToData(table,commands=None):
|
|||||||
return table
|
return table
|
||||||
else:
|
else:
|
||||||
raise ValueError("Only tabular LaTeX environment is supported")
|
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
|
@ -1,6 +1,6 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from TexSoup import TexSoup
|
from TexSoup import TexSoup
|
||||||
from .LaTeX import newCommand
|
from .LaTeX import newCommand,extractMath
|
||||||
from .utils import getValFromCell,checkFloat
|
from .utils import getValFromCell,checkFloat
|
||||||
from TexSoup import TexNode,TexEnv
|
from TexSoup import TexNode,TexEnv
|
||||||
from enum import IntEnum,auto,unique,IntFlag
|
from enum import IntEnum,auto,unique,IntFlag
|
||||||
@ -67,17 +67,7 @@ class dataFileBase(object):
|
|||||||
def convertState(StateTablelist,initialState,default=DataType.ABS,commands=[]):
|
def convertState(StateTablelist,initialState,default=DataType.ABS,commands=[]):
|
||||||
tmplst=[]
|
tmplst=[]
|
||||||
for TexState in StateTablelist:
|
for TexState in StateTablelist:
|
||||||
math=TexState.find("$")
|
st=str(extractMath(TexState,Soup=True,commands=commands))
|
||||||
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)
|
|
||||||
m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*(:?\((?P<type>[^\)]*)\))?",st)
|
m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*(:?\((?P<type>[^\)]*)\))?",st)
|
||||||
seq=m.group("multiplicity","symm")
|
seq=m.group("multiplicity","symm")
|
||||||
mul=int(m.group("multiplicity"))
|
mul=int(m.group("multiplicity"))
|
||||||
|
Loading…
Reference in New Issue
Block a user