summaryrefslogtreecommitdiff
path: root/texmf-dist/scripts/ketcindy/ketlib/ketpicscifiles6/Texsetctr.sci
blob: 166af676b909a9d46c2817206028115a5ab51ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 10.01.21

function Texsetctr(Nctr,Opstr)
  Ctr=Texctr(Nctr);
  Opstr=Opstr+'%';
  OperL='+-*/%';
  Oper='';
  Va='';
  Evflg=0;
  Paflg=0;
  for I=1:length(Opstr)
    Tmp=part(Opstr,I);
    if Tmp=='('
      Paflg=1;
      if length(Va)>0
        Evflg=1;
        Va=Va+Tmp;
      end;
      continue;
    end;
    if Tmp==')'
      Paflg=0;
      if Evflg>0
        Va=Va+Tmp;
      end;
      continue;
    end;
    if Paflg>0
      Va=Va+Tmp;
      continue;
    end;
    if length(mtlb_findstr(Tmp,OperL))==0
      Va=Va+Tmp;
    else
      if Evflg>0
        Tmp1=evstr(Va);
        Va='\value{'+Tmp1+'}';
        Evflg=0;
      end;
      if Oper==''
        if length(Va)>0
          Str='\setcounter{'+Ctr+'}{'+Va+'}';
          Texcom(Str);
        end;
        Oper=Tmp;
        Va='';      
      elseif Oper=='+'
        Str='\addtocounter{'+Ctr+'}{'+Va+'}';
        Texcom(Str);
        Oper=Tmp;
        Va='';
      elseif Oper=='-'
        Str='\addtocounter{'+Ctr+'}{-'+Va+'}';
        Texcom(Str);
        Oper=Tmp;
        Va='';
      elseif Oper=='*'
        Str='\multiply\value{'+Ctr+'} by '+Va;
        Texcom(Str);
        Oper=Tmp;
        Va='';      
      elseif Oper=='/'
        Str='\divide\value{'+Ctr+'} by '+Va;
        Texcom(Str);
        Oper=Tmp;
        Va='' 
      end;
    end;
  end;
endfunction;