10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Add extractMath function

This commit is contained in:
Mickaël Véril 2020-08-02 16:24:48 +02:00
parent e37fa5aaca
commit bdd0982b92
2 changed files with 19 additions and 13 deletions

View File

@ -139,3 +139,19 @@ def tabularToData(table,commands=None):
return table
else:
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

View File

@ -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<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*(:?\((?P<type>[^\)]*)\))?",st)
seq=m.group("multiplicity","symm")
mul=int(m.group("multiplicity"))