Debian Codegraph @

texmf-dist/doc/latex/tkz-elements/TKZdoc-elements-beginning.tex

raw
1 \section{Getting started}
2
3 \subsection{The first code}
4
5 A quick introduction to get you started.
6 We assume that the packages \tkzNamePack{tkz-euclide} and \tkzNamePack{tkz-elements} are installed.
7 Compile the following code using the \tkzEngine{lualatex} engine; you should obtain a straight line
8 passing through points $A$ and $B$.
9
10 \medskip
11 \noindent
12 \textbf{Note.}
13 The package \tkzNamePack{tkz-elements} performs all geometric definitions and computations in Lua,
14 while \tkzNamePack{tkz-euclide} is mainly used for drawing.
15 For this reason, the \texttt{mini} option of \tkzNamePack{tkz-euclide} is recommended.
16 If a compilation problem occurs, simply load \tkzNamePack{tkz-euclide} without this option.
17
18
19 \begin{mybox}{}
20 \begin{minipage}{.55\textwidth}
21 \begin{tkzexample}[code only]
22 % !TEX TS-program = lualatex
23 \documentclass{article}
24 \usepackage[mini]{tkz-euclide}
25 \usepackage{tkz-elements}
26 \begin{document}
27 \directlua{
28 init_elements()
29 z.A = point(0, 1)
30 % or z.A = point:new(0, 1)
31 z.B = point(2, 0)
32 }
33 \begin{tikzpicture}
34 \tkzGetNodes
35 \tkzDrawLine(A,B)
36 \tkzDrawPoints(A,B)
37 \tkzLabelPoints(A,B)
38 \end{tikzpicture}
39 \end{document}
40 \end{tkzexample}
41 \end{minipage}
42 \begin{minipage}{.35\textwidth}
43 \directlua{
44 z.A = point(0, 1)
45 z.B = point(2, 0)
46 }
47 \begin{tikzpicture}
48 \tkzGetNodes
49 \tkzDrawLine(A,B)
50 \tkzDrawPoints(A,B)
51 \tkzLabelPoints(A,B)
52 \end{tikzpicture}
53 \end{minipage}
54 \end{mybox}
55
56 \subsection{Key points}
57
58 The following points are essential for most of the codes in this documentation.
59
60 \begin{itemize}
61 \item \verb|% !TEX TS-program = lualatex|.
62 Compilation must be performed with \code{lualatex}. This line is optional if your editor is already configured accordingly.
63
64 \item \verb|\usepackage[mini]{tkz-euclide}|.
65 The use of \tkzNamePack{tkz-euclide} is optional; however, if it is loaded, the \code{mini} option is recommended.
66 It loads only the drawing macros, while all computations are handled by \code{lua}.
67 \textbf{Important:} at the current stage, some drawing macros are not yet fully independent of computation macros.
68 If a compilation problem occurs, simply load \tkzNamePack{tkz-euclide} without the \code{mini} option.
69
70 \item \verb|\usepackage{tkz-elements}|.
71 This package is required. It provides the Lua-based geometry engine and support macros used together with \tkzNamePack{tkz-euclide}.
72
73 \item \verb|\directlua{...}|.
74 All geometric definitions and computations are placed inside this macro (or within a \texttt{tkzelements} environment).
75
76 \item \verb|init_elements()|.
77 This function should be called at the beginning of each Lua section.
78 It resets internal tables and clears global variables used by \tkzNamePack{tkz-elements}.
79
80 \item \verb|\tkzGetNodes|.
81 This macro must be placed at the beginning of the \code{tikzpicture} environment.
82 It transfers the points defined in Lua to TikZ as usable nodes.
83 \end{itemize}
84
85
86
87 \subsection{Testing}
88
89 To test your installation and follow the examples in this documentation, you need to load two packages: \tkzNamePack{tkz-euclide} and \tkzNamePack{tkz-elements}. The first package automatically loads \tkzNamePack{\TIKZ}, which is necessary for all graphical rendering.
90
91
92 The \tkzname{Lua} code is provided as an argument to the \tkzMacro{lualatex}{directlua} macro. We will often refer to this code block as the \tkzname{Lua part } \footnote{This code can also be placed in an external file, e.g., \texttt{file.lua}.}. This part depends entirely on the \tkzNamePack{tkz-elements} package.
93
94 A crucial component in the \tkzEnv{tikz}{tikzpicture} environment is the macro \tkzMacro{tkz-elements}{tkzGetNodes}. This macro transfers the points defined in \tkzname{Lua} to \tkzNamePack{\TIKZ} by creating the corresponding nodes. All such points are stored in a table named \tkzname{z} and are accessed using the syntax \tkzname{z.label}. These labels are then reused within \tkzNamePack{tkz-euclide}.
95
96 When you define a point by assigning it a label and coordinates, it is internally represented as a complex number — the affix of the point. This representation allows the point to be located within an orthonormal Cartesian coordinate system.
97
98 If you want to use a different method for rendering your objects, this is the macro to modify. For example, Section~\ref{sec:metapost} presents \tkzMacro{tkz-elements}{tkzGetNodesMP}, a variant that enables communication with \code{MetaPost}.
99
100 Another essential element is the use of the function \tkzFct{tkz-elements}{init\_elements()}, which clears internal tables\footnote{All geometric objects are stored in Lua tables. These tables must be cleaned regularly, especially when creating multiple figures in sequence.} when working with multiple figures.
101
102 If everything worked correctly with the previous code, you're ready to begin creating geometric objects. Section~\ref{sec:class_and_object} introduces the available options and object structures.
103
104 Finally, it is important to be familiar with basic drawing commands in \tkzNamePack{tkz-euclide}, as they will be used to render the objects defined in \tkzname{Lua}.
105 \endinput