\newpage
\section{How to use} % (fold)
\label{sec:how_to_use}

You need to load either \TIKZ{} or \pkg{tkz-euclide} if you want to use these packages to get your plots, then you need to load \pkg{tkz-elements}.

Loading \pkg{tkz-elements} allows you to use the \env{elements} environment. However, you can use the macro \tkzcname{directlua} or the \env{luacode} environment  (the package \pkg{luacode} is loaded automatically).


\subsection{Environment elements} % (fold)
\label{sub:environment_elements}

You must first create an environment \tkzNameEnv{tkzelements}, then in this environment you create the fixed points of your figure. (For the moment, you place the environment \env{elements} before the environment \env{tikzpicture} but it is possible to place it inside the latter.)

In the following example, three fixed points are used (lines 8, 9 and 10), the first object \tkzNameObj{point} $A$ is created by 

|z.A  = point: new (2 , 4)|. 

Then we create a \tkzNameObj{triangle} (line 11)

|T.ABC  = triangle: new (z.A,z.B,z.C)|

Once the triangle has been created, you can either use its attributes or a method associated with the triangle object. In all cases, the result is either a number or a new object.

In order to obtain the circle inscribed in this triangle, we use a method of the \tkzname{triangle}. We obtain a new object, a circle, which I call |C.Ii|. A circle is defined by its center and a point through which it passes.  $I$ is the center and $i$ is the  projection of this center on the  side opposed to the first point of the triangle. 

There are several ways of obtaining these two points. As in the example, |get_points| is a function that extracts the points from the object given as an argument. You can also use the circle attributes: |z.I = C.Ii.center| and |z.i = CIi.through|. The first method is obviously simpler, but less explicit. Another possibility would be to obtain the center as an attribute of the triangle |z.I = T.ABC.incircle| and then project this center onto one of the sides, for example |z.i = T.ABC.bc : projection (z.I)|. An explanation is in order: |T.ABC.bc | is the straight line defined by the last two points of the triangle (see triangle attributes \ref{sec:classe_triangle}).

Then we look for the  circumscribed circle, which is obtained using a method of the triangle object. We define the circumscribed \tkzNameObj{circle} named |C.WA|.

|C.WA   = T.ABC : circum_circle ()| (line 16)

| z.W,_   = get_points (C.WA)| is used to get the center but possible is

 |z.W = T.ABC.circumcircle|

The south pole of the circle with center $W$ passing through $A$ is given by an attribute of the object \tkzNameObj{circle}.

We finally look for the intersection of two lines.

