\documentclass[papersize,a4paper,12pt]{article}
\usepackage{ketpic,ketlayer}
\usepackage{amsmath,amssymb}
% \usepackage{amsmath,newtxmath}
%\usepackage[dvipdfmx]{graphicx,color}
\usepackage{graphicx,color}
\usepackage{wrapfig}
%\usepackage[dvipdfmx,bookmarks=false,colorlinks=true,linkcolor=blue]{hyperref}
\usepackage[bookmarks=false,colorlinks=true,linkcolor=blue]{hyperref}
\setmargin{20}{20}{15}{25}
\usepackage{setspace}
\usepackage{comment}
\usepackage{bm,enumerate}
\usepackage{pict2e}

%\newcommand{\cmd}[1]{
%\begin{center}{\bf\large #1}\end{center}
%\hypertarget{#1}{}
%}

\newenvironment{cmd}[2]{
\hypertarget{#2}{}
\begin{center}{\bf\large #1}\end{center}
\begin{description}
}{
\end{description}
\begin{flushright} \hyperlink{functionlist}{$\Rightarrow$Command List}\end{flushright}
}

% item command for this documentation
\newcommand{\itemket}[1]{
\item[\Ltab{27mm}{#1}]
}


\begin{document}
\title{Guide to \ketcindy}
\author{\ketcindy\ Project Team}
\maketitle

\begin{center}  - ver.3.2 -\end{center}

\hypertarget{index}{}
\tableofcontents

\newpage

\section{About \ketcindy}

\subsection{Overview}

\ketcindy\ is a library of Cindyscript 
which is a programming language of Cinderella. 
It converts the data computed 
for generating dynamic graphics on Cinderella 
into \TeX\ graphical codes. 
Synchronized use of 
interactive graphics capabilities of Cinderella 
and well-structured programming capabilities of Cindyscript 
enables ordinary \TeX\ users to efficiently embed 
high-quality graphics into \TeX\ documents. 
Moreover, the collaborative use of \ketcindy\ 
and other software such as R, Maxima and C 
has been enabled.

\begin{center}
\input{Fig/concept}
\end{center}

Firstly, dynamic figure is generated on Cinderella. 
Secondly, \ketcindy\ generates 
a source file of R and makes R execute it 
for the generation of \TeX\ graphical codes. 
Thirdly, those codes are formatted into 
\TeX\ file which is input in the targetting \TeX\ document 
via the command \verb|\input|. 
Finally, usual compilation procedure of \TeX\ results in 
the generation of final PDF output 
including the corresponding figure. 
A batch file \verb|kc.bat| for Windows 
or a shell file \verb|kc.sh| for Mac or Linux 
is generated via \ketcindy\ 
in order to batch-process all the steps 
from the second to the last. 
Also by using these files, 
collaboration of Cinderella and other software 
as shown in the schematic diagram above 
is processed. 

Summarizingly, specific steps to generate a \TeX\ figure 
are listed as follows.

\begin{enumerate}[(1)]
\item 
Generate the needed geometric elements 
on the Euclidean view of Cinderella 
using its drawing tools. 
These elements can be moved interactively. 

\hspace{30mm}\includegraphics[bb=0.00 0.00 408.02 347.02,width=6cm]{Fig/incenter01.pdf}

\item 
Input the \ketcindy\ codes into Cindyscript editor 
to specify the graphical elements to be displayed 
in \TeX\ final output. 
Also \ketcindy\ codes are used 
to generate supplementary graphical elements 
and handle them. 

\hspace{10mm}\includegraphics[bb=0.00 0.00 811.04 257.01,width=12cm]{Fig/incenter02E.pdf}

In this stage, the programming capabilities 
inherently implemented to Cindyscript can be used simultaneously. 
Execute the whole program by clicking the "Run" button. 
For more details, see section 3. 

\item 
Click the button named \verb|Figures| in Euclidean view 
to automatically generate the following files 
in the folder named "fig". 
Here, "incenter" is the name specified 
via the command \verb|Setfiles("incenter")| 
in step (2). 

\begin{tabbing}
12\=1234567897890123456\=\kill

 \> \verb|kc|.sh or \verb|kc.bat| \> shell script file(Mac) or batch file(Windows) \\
 \> \verb|incenter.r| \> \\
 \> \verb|incenter.tex| \> \TeX\ file composed of graphical codes\\
 \> \verb|incentermain.aux| \> \\
 \> \verb|incentermain.log| \> \\
 \> \verb|incentermain.pdf| \> PDF file to display the resulting graphical image\\
 \> \verb|incentermain.tex| \> \TeX\ file temporarily used to generate 
the file \verb|incentermain.pdf|
\end{tabbing}

Subsequently, the file \verb|incentermain.pdf| 
is automatically displayed as shown below. 

\hspace{30mm}\includegraphics[bb=0.00 0.00 348.02 284.51,width=6cm]{Fig/incenter03.pdf}

We can manipulate this final output 
by modifying the inputs in steps (1) and (2) 
before processing the step (3) again. 

\vspace{\baselineskip}
\item  
Using \ketpic\ package of \TeX , 
\verb|incenter.tex| can be read 
into the targetting \TeX\ document 
via the command 
\begin{center}
\verb|\input{incenter}|
\end{center} 
Then the same figure is embedded in the targetting PDF output. 

\end{enumerate}


\newpage

\subsection{Geometric Figures}

Producing geometric figures in the plane is easy. Moreover, we can add hatchings  in some areas, which is better than shading 
for monochrome printing.
The following are the main parts of the script.

\begin{verbatim}
    Listplot([A,B,C,A]);
    Circledata([D,E]);
    Bowdata([B,A],[1,0.5,"Expr=c","da"]); 
    Bowdata([C,B],[1,0.5,"Expr=a","da"]);
    Bowdata([A,C],[1,0.5,"Expr=b","da"]); 
    Hatchdata("2",["oi"],[["crDE"],["sgABCA"]],["dr,0.7",""]); 
    Pointdata("I",D,["size=4"]);
    Letter([A,"sw","A",B,"ne","B",C,"se","C",D,"se","I"]);
\end{verbatim}

\begin{center}
\includegraphics[bb=0.00 0.00 416.00 347.00,height=42mm]{Fig/hatch.pdf}
\hspace{2mm}
\input{Fig/s106bowhatch.tex}
\end{center}


\subsection{Graphs of Functions}
\ketcindy\ can produce graphs of functions with
\begin{verbatim}
    Plotdata("1","x^2","x");
\end{verbatim}
or parametrically with
\begin{verbatim}
    Paramplot("1","[2*cos(t),sin(t)]", "t=[0,2*pi]");
\end{verbatim}
\noindent Here we give an example of the solution curve of a differential equation. The script is:
%\verb|        // data are assigned to the variable de1.|\\
%\verb|        // [0,XMAX] is the range of t.|\\
\begin{verbatim}
    Deqplot("1","y``=-L.x*y`-G.x*y","t=[0,XMAX]",0,[C.y,0]);
    // the equation is y''=-ay'-by (a=L.x, b=G.x).
    // C.y,0 are initial values of y and y' at t=0.
    Expr(M,"e","\displaystyle\frac{d^2 x}{dt^2}+"
           +"+L.x+"\frac{dx}{dt}+"+G.x+"x=0");
\end{verbatim}

Note that points C, G, L  on segments AB, EF, HK are movable, and 
are used to decide the coefficients and the initial value as you can see in the above scripts.
\vspace{3mm}

\begin{center}
\includegraphics[bb=0.00 0.00 385.00 398.00,height=60mm]{Fig/diffeq1.pdf}
\hspace{5mm}
\input{Fig/s210diffeq1.tex}

\end{center}

%\putnotes{35}{53}{\input{fig/s305incanddec.tex}}
%\putnotes{35}{110}{Figure \thefigno\ \ Table}\addtocounter{figno}{1}%
%\putnotes{97}{65}{\input{fig/kumamonthin.tex}}
%\putnotes{97}{59}{%
%\includegraphics[bb=0.00 0.00 183.63 142.07]{fig/figkumamon.pdf}}
%\putnotene{100}{72}{\input{fig/kumamoto.tex}}
%\putnotes{97}{110}{Figure \thefigno\ \ B\'ezier Curve}\addtocounter{figno}{1}%

\subsection{Drawing Tables}
Writing the code for tables to be inserted into the \TeX\ documents is sometimes troublesome.
However, it is not a hard job for \ketcindy\ (see the output in Figure.

\begin{verbatim}
      xLst=apply(1..7,15);
      yLst=[10,10,10,10,80];
      rmvL=apply(1..6,"c"+text(#)+"r4r5");
      rmvL=concat(rmvL,["r2c1c2","r3c1c2"]);
      Tabledata("",xLst,yLst,rmvL);
      Tlistplot(["c1r1","c2r4"]);
      Tlistplot(["c2r1","c1r4"]);
      Putrowexpr(1,"c",
          ["x","0","\cdots","e","\cdots","e\sqrt{e}","\cdots"]);
      Putrowexpr(2,"c",["y`","","+","0","-","-","-"]);
      Putrowexpr(3,"c",["y``","","-","-","-","0","+"]);
      Putrowexpr(4,"c",["y","","","10/e","","15/e\sqrt{e}",""]);
      Putcell("c0r4","c7r5","c","\input{fig/graph}");
\end{verbatim}

\vspace{2mm}

\begin{center}
\input{Fig/s305incanddec.tex}
\end{center}


\newpage

\subsection{Plotting data}
Here we call the data computed 
to generate the graphs of functions and geometric elements 
"Plotting data" which is abbreviated as PD. 
The PD to draw segment is the list of coordinates 
of its two endpoints. 
For example, 
when the coordinates of the points A and B 
are (1, 1) and (3, 2) respectively, 
PD of the segment AB named \verb|Listplot ([A,B])| 
is stored in the form \verb|[[1,1],[3,2]]|. 
Also the PD to draw a curve is the collection of 
those for drawing small segments 
which connect contiguous dividing points of the curve. 
PD are automatically given names via \ketcindy\ 
following the rules below.

\begin{itemize}
\item 
The beginning part of the PD's name 
depends on the kind of the corresponding graphical element. 
For instance, 
\verb|sg| is associated to segments and 
\verb|cr| is associated to circles. 

\item 
When some extra name is specified 
as the first argument in the definition of PD, 
it is added to the beginning part given above. 
For instance, the PD defined below 
is given the name \verb|sg1|. 
\begin{center}
\verb|Listplot("1",[[0,0],[1,2]]);| 
\end{center}

\item 
When the extra name is not needed, 
the names of the points are added 
to the beginning part given above. 
For instance, the PD defined below  
is given the name \verb|sgABC|. 
\begin{center}
\verb|Listplot([A,B,C]);|
\end{center}

\end{itemize}

\noindent 
Once PD are generated, 
their names are displayed on the console view of Cinderella. 
For instance, when the PD named \verb|sgABCA| is generated, 
the corresponding message is displayed as shown below. 

\begin{center}
\includegraphics[bb=0.00 0.00 298.02 115.01,width=6cm]{Fig/pdtoconsole.pdf}
\end{center}
Also the content of PD is displayed 
via the function \verb|println()| of Cindyscript. 
For instance, inputting the command 
\verb|println(sgABCA)| makes the following list displayed. 
\begin{center}
\verb| [[1,3],[-1,0],[3,0],[1,3]] |
\end{center}
This list is composed of the coordinates of the points A, B, and C. 

These names of PD are used 
when the corresponding PD need to be transformed. 
For instance, 
PD to draw the parallel transport of the segment AB 
is generated via the \ketcindy\ command 
\begin{center}
\verb|Translatedata("1","sgAB",[2,3]);|
\end{center}

PD can be generated also 
by using the programming capability of Cindyscript 
which can be subsequently used in \ketcindy .  
For more details, 
see the example of \verb|Listplot()| 
in the command reference. 
Inclusion of too much elements into a single PD 
may cause some error. 
To prevent such error, 
PD should be divided into several PD 
each of which is composed of 200 elements or so. 


\newpage

\section{Cindyscript}

\subsection{Cindyscript editor}

Choose "Cindyscript" in the "Scripting" menu 
or push keybuttons Ctrl+9 (Windows) / Command+9 (Mac), 
then Cindyscript editor opens as shown below. 

\begin{layer}{150}{0}
\putnotese{7}{15}{\includegraphics[bb=0.00 0.00 703.04 425.02,width=14cm]{Fig/slotE.pdf}}
\arrowlineseg[16]{30}{20}{10}{90}
\putnotese{25}{5}{Slots}
\arrowlineseg[16]{50}{20}{10}{100}
\putnotese{42}{5}{Page name}
\arrowlineseg[16]{90}{20}{10}{110}
\putnotese{80}{5}{Font size}
%\arrowlineseg[16]{107}{20}{15}{140}
%\putnotese{80}{5}{描画面を前面に}
\arrowlineseg[16]{135}{20}{10}{110}
\putnotese{125}{5}{Run}
\arrowlineseg[16]{142}{20}{10}{100}
\putnotese{135}{5}{Help}
\putnotese{100}{35}{Text field}
\putnotese{100}{80}{Console}
\end{layer}

\vspace{105mm}

Commands can be input into preferred "slot". 
Specific timing for execution of commands 
is assigned to each slot. 
The slot for current work can be chosen 
only by clicking the corresponding tab in the menu. 
Users can add extra pages to each slot. 
For instance, 
when some initialization other than 
those included in \verb|KETlib| is needed, 
clicking the folder icon of "Initialization" makes a new page open 
in which extra commands can be input. 
The name of each page can be given 
by directly inputting it into the "Page name" column. 
The font size of the scripts can be tuned 
by changing the number in the "Font size" column. 
Frequently used slots are listed below. 

\begin{itemize}

\item 
Draw

The commnds in this slot are executed 
when some change, like movement of point, 
occurs in the Euclidean view. 
In \verb|templatebasic1.cdy|, 
the protoype page named \verb|figure| 
including the \ketcindy\ commnads 
like \verb|Ketinit();| and \verb|Windispg();| 
which are unconditionally necessary 
has been prepared.  
The \ketcindy\ commands for drawing 
should be input into this slot. 

\item 
Initialization 

The definitions of functions 
and the initial values of variables 
are input here. 
The commands in this slot are exected 
only once just after the "Run" button is clicked. 
Thus, the initial data in this slot is changed 
when some modifications are made in other slots. 
In \verb|templatebasic1.cdy|, 
the protoype page named \verb|KETlib| 
including the default setting of \ketcindy\ 
has been prepared. 

\item 
Key Typed

The commnds in this slot are executed 
when some key is pushed. 

\end{itemize}

Clicking "Run" button or pushing the keybuttons Shift+Enter 
makes the whole program be executed. 
The results derived from executing the function \verb|print()| 
and error messages are displayed on the console view 
which is put at the bottom part of Cindyscript editor. 
Each error and its location 
is displayed together with the message 
"WARNING" or "syntax error". 
The outputs displayed on the console 
can be copied to other usual text editors. 

Click the "Help" button, 
then reference manual of Cinderella opens 
as shown below. \\

\includegraphics[bb=0.00 0.00 712.04 577.03,width=14cm]{Fig/CindyhelpE.pdf}


\subsection{Input}

The attribute of each input into Cindyscript 
is specified via the color of the corresponding letters 
as listed below. 

\begin{itemize}
\item 
The functions which are inherently implemented to Cinderella 
are displayed via blue color. 
\item 
The functions which are defined by user, 
including those of \ketcindy , 
are displayed via purple color. 
\item 
The functions which are not yet defined 
are displayed via red color. 
\item 
Strings are displayed via green color. 
\end{itemize}
As in the console view, 
copying and pasting to the other usual editing software 
via pushing the keybuttons Ctrl+C and Ctrl+V 
is accessible. 
Cutting and pasting via Ctrl+X and Ctrl+V 
is also possible. 
Also as in the other editing software, 
preferred strings can be specified 
via dragging mouse 
or pushing the keybutton Shift and moving the sursor. 
Serching for words via pushing Ctrl+F 
has not been enabled. 

The fundamental rule of describing scripts on Cindyscript editor 
are listed below. 
\begin{itemize}
\item 
Upper- and lowercase letters are distinguished. 
Using lowercase letters is preferable. 
\item 
As in \TeX , 
several blanks are regarded as a single blank. 
\item 
A semicolon should be located at the end of each row. 
Starting a new paragraph 
does not result in the ending of commnds. 
\end{itemize}
Particularly, in case of \ketcindy , 
the input of commands are controlled 
by the following rules. 
\begin{itemize}
\item 
The names of global variables 
begin with uppercase letters. 
\item 
The names of local variables 
begin with lowercase letters. 
Local variables are declared at the beginning part 
of the definitions of functions 
along with the Cinderella command \verb|regional()|. 
\item 
The names of functions 
begin with uppercase letters. 
\end{itemize}


\subsection{Variables and constants}

The declaration of the attribute of each variable 
is not needed in Cindyscript 
since it is automatically decided 
according to the input. 
Moreover, 
the different kind of value 
can be input without any declaration.  \\

\noindent 
{\bf Example}

\verb|          a=10;|

\verb|          b=2;|

\verb|          c=a+sqrt(b);|

\verb|          a="the square root of"|

\verb|          println("The sum of"+a+b+''and 10 is''+c);|\\

In this example, 
the attribute of variable \verb|a| was firstly integer, 
and then changed to string at the fourth row. 

The strings should be input with double quotation marks. 
The mathematical operations 
which involve several kind of variables 
must be taken much care. 
Exceptionally, 
connecting string and number with \verb|+| 
results in the generation of one single string. 

The variable \verb|pi| is reserved in Cindyscript 
as the ratio of the circumference of a circle to its diameter. 
Also the variable \verb|i| is reserved 
as the imaginary unit. 
When \verb|i| is used as variable once, 
it is changed to the imaginary unit via the command 
\begin{center}
\verb|i=complex(0,1);|
\end{center}

There are also some reserved variables in \ketcindy . 
Among them, the following ones can be changed by users. 
\begin{tabbing}
12\=3456789012345\=678989012345678901234567890123\=\kill
\>\verb|Fhead|  \>the beginning part of the file name 
which can be set by  \verb|Setfiles()|\\
\>\verb|Texparent|  \>the name of parent file 
which can be set by \verb|Setparent()|\\
\>\verb|Dirhead|  \>the beginning part of the path\\
\>\verb|Dirlib|  \>the path to the library ketlib\\
\>\verb|Dirbin|  \>the path to ketbin\\
\>\verb|Dirwork|  \>the path to the working directory 
which can be set by \verb|Changework()|\\
\>\verb|Shellfile|  \>the name of shell file
\end{tabbing}
Contrarily, the reserved variables listed below are the global variables 
usend in the library of \ketcindy , whence cannot be changed 
by users. 

\vspace{\baselineskip}
\noindent 
ADDAXES, ArrowlineNumber, ArrowheadNumber, BezierNumber, COM0thlist, COM1stlist, COM2ndlist, Dq, FUNLIST, Fnamesc ，Fnamescibody，Fnameout，Fnametex, GDATALIST, GLIST, GCLIST, GOUTLIST, KCOLOR, KETPICCOUNT,KETPICLAYER, LETTERlist, LFmark, MilliIn, PenThick,PenThickInit,  POUTLIST, SCALEX, SCALEY, SCIRELIST, SCIWRLIST, TenSize, TenSizeInit, ULEN, XMAX, XMIN, YaSize, YaThick,   YMAX, YMIN, VLIST

\vspace{\baselineskip}

A list can be defined by putting its elements in a square bracket 
with commas separating each other. 
The attribute of each element does not matter. 
The $n$-th element can be referred by using an underbar. 
For instance, the commands 

\begin{verbatim}
    list=[1,2,3,4,5];
    list_2="a";
\end{verbatim}
make the second element be substituted by the letter \verb|"a"|. 


\subsection{Frequently used commands}

\noindent
{\bf Displaying the computed output}

\noindent 
The following commands 
make the current value of the variable 
on the console view. 

\begin{tabbing}
12345\=6789012345678989012345678901234567890\=123\=\kill
\>\verb|print(the name of variable);| \> without a line break\\
\>\verb|println(the name of variable);| \> with a line break\\  
\end{tabbing}

\noindent
{\bf Conditional branching}

\noindent
The commnad \verb|if(A,B,C)| executes \verb|B| if \verb|A| is true 
and \verb|C| otherwise. 
The followings are frequently used. 
Nested conditions can be interpreted. 

\begin{tabbing}
12345\=67890123456789890\=12345678901234567890123\=\kill
\>\verb|if(a>b,...);|\\
\>\verb|if(a<b,...);|\\
\>\verb|if(a>=b,...);| \> $a\geqq b$\\
\>\verb|if(a<=b,...);| \> $a\leqq b$\\  
\>\verb|if(a=b,...);|\\
\>\verb|if(a!=b,...);| \> $a\neq b$\\  
\end{tabbing}

\noindent
{\bf Loop program}

\noindent
The commnad \verb|for(n,operation)| executes the operation 
$n$ times. If the counter should be specified, 
modify the command as \verb|for(n,s,operation)|. 
where the value of $s$ is successively changed. 
Loop program with respect to some list instead of counter 
is also possible via the command as \verb|forall(list,operation)|. 
For example, the commands

\begin{verbatim}
    sglist=[[A,B],[C,D],[E,F]];
    forall(sglist,Listplot(#));
\end{verbatim}
have the same output as 
\begin{verbatim}
    Listplot([A,B]);
    Listplot([C,D]);
    Listplot([E,F]);
\end{verbatim}

\noindent
{\bf User's definition of functions}

\noindent
The format of definition is \verb|function name(argument):=(operation)|. 
For example, if we define the function \verb|sign(n)| by 
\begin{verbatim}
    sign(n):=(
      if(n>0,print("positive"),print("0 or negative"));
    );
\end{verbatim}
it can be used as 
\begin{verbatim}
    n=3;
    println(sign(n));
\end{verbatim}

\mbox{} 

\noindent
{\bf Reference to geometric elements}

\noindent
The position of a point can be specified 
with both its name and the list of its $x,y$-coordinates. 
Thus, both of the following formats are allowed. 
\begin{verbatim}
    Listplot("1",[[1,1],[4,5]]);
    Listplot("1",[A,B]);
\end{verbatim}
Also we can get the coordinate of a point explicitly 
via the commands 
like \verb|A.xy|, \verb|A.x|, and \verb|A.y|.

\mbox{} 

\noindent
{\bf List processing}

\noindent
The list of integers between $a$ and $b$ 
is generated via the command \verb|a..b|. 
For instance, the synchronized use with the command \verb|apply| 
as below gives the shape of pentagram. 
\begin{verbatim}
    r=2;
    pt=apply(0..5,r*[cos(pi/2+#*4*pi/5),sin(pi/2+#*4*pi/5)]);
    repeat(5,s,Listplot(text(s),[pt_s,pt_(s+1)]));
\end{verbatim}
Here the Cindyscript command \verb|text| 
is used to convert the number into string. 



% -------------- Calling other softwares --------------

\newpage

\section{Collaboration with other softwares}

\subsection{Overview}

\ketcindy\ has functionalies to call other softwares such as Maxima, Risa/Asir, R and C.
Here, we introduce how to call Maxima.\vspace{1mm}

The steps are as follows.\vspace{-2mm}

\begin{enumerate}
\item Generate the shell file to call a CAS.\vspace{-2mm}
\item Execute the file.\vspace{-2mm}
\item Return the result as text.\vspace{-2mm}
\item Use the result in \ketcindy .\vspace{-2mm}
\item Produce the PDF file.\vspace{-2mm}
\end{enumerate}

And the flowchart is  as follows:
\begin{center}
{\scalebox{0.9}{\input{Fig/calling.tex}}}

\end{center}

When interfacing with Maxima, commands \texttt{Mxfun}, \texttt{CalcbyM} and \texttt{Mxtex} are all we need to complete the task. \texttt{Mxfun} and \texttt{CalcbyM} are for calling single command and multi commands of Maxima respectively. \texttt{Mxtex} is used for code conversion to \LaTeX. The output of Maxima  is returned to \ketcindy\ as a string or a list of strings for further processing. 

The options of these commands are:\\
\hspace*{10mm}\Ltab{25mm}{{\tt "m/r"}}To decide whether the result file will be  made again or not. \\
\hspace*{10mm}\Ltab{25mm}{}If these options are not given, \ketcindy\ decides automatically.\\
\hspace*{10mm}\Ltab{25mm}{{\tt "Disp=y/n"}}To decide whether the result will be displayed in the console or not. \\
\hspace*{10mm}\Ltab{25mm}{}It is only availabe for \texttt{Mxfun} and \texttt{Mxtex}.
The default is "y".


\subsection{Commands related to Maxima}

\subsubsection*{Mxfun}

The arguments are name of variable in \ketcindy, name of a function of Maxima, and a list of arguments of the function.\\
\hspace*{10mm}\verb|Mxfun("1","diff",["sin(x)","x"]);|  // The return is "cos(x)", assgined to mx1.\\
The above is equivallent to\\
\hspace*{10mm}\verb|Mxfun("1","diff(sin(x),x)",[]);|


\subsubsection*{Mxtex}

The arguments are name of variable in \ketcindy, an expression in Maxima format.\\
\hspace*{10mm}\verb|Mxtex("1",mx1);|  // The return is \verb|"\cos x"|, assgined to tx1.\\
\hspace*{10mm}\verb|Expr([0,1],"e",tx1]);|

\begin{center}
\input{Fig/maxima1.tex}
\end{center}

\subsubsection*{CalcbyM}

The arguments are name of variable in \ketcindy, a list of commands and the arguments of Maxima.\\
\hspace*{10mm}\verb|fn="sin(x)^4";|\\
\hspace*{10mm}\verb|cmdL=[|\\
\hspace*{10mm}\verb|  "df:diff",[fn,"x"],|\\
\hspace*{10mm}\verb|  "df:ratsimp",["df"],|\\
\hspace*{10mm}\verb|  "F:integrate",[fn,"x"],|\\
\hspace*{10mm}\verb|  "F","ratsimp",["F"],|\\
\hspace*{10mm}\verb|  "df::F",[]|\\
\hspace*{10mm}\verb|];|\\
\hspace*{10mm}\verb|CalcbyM("ans",cmdL);|\vspace{2mm}\\
The returned value is a list of df and F as strings, though these are not displayed in the console. They can be used, for example,\vspace{2mm}\\
\hspace*{10mm}\verb|Plotdata("1",fn,"x",["Num=200","do"]);|\\
\hspace*{10mm}\verb|Plotdata("2",ans_1,"x",["Num=200","dr"]);|\\
\hspace*{10mm}\verb|Plotdata("3",ans_2,"x",["Num=200","da"]);|\\
\hspace*{10mm}\verb|Mxtex("1",fn);|\\
\hspace*{10mm}\verb|Mxtex("1",ans_1);|\\
\hspace*{10mm}\verb|Mxtex("2",ans_2);|\\
\hspace*{10mm}\verb|Expr([A,"e",tx1,B,"e",tx2,C,"w",tx3]);|

\vspace{2mm}

\begin{center}
\input{Fig/s10diffint.tex}
\end{center}

\noindent
{\bf Remark} See KeTCindyreferenceE.pdf for more information.

\subsection{Commands related to R}

\verb|Rfun| and \verb|CalcbyR| are simillar to \verb|Mxfun| and \verb|CalcbyM|.\\
 See \verb|KeTCindyreferenceE.pdf| or \verb|samples/s08R| for more information.

% -------------- 3d figures --------------

\newpage

\section{Three Dimentional figures of \ketcindy}

\subsection{Summary and Geometric Elements}

In KeTCindy's 3D-mode, there are two rectangular areas surrounded by a white frame on the Euclidean view.

The main area on the left side of the screen is simillar to that of two dimentional figures. Figures in this area will be drawn to the \TeX\ document. The view direction can be moved with sliders under the main area.  \verb|TH| and \verb|FI| mean angles $\theta$ and $\varphi$ respectively, which are polar cocordinates of the view direction.

Figures from the view direction $(0,\ \varphi)$ are displayed in the sub area on the right side.

 \hspace{40mm} mainarea \hspace{40mm} subarea
\begin{center}
\includegraphics[bb=0.00 0.00 863.04 378.52,width=12cm]{Fig/3dscreen.pdf}
\end{center}

With internal command \verb|Ptseg3data| which is called in \verb|Start3d|, 
a point put to the main area with the drawing tool of Cinderella is regarded as a 3D point by \ketcindy, and a correspoinding point is put in the sub area. 
Though the initial coordinate of $z$ is 0, we can change it moving the point in the sub area.

For example, if we put point \verb|A| on the main area, point \verb|Az| will be put in the sub area and the 3D coordinates calculated from \verb|A| and \verb|Az|  are assigned to varible \verb|A3d|.\vspace{-1mm}

\begin{description}
\item[\bf Remark]Note that point \verb|Az| will not be deleted automatically even if point \verb|A| is deleted. We should delete it manually.
\end{description}

Geometric segment in the main area generates the corresponding geometric segment in the sub area as well.

\subsection{Lines and Curves}

\ketcindy\ commands \verb|Spaceline| and \verb|Spacecurve| are used do draw lines and curves in the space. Additionally, \verb|Xyzax3data| is used to draw axis.

\begin{description}
\item[Examples]\mbox{}\\
\verb|Xyzax3data("","x=[-5,5]","y=[-5,5]","z=[-5,5]");|\\
\verb|Spacecurve("1","3*[cos(t),sin(t),0.1*t]","t=[0,4*pi]",["Num=200"]);|\\
\verb|pt1=[3,0,0]; pt2=[3,0,3*0.1*4*pi];|\\
\verb|Spaceline("1",[pt1,pt2]);|\\
\verb|Skeletonparadata("1");| 

\item[Remark]The last command skeleton elimination is for skeleton elimination.
Compare two figures below. The right one is with skeleton elimination.

\end{description}

\begin{center}
\input{Fig/spacelinecurve1.tex}\hspace{10mm}\input{Fig/spacelinecurve2.tex}
\end{center}

\subsection{Two Dimensional Figures}

Data of two dimensional figures such as polyhedra or planes are given in obj format.

\begin{description}
\item[Examples]\mbox{}\\
\verb|Start3d();|\\
\verb|vertex=[[2,2,-2],[2,-2,-2],[-2,-2,-2],[-2,2,-2]];|\\
\verb|Reflect3d1(``1'',vertex,[[0,0,0],[1,0,0],[0,1,0]];|\\
\verb|vertex=concat(vertex,ref3d1);|\\
\verb|edge=[[1,2,6,5],[1,5,8,4],[1,4,3,2],[2,3,7,6],[3,4,8,7],[5,6,7,8]];|\\
\verb|cube=[vertex,edge];|\\
\verb|plane=[[[-3,1,-3],[3,-1,-3],[-4,5,3],[2,3,3]],[[1,2,4,3]]];|\\
\verb|tmp=Concatobj([cubic,plane]);|\\
\verb|VertexEdgeFace("1",tmp,["Vtx=nogeo","Edg=nogeo"]);|\\
\verb|Nohiddenbyfaces("1","phf3d1");| // for the figure on the left

\item[Remark]\mbox{}\\
Command \verb|Concatobj| combines data in obj format.\\
Command \verb|VertexEdgeFace| assigns vertices to {\tt phv}, edges to {\tt phe} and faces to {\tt phf}.\\
Command \verb|Nohiddenbyfaces| is for hiddenline elimination.\\
Use \verb|Skeletonparadata("1")| if the figure on the right is desirable.
\end{description}

\vspace{-10mm}

\begin{center}
\input{Fig/polygonplane1.tex}\hspace{10mm}\input{Fig/polygonplane2.tex}
\end{center}

\noindent
{\bf Remark} See \verb|KeTCindyreferenceE.pdf| or \verb|samples/s05spacefigure| for more information.

\subsection{Surfaces}

Two variable function is defined as a list of one of the followings.

\begin{enumerate}[\hspace*{5mm}\bf 1.]
\item \verb|["z=f(x,y)","x=[a,b]","y=[c,d]"]|
\item \verb|["z=f(x,y)","x=x(u,v)","y(u,v)","u=[a,b]","v=[c,d]"]|
\item \verb|["p","x=x(u,v)","y=y(u,v)","z=z(u,v)","u=[a,b]","v=[c,d]"]|
\end{enumerate}

Optionally, you can add what boundaries should be drawn.
The default is "wesn". Here, for example, "w" means the boundary defined by $[a,t]\ (c\leqq t\leqq d)$.

\ketcindy\ calls C to speed up the calculation of hidden lines elimination.

\begin{description}
\item[Example]\mbox{}\\
\verb|Start3d();|\\
\verb|Xyzax3data("","x=[-5,5]","y=[-5,5]","z=[-5,5]");|\\
\verb|fd=["z=x^2-y^2","x=[-2,2]","y=[-2,2]","senw"];|\\
\verb|Startsurf();|\\
\verb|Sfbdparadata("1",fd);|\\
\verb|Crvsfparadata("1","ax3d","sfbd3d1",fd);|\\
\verb|ExeccmdC("1");|
\verb|Windispg();|

\begin{center}
\input{Fig/saddle1E.tex}\hspace{10mm}\input{Fig/saddle2E.tex}
\end{center}

\item[Remark]Wires can be added if necessary with command \verb|Wireparadata| as seen in the upper right side figure.
The line-style also can be changed.

See \verb|KeTCindyreferenceE.pdf| or \verb|samples/s09surfaceC| for more information.
\end{description}

\subsection{Generating Files in Obj Format}

\ketcindy\ can generate files of 3D figures in obj format. Moreover, \ketcindy\ also can call Meshlab which is a 3D viewer.

\begin{description}
\item[Examples]\mbox{}\\
\verb|Xyzax3data("","x=[-5,5]","y=[-5,5]","z=[-5,5]");|\\
\verb|fd=["p","x=4*sin(V)*cos(U)","y=4*sin(V)*sin(U)","z=4*cos(V)",|\\
\verb|     "U=[pi/2,4*pi/2]","V=[0,pi]","we"];|\\
\verb|Mkobjcmd("1",fd,[40,40,"-"]);|\\
\verb|Mkobjcrvcmd("2","ax3d",[0.05,"xy"]);|\\
\verb|Mkobjsymbcmd("x",0.2,0,[0,1,0],[5.2,0,0]);|\\
\verb|Mkobjsymbcmd("y",0.2,0,[1,0,0],[0,5.2,0]);|\\
\verb|Mkobjsymbcmd("z",0.2,0,[0,1,0],[0,0,5.2]);|\\
\verb|SetObj();|
\item[Remark]See \verb|KeTCindyreferenceE.pdf| or \verb|samples/s13meshlab| for more information.
\end{description}

% -------------- Making slide --------------

\newpage

\section{Making Slides}

\subsection{Outline}

\ketcindy\ has functions to make slides for presentation with the help of \verb|layer| environment which is defined in \verb|ketlayer.sty|.
See \verb|KeTpicStyleE.pdf| for details about \verb|layer|.

You need both a cindy file and a text file with the same header.  For simple preparation, copy \verb|template2slide.cdy| to your work folder, rename the name, for example \verb|makeslide.cdy|, double click the file and press the button \verb|title| in the screen, then \verb|makeslide.txt| will be generated.

The following chart shows the relation between them.

\begin{center}
\input{Fig/makeslideE}
\end{center}

If necessary, edit \verb|Settitle| in CindyScript editor, and press the gear mark. Open the text file, and write commands of \ketcindy\ Slide and \TeX\ as follows.

\begin{verbatim}
  title::slide0//
  main::Introduction//
  \slidepage[m]//
  new::Programming Language//
  %repeat=6,para// 
  \slidepage// 
  itemize// 
  item::Python// 
  %thin[2,-]::item::Ruby// 
  %thin[3,-]::item::Java// 
  %thin[4,-]::item::JavaScript// 
  %thin[5,-]::item::CindyScript// 
  %thin[6,-]::item::C// 
  end// 
\end{verbatim}

\begin{description}
\item[Remark]``//'' should be added to the end of all lines. Use ``||||'' when you want to write \verb|//|.
\end{description}

%\begin{center}
%\includegraphics[bb=0.00 0.00 743.00 632.00,height=60mm]{fig/slidescreen.pdf}\hspace{5mm}
%\includegraphics[bb=0.00 0.00 802.00 633.00,height=60mm]{fig/slidescript.pdf}
%\end{center}

Press the button \verb|Slide| in Cindy Screen, then \ketcindy\ will make \TeX\ file \verb|makeslide.tex|,
typeset it and displays the pdf file as follows. If there occurs an error, check the text file or the \TeX\ file.

\begin{center}
\fbox{\includegraphics[bb=0.00 0.00 542.00 385.00,height=35mm]{Fig/slidepdf1.pdf}}\hspace{5mm}%
\fbox{\includegraphics[bb=0.00 0.00 541.00 380.00,height=35mm]{Fig/slidepdf2.pdf}}\hspace{5mm}%
\fbox{\includegraphics[bb=0.00 0.00 543.00 382.00,height=35mm]{Fig/slidepdf3.pdf}}\hspace{5mm}%
\end{center}

\subsection{Commands of \ketcindy\ slide}

You can use the following commands.\\
\verb|    title::slide0 (::wallpaper)//|\\
\verb|        Rem) Put only once at the first line.|\\
\verb|    main::(main title)//|\\
\verb|    new::(page title)//|\\
\verb|    enumerate//|\\
\verb|           =\begin{enumerate}|\\
\verb|        Rem) Add the option such as [(1)] using :: .|\\
\verb|    itemize//|\\
\verb|           =\begin{itemize}|\\
\verb|    layer::{xsize}{ysize}//|\\
\verb|           =\begin{layer}{xsize}{ysize}|\\
\verb|         Rem) "layer" is an environment defined in ketlayer.sty.|\\
\verb|    item::sentence//|\\
\verb|           =\item sentence|\\
\verb|    putnote::dir{xpos}{ypos}::filename(,scale)//|\\
\verb|           =putnotedir{xpos}{ypos}{\input{fig/filename}}||\\
\verb|         Rem) "putnote" is a command defined in ketlayer.sty|\\
\verb|    end//|\\
\verb|           =\end{itemize,enumerate,layer}|\\
\verb|    ...//|\\
\verb|          To insert a blank line.|

\noindent
You can also use the following \TeX\ mcores added by \ketcindy.\\
\verb|    \slidepage,\slidepage[m]//|\\
\verb|          To display the number each page.|\\
\verb|            \slidepage[m] is used for the \verb|main| page.|\\
\verb|    \setthin{thickness}|\\
\verb|          To change the thickness of thin letters temporarily.|\\
\verb|    \inputsound, \inputmovie|\\
\verb|          To insert mp3/mp4 files.|


\begin{description}
\item[Remark]Any other \TeX\ macroes are available. Put \verb|%%| instead of \verb|%| to comment out .
\end{description}


\subsection{Display of Page step by step}

\begin{enumerate}[1)]
\item Put just after new,\\
\verb|    %repeat=number of steps//|
\item Put at the head of each line as\\
\verb|    %[2,-]::sentences|\\
\verb|           display at all steps from 2|\\
\verb|    %[-,2]::sentences|\\
\verb|           display at all steps until 2|\\
\verb|    %[1..3,5]::sentences|\\
\verb|           display at steps of 1,2,3 and 5|
\item  Use \verb|%thin| to display with thin letters.\\
\verb|    %thin::[2,-]::sentence|
\item The dencity can be changed with Setslidebody or \verb|\setthin|.
\end{enumerate}

\subsection{Making Flip Animation}

\begin{enumerate}[1)]
\item Define function \verb|Mf(s)|, the state at s.
\item Put command \verb|Setpara| in the script editor as\\ 
\verb|    Setpara(subfolder,funcitonstr(mf(s)),range,options);|\\
\verb|        options=["m/r", "Div=25"];|
\item Describe in the text file as\\
\verb|    %repeat=, para=subfolder:{0}:s{60}{10}:input(:scale)//|
\item Press buttons \verb|ParaF| and \verb|Flip|, then \verb|subfolder| will be generated.
\item Press button \verb|Slide|.
\end{enumerate}

\subsection{Making Animation}

\begin{enumerate}[1)]
\item Add the following in the script editor\\ 
\verb|    Addpackage(["[dvipdfmx]{animate}"]);|
\item Add in the second option of Setpara,\\
\verb|    "Frate=num of frame in the second,"Scale=scale,"OpA=option of animation" |
\item Press buttons \verb|ParaF| and \verb|Anime|, then \verb|subfolder| will be generated.
\item Use \verb|\input|, not layer, to display.
\end{enumerate}

\subsection{Commands to Insert a mp3/mp4 file}

To insert a mp3 or mp4 file, change the first line to\\
\verb|    title::slide0|\\
\verb|    ::\usepackage{ketmedia}|\\
\verb|    ::\usepackage[dvipdfmx]{media9}//|\vspace{2mm}

\noindent
Use \verb|\inputsound| or \verb|\inputsoundclick| for mp3 files.\\
\verb|    \inputsountclik[90]{folder/}{mp3file} %starts when the button clicked|\\
The arguments are horizontal position(default is 90) of buttons, the folder, the file name.
\vspace{2mm}

\noindent
Use \verb|\inputmovie| for mp4 files.\\
\verb|    \inputsountclik[90]{1}{0.4}{folder/}{mp4file} %starts when the button clicked|
The 2nd and 3rd arguments are width and height as the coefficiients of \verb|\linewidth|

\subsection{Changing Style}

The default styles such as size and color of letters can be changed.
See \verb|KeTCindyReferenceE,pdf| or \verb|samples/s07slides|.

\end{document}