10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2025-01-12 14:08:28 +01:00

Update the fromXLSToLaTeX format to correctly handle double

This commit is contained in:
Mickaël Véril 2021-10-30 16:59:14 +02:00 committed by Anthony Scemama
parent 2d8ed7b9f7
commit 7fe13a7600
2 changed files with 67 additions and 45 deletions

View File

@ -9,7 +9,7 @@ class dfbOptions(object):
self.format="line" self.format="line"
self.suffix=None self.suffix=None
self.initialStates=defaultdict(lambda : state(1,1,"A_1")) self.initialStates=defaultdict(lambda : state(1,1,"A_1"))
self.isDouble=False
@staticmethod @staticmethod
def readFromEnv(lateEnv): def readFromEnv(lateEnv):
dfb_Opt=dfbOptions() dfb_Opt=dfbOptions()
@ -42,4 +42,20 @@ class dfbOptions(object):
else: else:
mystate=state.fromString("1 "+vRArgs[0]) mystate=state.fromString("1 "+vRArgs[0])
dfb_Opt.initialStates[vOArgs[0]]=mystate dfb_Opt.initialStates[vOArgs[0]]=mystate
dfbIsDouble=lateEnv.isDouble
if dfbIsDouble!=None:
dfbIsDouble=dfbIsDouble.expr
if type(dfbIsDouble) is TexCmd:
if len(dfbIsDouble.args)==0:
dfb_Opt.isDouble = True
elif len(dfbIsDouble.args)==1 and dfbIsDouble.args[0].type=="optional":
isDoubleStr=dfbIsDouble.args[0].value
if isDoubleStr == "true":
dfb_Opt.isDouble = True
elif isDoubleStr == "false":
isDouble = False
else:
raise ValueError("\isDouble must be 'true' or 'false'.")
else:
raise ValueError("Arguments error on '\isDouble'. Only one optional argument is supported.")
return dfb_Opt return dfb_Opt

View File

@ -6,25 +6,33 @@ from ...LaTeX import newCommand,extractMath
import numpy as np import numpy as np
import json import json
import itertools import itertools
def GetTypeFromAcronym(acronym): @formatName("fromXLSToLaTeX")
class fromXLSToLaTeXHandler(formatHandlerBase):
def GetTypeFromAcronym(self,acronym):
ra = r'\rightarrow'
acroDict={ acroDict={
"npi":r"n \rightarrow \pi^\star", "npi":rf'n {ra} \pi^\star',
"ppi":r"\pi \rightarrow \pi^\star", "ppi":rf'\pi {ra} \pi^\star',
"n3s":r"n \rightarrow 3s", "n3s":rf'n {ra} 3s',
"n3p":r"n \rightarrow 3p", "n3p":rf'n {ra} 3p',
"dou":"double", "dou":"double",
"p3s":r"\pi \rightarrow 3s", "p3s":rf'\pi {ra} 3s',
"p3p":r"\pi \rightarrow 3p", "p3p":rf'\pi {ra} 3p',
"spi":r"\sigma \rightarrow \pi^\star", "spi":rf'\sigma {ra} \pi^\star',
"CT":r"CT", "CT":r'CT',
"non-d":None, "non-d":None,
"n.d.":None "n.d.":None
} }
try: try:
return acroDict[acronym] value = acroDict[acronym]
if self.TexOps.isDouble and ra in value:
lr = [i.strip() for i in value.split(ra)]
return f'{lr[0]},{lr[0]} {ra} {lr[1]},{lr[1]}'
else:
return value
except KeyError as ex: except KeyError as ex:
raise ValueError(f"Unrecognized acronym: {acronym}") from ex raise ValueError(f"Unrecognized acronym: {acronym}") from ex
def GetFullState(TexState,defaultDatatype=DataType.ABS,VR=None,typeAcronym=None,Soup=True): def GetFullState(self,TexState,defaultDatatype=DataType.ABS,VR=None,typeAcronym=None,Soup=True):
datatype=defaultDatatype datatype=defaultDatatype
lst=list(TexState) lst=list(TexState)
if len(lst)>1 and lst[1].value=="F": if len(lst)>1 and lst[1].value=="F":
@ -37,7 +45,7 @@ def GetFullState(TexState,defaultDatatype=DataType.ABS,VR=None,typeAcronym=None,
if VR!=None: if VR!=None:
fulltype.append(r"\mathrm{"+VR+"}") fulltype.append(r"\mathrm{"+VR+"}")
if typeAcronym!=None: if typeAcronym!=None:
_type=GetTypeFromAcronym(typeAcronym) _type=self.GetTypeFromAcronym(typeAcronym)
if _type!=None: if _type!=None:
fulltype.append(_type) fulltype.append(_type)
if len(fulltype)>0: if len(fulltype)>0:
@ -48,8 +56,6 @@ def GetFullState(TexState,defaultDatatype=DataType.ABS,VR=None,typeAcronym=None,
else: else:
return resultstr return resultstr
@formatName("fromXLSToLaTeX")
class fromXLSToLaTeXHandler(formatHandlerBase):
def readFromTable(self,table): def readFromTable(self,table):
datalist=list() datalist=list()
subtablesRange=getSubtablesRange(table,firstindex=1,column=1) subtablesRange=getSubtablesRange(table,firstindex=1,column=1)
@ -77,7 +83,7 @@ class fromXLSToLaTeXHandler(formatHandlerBase):
methodname=str(methtex) methodname=str(methtex)
mymethod=method(methodname,basis) mymethod=method(methodname,basis)
methkey=json.dumps(mymethod.__dict__) methkey=json.dumps(mymethod.__dict__)
mathstates=[GetFullState(table[i,4],VR=str(table[i,6]),typeAcronym=str(table[i,7]),Soup=True) for i in myrange] mathstates=[self.GetFullState(table[i,4],VR=str(table[i,6]),typeAcronym=str(table[i,7]),Soup=True) for i in myrange]
finsts=dataFileBase.convertState(mathstates,initialState,default=self.TexOps.defaultType,commands=self.Commands) finsts=dataFileBase.convertState(mathstates,initialState,default=self.TexOps.defaultType,commands=self.Commands)
for index,cell in enumerate(col[myrange]): for index,cell in enumerate(col[myrange]):
if str(cell)!="": if str(cell)!="":