Line 17 an object line is created. Line 18 I name a line object already created (it's a triangle attribute).

All points are defined and stored in the |z| table. The macro \tkzcname{tkzGetNodes} retrieves the keys and associated values from this table and creates the nodes to be used by \TIKZ\ or \pkg{tkz-euclide}.

\begin{tkzexample}[small,code only,num]
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{tkz-euclide}
\usepackage{tkz-elements}
\begin{document}

\begin{tkzelements}
   z.A     = point: new (2 , 4)
   z.B     = point: new (0 , 0)
   z.C     = point: new (8 , 0)
   T.ABC   = triangle: new (z.A,z.B,z.C)
   C.Ii    = T.ABC: in_circle ()
   z.I,z.i = get_points (C.Ii)
   C.WA    = T.ABC : circum_circle ()
   z.W,_   = get_points (C.WA)
   z.O     = C.WA.south
   L.AO    = line: new (z.A,z.O)
   L.BC    = T.ABC.bc
   z.I_A   = intersection (L.AO,L.BC)
\end{tkzelements}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawCircles(W,A I,i)
   \tkzDrawArc(O,C)(B)
   \tkzDrawPolygon(A,B,C)
   \tkzDrawSegments[new](A,O B,O C,O)
   \tkzDrawLine(B,I)
   \tkzDrawPoints(A,B,C,I,I_A,W,O)
   \tkzFillAngles[green!20,opacity=.3](A,O,B A,C,B)
   \tkzFillAngles[teal!20,opacity=.3](O,B,C B,C,O B,A,O O,A,C)
   \tkzLabelPoints(I,I_A,W,B,C)
   \tkzLabelPoints[above](A)
\end{tikzpicture}
\end{document}
\end{tkzexample}

\begin{tkzelements}
   scale =.75
   z.A     = point: new (2 , 4)
   z.B     = point: new (0 , 0)
   z.C     = point: new (8 , 0)
   T.ABC   = triangle: new (z.A,z.B,z.C)
   C.Ii    = T.ABC: in_circle ()
   z.I,z.i = get_points (C.Ii)
   C.WA    = T.ABC : circum_circle ()
   z.W,_   = get_points (C.WA)
   z.O     = C.WA.south
   L.AO    = line: new (z.A,z.O)
   L.BC    = T.ABC.bc
   z.I_A   = intersection (L.AO,L.BC)
\end{tkzelements}

\hspace*{\fill}
\begin{tikzpicture}
\tkzGetNodes
\tkzDrawCircles(W,A I,i)
\tkzDrawArc(O,C)(B)
\tkzDrawPolygon(A,B,C)
\tkzDrawSegments[new](A,O B,O C,O)
\tkzDrawLine(B,I)
\tkzDrawPoints(A,B,C,I,I_A,W,O)
\tkzFillAngles[green!20,opacity=.3](A,O,B A,C,B)
\tkzFillAngles[teal!20,opacity=.3](O,B,C B,C,O B,A,O O,A,C)
\tkzLabelPoints(I,I_A,W,B,C,O)
\tkzLabelPoints[above](A)
\end{tikzpicture}
\hspace*{\fill}
% subsection environment_elements (end)

\subsection{Fom Lua to tkz-euclide or TikZ} % (fold)
\label{sub:fom_lua_to_tkz_euclide_or_tikz}

\subsubsection{Points transfer} % (fold)
\label{ssub:points_transfer}
We use an environment \tkzname{tkzelements}  outside an environment \tkzname{tikzpicture} which allows us to carry out all the necessary calculations, then we launch the macro \tkzcname{tkzGetNodes} which transforms the affixes of the table \tkzname{z} into a list of \tkzname{Nodes}. It only remains to draw.

Currently the drawing program is either \TIKZ\ or \pkg{tkz-euclide}. You have the possibility to use another package to trace but for that you have to create a macro similar to \tkzcname{tkzGetNodes}. Of course, this package must be able to store the points as does \TIKZ\ or \pkg{tkz-euclide}. 

\vspace*{1em}

\begin{tkzexample}[latex=0cm,small,code only]
\def\tkzGetNodes{\directlua{%
   for K,V in pairs(z) do
      local KS,n,sd,ft
      KS = tostring(K)
      n = string.len(KS)
      if n >1 then
      _,_,ft, sd = string.find( KS , "(.+)(.)" )  
     if sd == "p" then   K=ft.."'" end  
       end    
  tex.print("\\coordinate ("..K..") at ("..V.re..","..V.im..") ;\\\\")
end}
}
\end{tkzexample}

The environment \tkzNameEnv{tkzelements} allows to use the underscore |_| and the macro \tkzcname{tkzGetNodes} allows to obtain names of nodes containing \tkzname{prime}. (see the next example)

\begin{minipage}{0.5\textwidth}
\begin{tkzexample}[latex=0cm,small,code only]
\begin{tkzelements}
   scale = 1.2
   z.o   = point: new (0,0)
   z.a_1 = point: new (2,1)
   z.a_2 = point: new (1,2)
   z.ap  = z.a_1 + z.a_2
\end{tkzelements}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawSegments(o,a_1 o,a_2 o,a')
   \tkzDrawSegments[red](a_1,a' a_2,a')
   \tkzDrawPoints(a_1,a_2,a',o)
   \tkzLabelPoints(o,a_1,a_2,a')
\end{tikzpicture}
\end{tkzexample}%
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\begin{tkzelements}
scale = 1.2
z.o = point: new (0,0)
z.a_1 = point: new (2,1)
z.a_2 = point: new (1,2)
z.ap = z.a_1 + z.a_2
\end{tkzelements}
\begin{tikzpicture}
\tkzGetNodes
 \tkzDrawSegments(o,a_1 o,a_2 o,a')
 \tkzDrawSegments[red](a_1,a' a_2,a')
 \tkzDrawPoints(a_1,a_2,a',o)
 \tkzLabelPoints(o,a_1,a_2,a')
\end{tikzpicture}
\end{minipage}%

% subsection fom_lua_to_tkz_euclide_or_tikz (end)
\subsubsection{Other transfers} % (fold)
\label{ssub:other_transfers}

Sometimes it's useful to transfer angle or length measurements. For this purpose, I have created the function (see \ref{ssub:transfer_from_lua_to_tex})  
\Igfct{package}{set\_lua\_to\_tex (list)}

% subsubsection other_transfers (end)
% subsubsection points_transfer (end)

% section how_to_use (end)




\endinput