diff options
Diffstat (limited to 'Master/texmf-dist/scripts/ketcindy/ketlib/ketcindylibbasic3r.cs')
-rw-r--r-- | Master/texmf-dist/scripts/ketcindy/ketlib/ketcindylibbasic3r.cs | 384 |
1 files changed, 337 insertions, 47 deletions
diff --git a/Master/texmf-dist/scripts/ketcindy/ketlib/ketcindylibbasic3r.cs b/Master/texmf-dist/scripts/ketcindy/ketlib/ketcindylibbasic3r.cs index 8a953f20a95..b5308c171bf 100644 --- a/Master/texmf-dist/scripts/ketcindy/ketlib/ketcindylibbasic3r.cs +++ b/Master/texmf-dist/scripts/ketcindy/ketlib/ketcindylibbasic3r.cs @@ -14,7 +14,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/> // -println("ketcindylibbasic3[20190623] loaded"); +println("ketcindylibbasic3[20190918] loaded"); //help:start(); @@ -356,7 +356,7 @@ Defvar(name,value):=( if(isstring(#), // 16.11.14 tmp1=tmp1+Dq+#+Dq+","; // 16.11.14 , - tmp1=tmp1+format(#,5)+","; + tmp1=tmp1+format(#,16)+","; //190918 ); ); tmp1=substring(tmp1,0,length(tmp1)-1)+"]"; @@ -452,11 +452,15 @@ Deffun(name,bodylist):=( regional(funstr,str,Pos,nbody,bdy,ppL,bpL,excma,tmp,tmp1,tmp2); funstr=name+":=("; forall(bodylist, - funstr=funstr+#+";"; + tmp1=Removespace(#); //190816from +// tmp=substring(tmp1,length(tmp1)-1,length(tmp1)); +// if(tmp!=",", tmp1=tmp1+";"); + tmp1=tmp1+";"; + funstr=funstr+tmp1; //190816to ); funstr=funstr+");"; parse(funstr); - tmp=indexof(name,"("); + tmp=indexof(name,"("); // no ketjs on //190814 str=substring(name,0,tmp-1)+"<-function"+PaO(); str=str+substring(name,tmp,length(name))+"{"; forall(1..(length(bodylist)-1),nbody, @@ -492,8 +496,10 @@ Deffun(name,bodylist):=( str=str+bdy+";"; ); ); - str=str+"return"+PaO()+bodylist_(length(bodylist))+")}"; - FUNLIST=append(FUNLIST,str); + tmp1=bodylist_(length(bodylist)); //190816from + tmp1=RSform(tmp1,2); + str=str+"return"+PaO()+tmp1+")}"; //190816to + FUNLIST=append(FUNLIST,str); // no ketjs off ); ////%Deffun end//// @@ -2963,12 +2969,14 @@ Gcd(xL,nmx):=( ); ////%Gcd end//// -////%Fracform start//// //190623 +////%Fracform start//// //190623,29 Fracform(x):=Fracform(x,5); -Fracform(x,denorg):=( +Fracform(x,den):=Fracform(x,den,5); +Fracform(x,denorg,deg):=( //help:Fracform(1.3); -//help:Fracform(1.3,[denomlist]); - regional(den,fL,tmp,nn,mm,err); +//help:Fracform(1.3,[denomlist],5); + regional(Eps,den,fL,flg,tmp,nn,mm,err); + Eps=10^(-deg); den=denorg; if(islist(den), if(!contains(den,1), den=prepend(1,den)); @@ -2976,19 +2984,29 @@ Fracform(x,denorg):=( den=1..den; ); fL=[]; + flg=0; forall(den, - tmp=round(x*#); - fL=append(fL,[tmp,#,abs(tmp/#-x)]); + if(flg==0, + tmp=round(x*#); + tmp=[tmp,#,abs(tmp/#-x)]; + if(tmp_3<Eps, + flg=1; + , + fL=append(fL,tmp); + ); + ); + ); + if(flg==0, + fL=sort(fL,#_3); + tmp=fL_1; ); - fL=sort(fL,#_3); - tmp=fL_1; mm=tmp_1; nn=tmp_2; err=tmp_3; if(nn>1, out="fr("+text(mm)+","+text(nn)+")"; , out=text(mm); ); - [out,"err="+format(err,6)]; + [out,"err="+format(err,6),mm,nn]; //190914 ); ////%Fracform end//// @@ -3067,9 +3085,21 @@ Totexformpart(str):=( //190514 ////%Totexform start//// Totexform(str):=( //190514 //help:Totexform("frac(2,3)"); - regional(out,plv,flg,nn,tmp,tmp1); - out=replace(str," ","\ "); - out=replace(str,"*"," "); + regional(out,plv,flg,nn,tmp,tmp1,tmp2); + out=replace(str,"pi","\pi"); //190715 + tmp1=apply(0..9,text(#)); //190915from + tmp2=Indexall(out,"*"); + forall(tmp2, + tmp=substring(out,#,#+1); + if(contains(tmp1,tmp), + out=substring(out,0,#-1)+"$"+substring(out,#,length(out)); + , + out=substring(out,0,#-1)+"%"+substring(out,#,length(out)); + ); + ); + out=replace(out,"$","\cdot "); + out=replace(out,"%",""); //190915to + out=replace(out," ","\;"); plv=Bracket(out,"()"); //190515from flg=0; //190521from if(length(plv)==0, @@ -3102,7 +3132,6 @@ Totexform(str):=( //190514 out=replace(out,"-+","\mp "); out=replace(out,"<=","\leq "); out=replace(out,">=","\geq "); - out=Assign(out,["pi","\pi"]); //190521 tmp1=Indexall(out,"^"); forall(tmp1,nn, if(substring(out,nn,nn+1)=="(", @@ -3110,8 +3139,9 @@ Totexform(str):=( //190514 tmp2=select(tmp2,#_2==-1); tmp2=tmp2_1_1+nn; tmp=substring(out,nn+1,tmp2-1); + tmp2=substring(out,tmp2,length(out));//190915 out=substring(out,0,nn)+"{"+tmp+"}"; - out=out+substring(out,tmp2,length(out)); + out=out+tmp2; ); ); ); @@ -3196,6 +3226,10 @@ Tocindyform(str):=( //190521 //help:Tocindyform("frac(2,3)"); regional(out,plv,flg,nn,tmp,tmp1); out=str; + out=replace(out,"\",""); //190712[4lines] + out=replace(out," "," "); + out=replace(out," "," "); + out=replace(out," ","*"); plv=Bracket(out,"()"); flg=0; if(length(plv)==0, @@ -3223,19 +3257,6 @@ Tocindyform(str):=( //190521 ); ); ); - if(flg<=1, - tmp1=Indexall(out,"^"); - forall(tmp1,nn, - if(substring(out,nn,nn+1)=="(", - tmp2=Bracket(substring(out,nn,length(out)),"()"); - tmp2=select(tmp2,#_2==-1); - tmp2=tmp2_1_1+nn; - tmp=substring(out,nn+1,tmp2-1); - out=substring(out,0,nn)+"{"+tmp+"}"; - out=out+substring(out,tmp2,length(out)); - ); - ); - ); out=replace(out,"{","("); out=replace(out,"}",")"); out; @@ -3352,10 +3373,19 @@ Setketcindyjs(list):=( ); ////%Setketcindyjs end//// +////%Ketcindyjsbody start//// 190909 +Ketcindyjsbody(list1,list2):=( +//help:Ketcindyjsbody(listfront,listrear); + JSBODY=[list1,list2]; + JSBODY; +); +////%Ketcindyjsbody end//// + ////%Ketcindyjsdata start//// //190421 Ketcindyjsdata(datalistorg):=( //help:Ketcindyjsdata(["ans",ans,"pea[parse]",pea]); regional(nn,func,tmp,tmp1,tmp2); + if(!islist(KetcindyjsDataList),KetcindyjsDataList=[]); //190801 datalist=datalistorg; forall(1..(length(datalist)/2), nn, //190423from tmp1=datalist_(2*nn-1); @@ -3383,11 +3413,12 @@ Ketcindyjsdata(datalistorg):=( ); tmp2=substring(tmp,0,length(tmp)-1)+"]"; , - tmp2=Dqq(tmp2); + if(isstring(tmp2),tmp2=Dqq(tmp2)); ); tmp=tmp1+"="+tmp2; KetcindyjsDataList=append(KetcindyjsDataList,tmp); - ); //190423to + KetcindyjsDataList=set(KetcindyjsDataList); //190802 + ); ); Ketcindyjsdata(name,vaL):=( Ketcindyjsdata([name,vaL]); @@ -3595,15 +3626,163 @@ Textedit2value(no,options):=( ); ////%Textedit2value end//// +////%Parsejson start//// +Parsejson(json):=( +//help:Parsejson("{a:[1,2,[3,4],5],b:{1,2,3}}"); + regional(outL,symbolleftL,symbolrightL,symbolstack,stacksize,leftpos,rightpos,breakflg,strflg,flg); + outL=[]; + symbolleftL =["[","{"]; + symbolrightL=["]","}"]; + leftpos=1; + while(leftpos<=length(json), + while( ( json_leftpos==" " % json_leftpos=="{" ) & leftpos<=length(json), leftpos=leftpos+1); + rightpos=leftpos; + symbolstack=" "; + stacksize=0; + breakflg=0; + strflg=0; + while(breakflg==0 & rightpos<=length(json), + flg=0; + if(strflg==0 & json_rightpos==unicode("0022"), // unicode("0022")='"' + strflg=1; + flg=1; + ); + if(flg==0 & strflg==1 & json_rightpos==unicode("0022"), + strflg=0; + flg=1; + ); + if(strflg==0, + repeat(length(symbolleftL), + if(flg==0 & stacksize>0, + if(symbolstack_stacksize==symbolleftL_# & json_rightpos==symbolrightL_#, + stacksize=stacksize-1; + flg=1; + ); + ); + if(flg==0 & json_rightpos==symbolleftL_#, + stacksize=stacksize+1; + symbolstack_stacksize=symbolleftL_#+" "; + flg=1; + ); + ); + if(flg==0 & json_rightpos==",", + if(stacksize==0, breakflg=1); + flg=1; + ); + if(flg==0 & json_rightpos=="}", + if(stacksize==0, breakflg=1); + flg=1; + ); + ); + if(breakflg==0,rightpos=rightpos+1); + ); + if(leftpos<rightpos,outL=append(outL,substring(json,leftpos-1,rightpos-1))); + leftpos=rightpos+1; + ); + outL; +); +////%Parsejson end//// + +////%Resizetextsize start//// +Resizetextsize(json,defaultsize,scale):=( +//help:Resizetextsize("{textsize: 10}",12,4); +//help:Resizetextsize("{aaa: bbb}",12,4); + regional(out,propertiesL,textsize,existflg,breakflg); + out=json; + propertiesL=Parsejson(out); + existflg=indexof(out,"textsize"); + if(existflg==0, + if(length(propertiesL)>0, + textsize="textsize: "+round(scale*defaultsize); + out=replace(out,propertiesL_length(propertiesL),propertiesL_length(propertiesL)+", "+textsize); + ); + ); + if(existflg>0, + breakflg=0; + forall(propertiesL, + if(breakflg==0 & indexof(#,"textsize")>0, + textsize="textsize: "+round(scale*parse(substring(#,indexof(#,":"),length(#)))); + out=replace(out,#,textsize); + breakflg=1; + ); + ); + ); + out; +); +////%Resizetextsize end//// + +////%Movetojs start//// +Movetojs(geoorg,pos,textsize):=( +//help:Movetojs(Text51,[1,2],12); + regional(geo); //190729from + geo=geoorg; + if(isreal(geo),geo=parse("Text"+text(geo))); //190729to + inspect(geo,"textsize",textsize); + if(!islist(MOVETOJSLIST), MOVETOJSLIST=[]); //190802 + MOVETOJSLIST=append(MOVETOJSLIST,[geo.name,[pos_1,pos_2]]); +); +////%Movetojs end//// + +////%Movetojsexe start//// +Movetojsexe(json):=( + regional(out,geo,propertiesL,breakflg); + out=json; + geo=select(MOVETOJSLIST,indexof(json,"name: "+Dqq(#_1))>0); + if(length(geo)>0, + geo=geo_1; + propertiesL=Parsejson(out); + forall(propertiesL, + breakflg=0; + if(breakflg==0 & ( indexof(#,"pos:")>0 % indexof(#,"dock:")>0 ), + out=replace(out,#,"pos: ["+geo_2_1+","+geo_2_2+",1]"); + breakflg=1; + ); + ); + ); + out; +); +////%Movetojsexe end//// + +////%Setplaybuttons start//// +Setplaybuttons(pt,font):=Setplaybuttons(pt_1,pt_2,font,[]); +Setplaybuttons(Arg1,Arg2,Arg3):=( + if(islist(Arg1), + Setplaybuttons(Arg1_1,Arg1_2,Arg2,Arg3); + , + Setplaybuttons(Arg1,Arg2,Arg3,[]); + ); +); +Setplaybuttons(x,y,font,sporg):=( +//help:Setplaybuttons(-2,-6,14); +//help:Setplaybuttons([-2,-6],14,[1,1,1]); + regional(x1,sp,tmp,tmp1); + sp=sporg; + tmp=length(sp); + if(tmp==0,tmp1=0,tmp1=sp_tmp); + tmp=apply(1..(3-tmp),tmp1); + sp=concat(sp,tmp); + x1=x; + Movetojs(71,[x1,y],font); + x1=x1+(0.84*font+sp_1)/10; + Movetojs(72,[x1,y],font); + x1=x1+(1.06*font+sp_2)/10; + Movetojs(73,[x1,y],font); + x1=x1+(0.76*font+sp_3)/10; + Movetojs(74,[x1,y],font); +); +////%Setplaybuttons end//// + ////%Mkketcindyjs start//// 190115 Mkketcindyjs():=Mkketcindyjs(KETJSOP); //190129 Mkketcindyjs(options):=( //17.11.18 //help:Mkketcindyjs(); //help:Mkketcindyjs(options=["Local=(y)","Scale=(1)","Nolabel=[]","Color=","Grid="]); -//help:Mkketcindyjs(optionsadd=["Web=(y)","Path=Dircdy","Ignore=","Equal="]); +//help:Mkketcindyjs(optionsadd=["Web=(y)","Path=Dircdy","Ignore=","Remove=(list)"]); +//help:Mkketcindyjs(optionsadd2=["Equal=","Axes=","Figure=(n)"]); regional(webflg,localflg,htm,htmorg,from,upto,flg,fL,fun,jj,tmp,tmp1,tmp2,tmp3, libnameL,libL,lib,jc,nn,name,partL,toppart,lastpart,path,ketflg,flg,cmdL,scale, - nolabel,color,grid,out,Out,igno,onlyflg,rmptL,colorrgb,ptname,eqflg,eqrep); + nolabel,color,grid,axes,out,Out,igno,onlyflg,rmptL,colorrgb,ptname,eqflg,eqrep, + figure,dpi,margin,defaultbuttonsize,defaulteditsize); libnameL=["basic1","basic2","basic3","3d"]; //190416,190428 webflg="Y"; //190128 texflg removed localflg="Y"; //190209,0215 @@ -3611,7 +3790,13 @@ Mkketcindyjs(options):=( //17.11.18 nolabel=["SW","NE"]; //190129 color="lightgray"; //190503 eqflg=0; //190603 + figure=0; + dpi=86.4; // 12px/10pt = 12px/(10/72)in = 86.4dpi + margin=5; // mm + defaultbuttonsize=12; // px + defaulteditsize=12; // px grid=""; + axes=""; path=Dircdy; igno=[]; rmptL=REMOVEPTJS; @@ -3658,6 +3843,12 @@ Mkketcindyjs(options):=( //17.11.18 grid=tmp2; ); ); + if(tmp1=="A", + if(length(tmp2)>0, + tmp2=Toupper(substring(tmp2,0,1)); //190729[2lines] + if(contains(["N","F"],tmp2),axes="false"); + ); + ); if(tmp1=="E", //190603from eqflg=1; if(length(tmp2)>0, @@ -3684,6 +3875,11 @@ Mkketcindyjs(options):=( //17.11.18 rmptL=concat(rmptL,tmp2); ); //190503to ); //190503to + if(tmp1=="F", + if(length(tmp2)>0, + if(Toupper(substring(tmp2,0,1))=="Y",figure=1,figure=0); + ); + ); ); if(substring(color,0,1)=="[", tmp=parse(color); @@ -3911,12 +4107,25 @@ Mkketcindyjs(options):=( //17.11.18 ); ); ); + Ketcindyjsdata(["Ketcindyjsfigure",figure,"Ketcindyjsscale",scale]);//190801from[moved] + forall(KetcindyjsDataList, + println(SCEOUTPUT,#+";"); + ); //190801to[moved] tmp=select(partL,#_1=="csinit"); if(length(tmp)>0, tmp=tmp_1; - from=tmp_2+5; //190206 + from=tmp_2; //190905from + flg=0; + forall(1..6, + if(flg==0, + if(indexof(htmorg_from,"ketcindy.ini")>0, + flg=1; + ); + from=from+1; + ); + );//190905to upto=tmp_3; - tmp1=htmorg_((from+1)..(upto-1)); //190119 + tmp1=htmorg_((from)..(upto-1)); //190905 ketflg="off"; //190206from onlyflg="off"; //190502 forall(tmp1, @@ -3945,9 +4154,6 @@ Mkketcindyjs(options):=( //17.11.18 ); ); ); - forall(KetcindyjsDataList, //190422from - println(SCEOUTPUT,#+";"); - ); //190422to println(SCEOUTPUT,"</script>"); tmp=select(partL,#_1=="csdraw"); tmp=tmp_1; @@ -4001,6 +4207,8 @@ Mkketcindyjs(options):=( //17.11.18 nn=Indexall(tmp,Dq); tmp=substring(tmp,nn_1,nn_2-1); if(!contains(tmp2,tmp), + tmp1_jj=Movetojsexe(tmp1_jj); + if(figure>0,tmp1_jj=Resizetextsize(tmp1_jj,defaultbuttonsize,scale)); out=append(out,tmp1_jj); //190129 ); flg=1; @@ -4009,6 +4217,8 @@ Mkketcindyjs(options):=( //17.11.18 if(indexof(tmp1_jj,"Evaluate")>0, tmp=replace(tmp1_jj,Dqq("Evaluate"),Dqq("EditableText")); if(eqflg==1,tmp=replace(tmp,"=",eqrep)); //190604 + tmp=Movetojsexe(tmp); + if(figure>0,tmp=Resizetextsize(tmp,defaulteditsize,scale)); out=append(out,tmp); flg=1; ); @@ -4016,8 +4226,10 @@ Mkketcindyjs(options):=( //17.11.18 if(flg==0, if(indexof(tmp1_jj,"Calculation")>0, tmp=replace(tmp1_jj,Dqq("Calculation"),Dqq("EditableText")); + tmp=Movetojsexe(tmp); if(eqflg==1,tmp=replace(tmp,"=",eqrep)); //190604 - out=append(out,tmp); + if(figure>0,tmp=Resizetextsize(tmp,defaulteditsize,scale)); + out=append(out,tmp); flg=1; ); ); @@ -4100,6 +4312,7 @@ Mkketcindyjs(options):=( //17.11.18 if(substring(tmp1,length(tmp1)-1,length(tmp1))==",", //190201from out_(tmp-1)=substring(tmp1,0,length(tmp1)-1); ); //190201to + if(figure==0, tmp=select(1..(length(out)),indexof(out_#,"width:")>0); jj=tmp_1; tmp1=out_jj; @@ -4110,7 +4323,7 @@ Mkketcindyjs(options):=( //17.11.18 if(tmp==":", tmp2=substring(tmp1,#+1,length(tmp1)-1); flg=1; - ); + );d ); ); tmp=round(scale*parse(tmp2)); @@ -4130,6 +4343,21 @@ Mkketcindyjs(options):=( //17.11.18 ); tmp=round(scale*parse(tmp2)); out_jj=" height: "+text(tmp)+","; + ); + if(figure>0, + tmp=select(1..(length(out)),indexof(out_#,"width:")>0); + jj=tmp_1; + tmp=round(dpi*scale*(XMAX-XMIN+margin/10*2)*10/25.4); + out_jj=" width: "+text(tmp)+","; + tmp=select(1..(length(out)),indexof(out_#,"height:")>0); + jj=tmp_1; + tmp=round(dpi*scale*(YMAX-YMIN+margin/10*2)*10/25.4); + out_jj=" height: "+text(tmp)+","; + tmp=select(1..(length(out)),indexof(out_#,"transform:")>0); + jj=tmp_1; + tmp=" transform: [{visibleRect: ["+text(XMIN-margin/10)+","+text(YMAX+margin/10); + out_jj=tmp+","+text(XMAX+margin/10)+","+text(YMIN-margin/10)+"]}],"; + ); if(length(color)>0, tmp=select(1..(length(out)),indexof(out_#,"background: ")>0); jj=tmp_1; @@ -4146,9 +4374,71 @@ Mkketcindyjs(options):=( //17.11.18 ); out_jj=tmp1; ); - forall(out, - println(SCEOUTPUT,#); - ); //190129to + if(length(axes)>0, + tmp=select(1..(length(out)),indexof(out_#,"axes:")>0); + if(length(tmp)>0, + jj=tmp_1; + tmp1=" axes: "+axes; + if(indexof(out_jj,",")>0, + tmp1=tmp1+","; + ); + out_jj=tmp1; + ); + ); + forall(out,tmp1, //190910from + if(indexof(tmp1,"</body>")==0, + println(SCEOUTPUT,tmp1); + if(indexof(tmp1,"<body>")>0, + forall(JSBODY_1, + tmp2=replace(#,"_;"," "); + tmp2=Removespace(tmp2); + tmp=indexof(tmp2,">"); + tmp3=substring(tmp2,1,tmp-1); + if(indexof(tmp3,"p")>0, + tmp2=substring(tmp2,tmp,length(tmp2)); + ); + tmp3=Strsplit(tmp3,","); + forall(reverse(1..(length(tmp3))),nn, + tmp=tmp3_nn; + if(substring(tmp,0,1)=="f", + tmp="<font size="+Dqq(substring(tmp,1,length(tmp)))+">"; + tmp2=tmp+tmp2+"</font>"; + ); + if(substring(tmp,0,1)=="p", + tmp2="<p>"+tmp2+"</p>"; + ); + ); + tmp2=replace(tmp2,"''",Dq); + tmp2=" "+replace(tmp2,"`","'"); + println(SCEOUTPUT,tmp2); + ); + ); + , + forall(JSBODY_2, + tmp2=replace(#,"_;"," "); + tmp2=Removespace(tmp2); + tmp=indexof(tmp2,">"); + tmp3=substring(tmp2,1,tmp-1); + if(indexof(tmp3,"p")>0, + tmp2=substring(tmp2,tmp,length(tmp2)); + ); + tmp3=Strsplit(tmp3,","); + forall(reverse(1..(length(tmp3))),nn, + tmp=tmp3_nn; + if(substring(tmp,0,1)=="f", + tmp="<font size="+Dqq(substring(tmp,1,length(tmp)))+">"; + tmp2=tmp+tmp2+"</font>"; + ); + if(substring(tmp,0,1)=="p", + tmp2="<p>"+tmp2+"</p>"; + ); + ); + tmp2=replace(tmp2,"''",Dq); + tmp2=" "+replace(tmp2,"`","'"); + println(SCEOUTPUT,tmp2); + ); + ); + ); //190910to closefile(SCEOUTPUT); setdirectory(Dirwork); if(webflg=="Y",tmp="json",tmp="jsoff"); |