2019-11-12 14:36:23 +01:00
|
|
|
import itertools
|
|
|
|
import sys
|
|
|
|
from TexSoup import TexEnv,TexNode, RArg
|
|
|
|
from collections.abc import Iterable
|
|
|
|
def nodify(TexArray,envName="[tex]",parent=None):
|
|
|
|
env=TexEnv(envName,TexArray)
|
|
|
|
node=TexNode(env)
|
|
|
|
node.parent=parent
|
|
|
|
return node
|
|
|
|
def desarg(tex):
|
|
|
|
lst=[]
|
|
|
|
for item in tex.contents:
|
|
|
|
if type(item) is RArg:
|
|
|
|
myitem=item.contents
|
|
|
|
if type(myitem) is list:
|
|
|
|
for myit in myitem:
|
|
|
|
lst.append(myit)
|
|
|
|
else:
|
|
|
|
lst.append(myit)
|
|
|
|
else:
|
|
|
|
myitem=item
|
|
|
|
lst.append(myitem)
|
2019-12-17 15:27:40 +01:00
|
|
|
return nodify(lst,tex.name,tex.parent)
|
|
|
|
def getValFromCell(cell):
|
|
|
|
unsafe=False
|
2020-02-05 09:51:54 +01:00
|
|
|
lst= list(cell.contents)
|
|
|
|
val= lst[0]
|
|
|
|
if type(val) is TexNode and str(val.expr)=='$\sim$' :
|
|
|
|
unsafe=True
|
|
|
|
val = lst[1]
|
|
|
|
val=checkFloat(str(val))
|
|
|
|
elif type(val) is TexNode and val.name=='emph':
|
2019-12-17 15:27:40 +01:00
|
|
|
unsafe=True
|
|
|
|
val=val.string
|
2020-02-01 16:40:11 +01:00
|
|
|
val=checkFloat(str(val))
|
2019-12-18 15:18:46 +01:00
|
|
|
return (val,unsafe)
|
|
|
|
|
2020-02-01 16:40:11 +01:00
|
|
|
def checkFloat(x):
|
2019-12-18 15:18:46 +01:00
|
|
|
try:
|
2020-02-01 16:40:11 +01:00
|
|
|
float(x)
|
|
|
|
return x
|
2019-12-18 15:18:46 +01:00
|
|
|
except ValueError:
|
|
|
|
return None
|