# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

pari_precision=20
pari_serieslength=5
ins_align=middle

matA=!rawmatrix $matA
!if $wims_warn_rawmatrix!=$empty
 error=rawmatrix
 wims_warn_rawmatrix=
 rawmatrix=A
!endif
matB=!rawmatrix $matB
!if $wims_warn_rawmatrix!=$empty
 error=$error rawmatrix
 rawmatrix=B
!endif

wims_rawmath_variables=A,B
show=!rawmath $show
!if $show=$empty and $matA$matB != $empty and $cmd=reply
 error=$error no_formula
 !exit
!endif

!if $cmd != resume and $matA$matB != $empty and $show != $empty
  compute=yes
 !if $matA=$empty and A isvarof $show
  error=$error empty_data
  empty_data=A
  !exit
 !endif
 !if $matB=$empty and B isvarof $show
  error=$error empty_data
  empty_data=B
  !exit
 !endif
  pariA=!translate $\
$ to ; in $matA
  pariB=!translate $\
$ to ; in $matB
  pariout=!exec pari A=Mat([$pariA]);printtex(A)\
	B=Mat([$pariB]);printtex(B)\
	C=$show;printtex(C)\
	print(C)
  !distribute lines $pariout into texA,texB,texC,rawC
  !for i in texA,texB,texC,rawC
   $i=!trim $($i)
  !next i
  !if $texA=$empty and $matA!=$empty
   error=$error bad_mat
   bad_mat=A
   !exit
  !endif
  !if $texB=$empty and $matB!=$empty
   error=$error bad_mat
   bad_mat=B
   !exit
  !endif
  !if $matA!=$empty
   texA=A=$texA
  !else
   texA=
  !endif
  !if $matB!=$empty
   texB=B=$texB
  !else
   texB=
  !endif
  !if $texC=$empty
   error=$error eval_fail
   !exit
  !endif
!endif

