Debian Codegraph @

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

raw
1 \section{Work organization}
2 \label{sec:work_organization}
3
4
5 Here is a sample organization for working with \tkzNamePack{tkz-euclide} and \tkzEngine{Lua\LATEX}.
6
7 \begin{itemize}
8 \item \texttt{Compilation:} Add the line:
9 \begin{verbatim}
10 % !TEX TS-program = lualatex
11 \end{verbatim}
12 to ensure that your document compiles with \tkzEngine{Lua\LATEX}.
13
14 \item \texttt{Document Class:} The \texttt{standalone} class is recommended when the goal is simply to create a figure, as it avoids unnecessary overhead.
15
16 \item \texttt{Package Loading:} You can load \tkzNamePack{tkz-euclide} in two ways:
17 \begin{itemize}
18 \item \tkzcname{usepackage\{tkz-euclide\} }gives you full access to the entire package.
19 \item The recommended method is to use the \tkzPopt{tkz-euclide}{mini} option, which loads only the necessary modules for drawing. You still retain the ability to draw with \TIKZ{} if desired.
20 \end{itemize}
21
22 \item \texttt{Conditionals:} The package \tkzNamePack{ifthen} is useful when you need to evaluate Boolean conditions within your document.
23
24 \item \texttt{Lua Code Organization:} While you can embed Lua code directly with \verb|\directlua|, externalizing the code offers several advantages:
25 \begin{itemize}
26 \item Better syntax highlighting and code presentation in editors that support \tkzname{Lua} and \LATEX{}.
27 \item Simplified commenting: \tkzname{Lua} uses \verb|--|, while \LATEX{} uses \verb|%|. Keeping Lua in a separate file avoids confusion.
28 \item Reusability: external code files can be reused across multiple documents or figures.
29 \end{itemize}
30 \end{itemize}
31
32 For simplicity, this documentation uses embedded Lua code in most cases. However, in some examples, external files are used to show you how it's done.
33
34
35 \vspace{12pt}
36 \begin{mybox}{}
37 \begin{minipage}{.50\textwidth}
38 \begin{verbatim}
39 % !TEX TS-program = lualatex
40 % Created by Alain Matthes on 2024-01-09.
41 \documentclass[margin = 12pt]{standalone}
42 \usepackage[mini]{tkz-euclide}
43 \usepackage{tkz-elements,ifthen}
44
45 \begin{document}
46 \directlua{
47 init_elements() % Clear tables
48 dofile ("lua/sangaku.lua")
49 % Load the lua code
50 }
51 \begin{tikzpicture}[ scale = .75]
52 \tkzGetNodes
53 \tkzDrawCircle(I,F)
54 \tkzFillPolygon[purple](A,C,D)
55 \tkzFillPolygon[blue!50!black](A,B,C)
56 \tkzFillCircle[orange](I,F)
57 \end{tikzpicture}
58 \end{document}
59 \end{verbatim}
60 \end{minipage}
61 \begin{minipage}{.40\textwidth}
62 \directlua{
63 init_elements()
64 dofile ("lua/sangaku.lua")
65 }
66 \begin{center}
67 \begin{tikzpicture}[ scale = .75]
68 \tkzGetNodes
69 \tkzDrawCircle(I,F)
70 \tkzFillPolygon[purple](A,C,D)
71 \tkzFillPolygon[blue!50!black](A,B,C)
72 \tkzFillCircle[orange](I,F)
73 \end{tikzpicture}
74 \end{center}
75 \end{minipage}
76 \end{mybox}
77
78 \vspace{12pt}
79 And here is the code for the \tkzname{Lua} part: the file |sangaku.lua|
80
81 \vspace{1em}
82 \begin{minipage}{.5\textwidth}
83 \begin{mybox}
84 \begin{verbatim}
85 z.A = point(0, 0)
86 z.B = point(8, 0)
87 L.AB = line(z.A, z.B)
88 S.AB = L.AB:square()
89 _, _, z.C, z.D = S.AB:get()
90 z.F = S.AB.ac:projection(z.B)
91 L.BF = line(z.B, z.F)
92 T.ABC = triangle(z.A, z.B, z.C)
93 L.bi = T.ABC:bisector(2)
94 z.c = L.bi.pb
95 L.Cc = line(z.C, z.c)
96 z.I = intersection(L.Cc, L.BF)
97 \end{verbatim}
98 \end{mybox}
99 \end{minipage}
100
101
102 \subsection{Scaling Policy Update}
103
104 In previous versions, it was recommended to apply scaling within the Lua part of the code. However, this guidance has now changed.
105
106 Since all geometric computations are handled in \tkzname{Lua}, applying scaling in \TIKZ{} no longer presents any issues. On the contrary, performing scaling in \tkzname{Lua} has led to several complications—particularly with the recent implementation of conic-related functions, which involve numerous distance calculations using real numbers.
107
108 These challenges prompted a review of several functions, during which some bugs related to Lua-side scaling were identified and resolved.
109
110 \medskip
111
112 \textbf{\textcolor{red}{New Recommendation:}} From now on, scaling should be applied exclusively in the \TIKZ{} part. The \tkzname{Lua} code should operate in an unscaled, consistent coordinate system to ensure the reliability of all geometric computations.
113
114 The following documentation uses only scaling in the \tkzEnv{tikz}{tikzpicture} environment.
115 \endinput