Debian Codegraph @

texmf-dist/tex/latex/tkz-elements/tkz-elements.sty

raw
1 % File: tkz-elements.sty
2 % Copyright (c) 2026 Alain Matthes
3 % SPDX-License-Identifier: LPPL-1.3c
4 % Maintainer: Alain Matthes
5
6 \ProvidesPackage{tkz-elements}[2026/04/11 v5.06c Graphic Object Library]
7
8 \typeout{Package tkz-elements v5.06c (2026/04/11) loaded.}
9
10 \RequirePackage{iftex}
11 \ifluatex\else
12 \PackageError{tkz-elements}{%
13 This package requires LuaLaTeX.%
14 }{%
15 Please compile with LuaLaTeX.\MessageBreak
16 Aborted compilation.%
17 }
18 \fi
19 \directlua{
20 require "tkz_elements_main"
21 init_elements()
22 }%
23
24 % new version of the next macro proposed by Sanskar Singh
25 \makeatletter
26 \let\percentchar\@percentchar
27 \@ifpackageloaded{tkz-euclide}{%
28 \@ifpackagelater{tkz-euclide}{2024/04/19}{%
29 \def\tkzGetNodes{\directlua{%
30 tkz.GetNodes()
31 tkz.flush_coord_warnings()
32 }}
33
34 \def\tkzDrawLuaEllipse{\pgfutil@ifnextchar[{\tkz@DrawLuaEllipse}{\tkz@DrawLuaEllipse[]}}
35 \def\tkz@DrawLuaEllipse[#1](#2,#3,#4){%
36 \begingroup
37 \draw[#1](#2) ellipse [x radius=\tkzUseLua{length_(z.#3,z.#2)}, y radius =
38 \tkzUseLua{length_(z.#4,z.#2)},rotate=\tkzUseLua{math.deg(slope_ (z.#3,z.#2))}];
39 \endgroup}%
40
41
42 \def\tkzDrawCoordinates{\pgfutil@ifnextchar[{\tkz@DrawCoordinates}{\tkz@DrawCoordinates[]}}
43 \def\tkz@DrawCoordinates[#1](#2){%
44 \begingroup
45 \draw[#1] plot coordinates {\directlua{tex.print(#2)}};
46 \endgroup}%
47
48 \let\tkzDrawPath\tkzDrawCoordinates
49
50
51 \def\tkzPrintNumber{\pgfutil@ifnextchar[{\tkz@PrintNumber}{\tkz@PrintNumber[2]}}%
52 \def\tkz@PrintNumber[#1]#2{%
53 \begingroup
54 \pgfkeys{/pgf/number format/.cd,fixed,precision=#1}%
55 \pgfmathprintnumber{#2}%
56 \endgroup
57 }
58 \let\tkzPN\tkzPrintNumber
59
60 \def\tkzDrawSegmentsFromPaths{\pgfutil@ifnextchar[{\tkz@DrawSegmentsFromPaths}{\tkz@DrawSegmentsFromPaths[]}}
61 \def\tkz@DrawSegmentsFromPaths[#1](#2,#3){%
62 \begingroup
63 \directlua{%
64 local P = #2
65 for i = 1, P:count() do
66 local x1, y1 = #2:get_number_path(i)
67 local x2, y2 = #3:get_number_path(i)
68 tex.print("\\tkzDefPoint("..x1..","..y1.."){start}")
69 tex.print("\\tkzDefPoint("..x2..","..y2.."){end}")
70 tex.print("\\tkzDrawSegment[" .. "\luaescapestring{#1}" .. "](start,end)")
71 end
72 }%
73 \endgroup}%
74
75 \def\tkzUseLua#1{\directlua{tex.sprint(#1)}}
76
77 \def\tkzDrawPointsFromPath{\pgfutil@ifnextchar[{\tkz@DrawPointsFromPath}{\tkz@DrawPointsFromPath[]}}
78 \def\tkz@DrawPointsFromPath[#1](#2){%
79 \begingroup
80 \foreach[expand list] \r/\s in {\directlua{tex.sprint(#2:concat_rawpair(","))}} {%
81 \tkzDrawPoint[#1](\r,\s)%
82 }%
83 \endgroup
84 }
85
86
87 \def\tkzDrawCirclesFromPaths{\pgfutil@ifnextchar[{\tkz@DrawCirclesFromPaths}{\tkz@DrawCirclesFromPaths[]}}
88 \def\tkz@DrawCirclesFromPaths[#1](#2,#3){%
89 \begingroup
90 \directlua{
91 local P = #2
92 for i = 1, P:count() do
93 local cx, cy = #2:get_number_path(i)
94 local tx, ty = #3:get_number_path(i)
95 tex.print("\\node[" .. "\luaescapestring{#1}" .. ",circle through={(" .. tx .. "," .. ty .. ")}] at (" .. cx .. "," .. cy .. ") {};")
96 end
97 }
98 \endgroup
99 }
100
101 \def\tkzGetPointsFromPath(#1,#2){%
102 \begingroup
103 \foreach[expand list][count = \i] \r/\s in {%
104 \directlua{tex.sprint(#1:concat_rawpair(","))}}%
105 {%
106 \tkzDefPoint(\r,\s){#2_\i}%
107 }%
108 \endgroup
109 }
110
111
112 \def\tkzDrawFromPointToPath{%
113 \pgfutil@ifnextchar[{\tkz@DrawFromPointToPath}{\tkz@DrawFromPointToPath[]}%
114 }
115 \def\tkz@DrawFromPointToPath[#1](#2,#3){%
116 \begingroup
117 \directlua{%
118 local P = #3
119 local A = "\luaescapestring{#2}"
120 for i,x,y in P:iter() do
121 tex.print("\\tkzDefPoint("..x..","..y.."){tmp}")
122 tex.print("\\tkzDrawSegment["..
123 "\luaescapestring{#1}".."]("..A..",tmp)")
124 end
125 }%
126 \endgroup
127 }
128
129 \makeatother
130
131
132 % Returns the number of points in a path (usage: \tkzPathCount{PA.A}{N})
133 \def\tkzPathCount(#1)#2{%
134 \directlua{
135 local n = #1:count()
136 tex.print("\\edef\\#2{"..n.."}") % <-- \N = "10" (par ex.)
137 }%
138 }
139
140 %\newcommand{\tkzGetPointFromPath}[3]{%
141 \def\tkzGetPointFromPath(#1,#2)#3{%
142 \begingroup
143 \directlua{%
144 local i = \number#2
145 local cx,cy = #1:get_number_path(i)
146 tex.print("\\tkzDefPoint("..cx..","..cy.."){#3}")
147 }%
148 \endgroup
149 }
150
151 \def\tkzEraseLuaObj#1{\directlua{#1 = nil}}
152
153 }{%
154 \PackageWarning{tkz-elements}{%
155 tkz-euclide is loaded but too old.\MessageBreak
156 Minimum version required : 5.10c 2024/04/19%
157 }}}{%
158 }%
159
160
161
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 \def\tkzGetNodesMP#1{\directlua{
166 local out = assert(io.open("#1.mp", "w"))
167 local names = {}
168 for K, _ in pairs(z) do
169 table.insert(names, tostring(K))
170 end
171 table.sort(names)
172 out:write("pair ", table.concat(names, ", "), ";\string\n")
173 for _, name in ipairs(names) do
174 local V = z[name]
175 if V then
176 out:write(name, " := (", V.re, "cm,", V.im, "cm);\string\n")
177 end
178 end
179 out:close()
180 }}
181
182 \endinput