Doc: ajout des commandes à lstlisting
[delaunay.git] / luamesh.sty
1 \NeedsTeXFormat{LaTeX2e}%
2 \def\PackageName{luamesh}%
3 \def\fileversion{v0.1}%
4 \def\filedate{2016/11/20}%
5 \ProvidesPackage{luamesh}[\filedate\space\fileversion]%
6 %
7 % package to load
8 \RequirePackage{xkeyval,xcolor,ifthen}%
9 %% one global option: mp or tikz
10 %\newif\ifluameshmp%
11 %\define@key{luamesh.sty}{mp}[]{\luameshmptrue}%
12 %\define@key{luamesh.sty}{tikz}[]{\luameshmpfalse}%
13 %
14 %\RequirePackage{etoolbox} % pour robustifier les commandes
15 %
16 %
17 %\ifluameshmp%
18    \RequirePackage{luamplib}%
19 %\else%
20    \RequirePackage{tikz}%
21 %\fi%
22 %
23 % load the lua code
24 \directlua{require("luamesh.lua")}%
25 %
26 %%
27 % for tikz (default value)
28 % default color for the plot of a global mesh
29 \definecolor{TeXCluaMeshTikZ}{rgb}{0.,0.,0.}
30 % default color for a new element
31 \definecolor{TeXCluaMeshNewTikZ}{rgb}{0.5,0.1,0.1}
32 % defaut color for the background of new element
33 \definecolor{TeXCluaMeshBackTikZ}{rgb}{0.99,0.85,0.85}
34 % default color for circoncircle
35 \definecolor{TeXCluaMeshCircleTikZ}{rgb}{0.1,0.6,0.1}
36
37
38 %%%%%%%%%%%%%%%% the buildMesh command
39 %% the user can write code (tikz or MP)
40 %% before and after the generated code
41 \define@boolkey{buildMeshInc}{tikz}[true]{}%
42 %% show the bounding box for delaunay
43 \define@choicekey*{buildMeshInc}{bbox}[\val\nr]{none, show}{%
44   \ifcase\nr\relax%
45   \def\luameshval@bmi@bbox{none}%
46   \or%
47   \def\luameshval@bmi@bbox{bbox}%
48   \fi%
49 }%
50 %% the scale
51 \define@key{buildMeshInc}{scale}[1cm]{\def\luameshval@bmi@scale{#1}}%
52 %% print ponits ?
53 \define@choicekey*{buildMeshInc}{print}[\val\nr]{none, points}{%
54   \ifcase\nr\relax%
55   \def\luameshval@bmi@print{none}%
56   \or%
57   \def\luameshval@bmi@print{points}%
58   \fi%
59 }%
60 %% the name of the point
61 \define@key{buildMeshInc}{meshpoint}[P]{\def\luameshval@bmi@meshpoint{#1}}%
62 %% the mode for reading the points
63 \define@choicekey*{buildMeshInc}{mode}[\val\nr]{int, ext}{%
64   \ifcase\nr\relax%
65   \def\luameshval@bmi@mode{int}%
66   \or%
67   \def\luameshval@bmi@mode{ext}%
68   \fi%
69 }%
70 %% the name of the color of drawing
71 \define@key{buildMeshInc}{color}[black]{\def\luameshval@bmi@color{#1}}%
72 %% the name of the color of drawing the bbox
73 \define@key{buildMeshInc}{colorBbox}[black]{\def\luameshval@bmi@colorbbox{#1}}%
74 %
75 \presetkeys{buildMeshInc}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,color,colorBbox}{}%
76 %
77 \newcommand*{\buildMeshBWinc}[4][]{%
78   % #1 : optionnal arguments
79   % #2 : the string containing the list of points
80   %      (x1,y1);(x2,y2);... or the name file containing the points
81   % #3 : the code to place before the generated one
82   % #4 : the code to place after the generated one
83   \setkeys{buildMeshInc}{#1} %
84   \def\MeshPoint{\luameshval@bmi@meshpoint}%
85   \ifKV@buildMeshInc@tikz% if we are using tikz
86   \directlua{%
87     buildMeshTikZBWinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@bmi@mode","\luameshval@bmi@print","\luameshval@bmi@bbox","\luameshval@bmi@scale","\luameshval@bmi@color","\luameshval@bmi@colorbbox")%
88   }%
89   \else % we are using MP
90   \mplibcolor{\luameshmpcolor}{\luameshval@bmi@color}
91   \mplibcolor{\luameshmpcolorBbox}{\luameshval@bmi@colorbbox}
92   \directlua{%
93     buildMeshMPBWinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@bmi@mode","\luameshval@bmi@print","\luameshval@bmi@bbox","\luameshval@bmi@scale")%
94   }%
95   %
96   \fi%
97 }%
98 %
99 %%%%%%%%%%%%%%%% the buildMeshBW command
100 %% the code is complete and we don't have any callbacks
101 \define@boolkey{buildMesh}{tikz}[true]{}%
102 %% show the bounding box for delaunay
103 \define@choicekey*{buildMesh}{bbox}[\val\nr]{none, show}{%
104   \ifcase\nr\relax%
105   \def\luameshval@bm@bbox{none}%
106   \or%
107   \def\luameshval@bm@bbox{bbox}%
108   \fi%
109 }%
110 %% the scale
111 \define@key{buildMesh}{scale}[1cm]{\def\luameshval@bm@scale{#1}}%
112 %% print points
113 \define@choicekey*{buildMesh}{print}[\val\nr]{none, points}{%
114   \ifcase\nr\relax%
115   \def\luameshval@bm@print{none}%
116   \or%
117   \def\luameshval@bm@print{points}%
118   \fi%
119 }%
120 %% the name of the point
121 \define@key{buildMesh}{meshpoint}[P]{\def\luameshval@bm@meshpoint{#1}}%
122 %% the mode for reading the points
123 \define@choicekey*{buildMesh}{mode}[\val\nr]{int, ext}{%
124   \ifcase\nr\relax%
125   \def\luameshval@bm@mode{int}%
126   \or%
127   \def\luameshval@bm@mode{ext}%
128   \fi%
129 }%
130 %% the name of the color of drawing
131 \define@key{buildMesh}{color}[black]{\def\luameshval@bm@color{#1}}%
132 %% the name of the color of drawing the bbox
133 \define@key{buildMesh}{colorBbox}[black]{\def\luameshval@bm@colorbbox{#1}}%
134 %
135 \presetkeys{buildMesh}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,color,colorBbox}{}%
136 %
137 \newcommand{\buildMeshBW}[2][]{%
138   % #1 : optionnal arguments
139   % #2 : the string containing the list of points
140   % (x1,y1);(x2,y2);... or the name file containing the points
141   \setkeys{buildMesh}{#1} %
142   \def\MeshPoint{\luameshval@bm@meshpoint}%
143   \ifKV@buildMesh@tikz% if we are using tikz
144   \directlua{%
145     buildMeshTikZBW("#2","\luameshval@bm@mode","\luameshval@bm@print","\luameshval@bm@bbox","\luameshval@bm@scale","\luameshval@bm@color","\luameshval@bm@colorbbox")%
146   }%
147   \else % we are using MP
148   \mplibcolor{\luameshmpcolor}{\luameshval@bm@color}
149   \mplibcolor{\luameshmpcolorBbox}{\luameshval@bm@colorbbox}
150   \directlua{%
151     buildMeshMPBW("#2","\luameshval@bm@mode","\luameshval@bm@print","\luameshval@bm@bbox","\luameshval@bm@scale")%
152   }%
153   %
154   \fi%
155 }%
156 %
157 %
158 %%%%%%%%%%%%%%%%% the draw Points macro
159 %% plot the list of points given in argument
160 % the engine
161 \define@boolkey{drawPoints}{tikz}[true]{}%
162 %% show the bounding box for delaunay
163 \define@choicekey*{drawPoints}{bbox}[\val\nr]{none, show}{%
164   \ifcase\nr\relax%
165   \def\luameshval@tp@bbox{none}%
166   \or%
167   \def\luameshval@tp@bbox{bbox}%
168   \fi%
169 }%
170 %% the scale
171 \define@key{drawPoints}{scale}[1cm]{\def\luameshval@tp@scale{#1}}%
172 %% print points
173 \define@choicekey*{drawPoints}{print}[\val\nr]{none, points}{%
174   \ifcase\nr\relax%
175   \def\luameshval@tp@print{none}%
176   \or%
177   \def\luameshval@tp@print{points}%
178   \fi%
179 }%
180 %% the name of the point
181 \define@key{drawPoints}{meshpoint}[P]{\def\luameshval@tp@meshpoint{#1}}%
182 %% the mode for reading the points
183 \define@choicekey*{drawPoints}{mode}[\val\nr]{int, ext}{%
184   \ifcase\nr\relax%
185   \def\luameshval@tp@mode{int}%
186   \or%
187   \def\luameshval@tp@mode{ext}%
188   \fi%
189 }%
190 %% the name of the color of drawing
191 \define@key{drawPoints}{color}[black]{\def\luameshval@tp@color{#1}}%
192 %% the name of the color of drawing the bbox
193 \define@key{drawPoints}{colorBbox}[black]{\def\luameshval@tp@colorbbox{#1}}%
194 %
195 \presetkeys{drawPoints}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,color,colorBbox}{}%
196 %
197 \newcommand{\drawPointsMesh}[2][]{%
198   % #1 : optionnal arguments
199   % #2 : the string containing the list of points
200   % (x1,y1);(x2,y2);... or the name file containing the points
201   \setkeys{drawPoints}{#1} %
202   \def\MeshPoint{\luameshval@tp@meshpoint}%
203   \ifKV@drawPoints@tikz% if we are using tikz
204   \directlua{%
205     printPointsTikZ("#2","\luameshval@tp@mode","\luameshval@tp@print","\luameshval@tp@bbox","\luameshval@tp@scale","\luameshval@tp@color","\luameshval@tp@colorbbox")%
206   }%
207   \else % we are using MP
208   \mplibcolor{\luameshmpcolor}{\luameshval@tp@color}
209   \mplibcolor{\luameshmpcolorBbox}{\luameshval@tp@colorbbox}
210   \directlua{%
211     printPointsMP("#2","\luameshval@tp@mode","\luameshval@tp@print","\luameshval@tp@bbox","\luameshval@tp@scale")%
212   }%
213   %
214   \fi%
215 }%
216 %
217
218 %%%%%%%%%%%%%%%% the draw Points macro inc with callbacks
219 %% engine of drawing
220 \define@boolkey{drawPointsInc}{tikz}[true]{}%
221 %% show the bounding box for delaunay
222 \define@choicekey*{drawPointsInc}{bbox}[\val\nr]{none, show}{%
223   \ifcase\nr\relax%
224   \def\luameshval@tpi@bbox{none}%
225   \or%
226   \def\luameshval@tpi@bbox{bbox}%
227   \fi%
228 }%
229 %% the scale
230 \define@key{drawPointsInc}{scale}[1cm]{\def\luameshval@tpi@scale{#1}}%
231 %% print points
232 \define@choicekey*{drawPointsInc}{print}[\val\nr]{none, points}{%
233   \ifcase\nr\relax%
234   \def\luameshval@tpi@print{none}%
235   \or%
236   \def\luameshval@tpi@print{points}%
237   \fi%
238 }%
239 %% the name of the point
240 \define@key{drawPointsInc}{meshpoint}[P]{\def\luameshval@tpi@meshpoint{#1}}%
241 %% the mode for reading the points
242 \define@choicekey*{drawPointsInc}{mode}[\val\nr]{int, ext}{%
243   \ifcase\nr\relax%
244   \def\luameshval@tpi@mode{int}%
245   \or%
246   \def\luameshval@tpi@mode{ext}%
247   \fi%
248 }%
249 %
250 % color
251 %% the name of the color of drawing
252 \define@key{drawPointsInc}{color}[black]{\def\luameshval@tpi@color{#1}}%
253 %% the name of the color of drawing the bbox
254 \define@key{drawPointsInc}{colorBbox}[black]{\def\luameshval@tpi@colorbbox{#1}}%
255 %
256 \presetkeys{drawPointsInc}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,color,colorBbox}{}%
257 %
258 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 \newcommand*{\drawPointsMeshinc}[4][]{%
260   % #1 : optionnal arguments
261   % #2 : the string containing the list of points
262   % (x1,y1);(x2,y2);... or the name file containing the points
263   % #3 : the code to place before the generated one
264   % #4 : the code to place after the generated one
265   \setkeys{drawPointsInc}{#1} %
266   \def\MeshPoint{\luameshval@tpi@meshpoint}%
267   \ifKV@drawPointsInc@tikz% if we are using tikz
268   \directlua{%
269     buildMeshTikZ("#2","\luameshval@tpi@mode","\luameshval@tpi@print","\luameshval@tpi@bbox","full","\luameshval@tpi@sc%ale","\luameshval@tpi@color")%
270   }%
271   \else % we are using MP
272   \mplibcolor{\luameshmpcolor}{\luameshval@tpi@color}
273   \mplibcolor{\luameshmpcolorBbox}{\luameshval@tpi@colorbbox}
274   \directlua{%
275     printPointsMPinc("#2","\luaescapestring{\unexpanded{#3}}","\luaescapestring{\unexpanded{#4}}","\luameshval@tpi@mode","\luameshval@tpi@print","\luameshval@tpi@bbox","\luameshval@tpi@scale")%
276   }%
277   \fi%
278 }%
279 %
280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 %% the meshAddOnePointBW commande
282 %%engine of drawing
283 \define@boolkey{MeshAddOneBW}{tikz}[true]{}%
284 %% the scale
285 \define@key{MeshAddOneBW}{scale}[1cm]{\def\luameshval@ap@scale{#1}}%
286 %% the name of the points
287 \define@key{MeshAddOneBW}{meshpoint}[P]{\def\luameshval@ap@meshpoint{#1}}%
288 %% the name of the new point
289 \define@key{MeshAddOneBW}{newpoint}[P]{\def\luameshval@ap@newpoint{#1}}%
290 %% a complete picture or some code of the engine
291 \define@choicekey*{MeshAddOneBW}{step}[\val\nr]{badtriangles, cavity, newtriangles}{%
292   \ifcase\nr\relax%
293   \def\luameshval@ap@step{badT}%
294   \or%
295   \def\luameshval@ap@step{cavity}%
296   \or%
297   \def\luameshval@ap@step{newT}%
298   \fi%
299 }%
300 % color
301 %% the color of drawing
302 \define@key{MeshAddOneBW}{color}[black]{\def\luameshval@ap@color{#1}}%
303 %% the color of background of new element
304 \define@key{MeshAddOneBW}{colorBack}[black!20]{\def\luameshval@ap@colorback{#1}}%
305 %% the color of new element
306 \define@key{MeshAddOneBW}{colorNew}[red]{\def\luameshval@ap@colornew{#1}}%
307 %% the color of circoncircle
308 \define@key{MeshAddOneBW}{colorCircle}[green]{\def\luameshval@ap@colorcircle{#1}}%
309 %% the name of the color of drawing the bbox
310 \define@key{MeshAddOneBW}{colorBbox}[black]{\def\luameshval@ap@colorbbox{#1}}%
311 %
312 %% a complete picture or some code of the engine
313 \define@choicekey*{MeshAddOneBW}{mode}[\val\nr]{int, ext}{%
314   \ifcase\nr\relax%
315   \def\luameshval@ap@mode{int}%
316   \or%
317   \def\luameshval@ap@mode{ext}%
318   \fi%
319 }%
320 \define@choicekey*{MeshAddOneBW}{bbox}[\val\nr]{none, show}{%
321   \ifcase\nr\relax%
322   \def\luameshval@ap@bbox{none}%
323   \or%
324   \def\luameshval@ap@bbox{bbox}%
325   \fi%
326 }%
327 \presetkeys{MeshAddOneBW}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none,colorBbox}{}%
328 %
329 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330 \newcommand*{\meshAddPointBW}[3][]{%
331   % #1 : optionnal arguments
332   % #2 : the string containing the list of points
333   % (x1,y1);(x2,y2);... or the name file containing the points
334   \setkeys{MeshAddOneBW}{#1} %
335   \def\MeshPoint{\luameshval@ap@meshpoint}%
336   \def\NewPoint{\luameshval@ap@newpoint}%
337   \ifKV@MeshAddOneBW@tikz% if we are using tikz
338   \directlua{%
339     TeXOnePointTikZBW("#2","#3","\luameshval@ap@step","\luameshval@ap@scale","\luameshval@ap@mode","\luameshval@ap@bbox","\luameshval@ap@color","\luameshval@ap@colorback","\luameshval@ap@colornew","\luameshval@ap@colorcircle","\luameshval@ap@colorbbox")%
340   }%
341   \else % we are using MP
342   \mplibcolor{\luameshmpcolor}{\luameshval@ap@color}
343   \mplibcolor{\luameshmpcolorBack}{\luameshval@ap@colorback}
344   \mplibcolor{\luameshmpcolorNew}{\luameshval@ap@colornew}
345   \mplibcolor{\luameshmpcolorCircle}{\luameshval@ap@colorcircle}
346   \mplibcolor{\luameshmpcolorBbox}{\luameshval@ap@colorbbox}
347   \directlua{%
348     TeXOnePointMPBW("#2","#3","\luameshval@ap@step","\luameshval@ap@scale","\luameshval@ap@mode","\luameshval@ap@bbox")%
349   }%
350   %
351   \fi%
352 }%
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 %%% the meshAddPointBWinc commande with callbacks
355 %% engine of drawing
356 \define@boolkey{MeshAddOneBWinc}{tikz}[true]{}%
357 %% the scale
358 \define@key{MeshAddOneBWinc}{scale}[1cm]{\def\luameshval@api@scale{#1}}%
359 %% the name of the points
360 \define@key{MeshAddOneBWinc}{meshpoint}[P]{\def\luameshval@api@meshpoint{#1}}%
361 %% the name of the new point
362 \define@key{MeshAddOneBWinc}{newpoint}[P]{\def\luameshval@api@newpoint{#1}}%
363 %% a complete picture or some code of the engine
364 \define@choicekey*{MeshAddOneBWinc}{step}[\val\nr]{badtriangles, cavity, newtriangles}{%
365   \ifcase\nr\relax%
366   \def\luameshval@api@step{badT}%
367   \or%
368   \def\luameshval@api@step{cavity}%
369   \or%
370   \def\luameshval@api@step{newT}%
371   \fi%
372 }%
373 % color
374 %% the color of drawing
375 \define@key{MeshAddOneBWinc}{color}[black]{\def\luameshval@api@color{#1}}%
376 %% the color of background of new element
377 \define@key{MeshAddOneBWinc}{colorBack}[black!20]{\def\luameshval@api@colorback{#1}}%
378 %% the color of new element
379 \define@key{MeshAddOneBWinc}{colorNew}[red]{\def\luameshval@api@colornew{#1}}%
380 %% the color of circoncircle
381 \define@key{MeshAddOneBWinc}{colorCircle}[green]{\def\luameshval@api@colorcircle{#1}}%
382 \define@key{MeshAddOneBWinc}{colorBbox}[black]{\def\luameshval@api@colorbbox{#1}}%
383 %
384 %% a complete picture or some code of the engine
385 \define@choicekey*{MeshAddOneBWinc}{mode}[\val\nr]{int, ext}{%
386   \ifcase\nr\relax%
387   \def\luameshval@api@mode{int}%
388   \or%
389   \def\luameshval@api@mode{ext}%
390   \fi%
391 }%
392 \define@choicekey*{MeshAddOneBWinc}{bbox}[\val\nr]{none, show}{%
393   \ifcase\nr\relax%
394   \def\luameshval@api@bbox{none}%
395   \or%
396   \def\luameshval@api@bbox{bbox}%
397   \fi%
398 }%
399 \presetkeys{MeshAddOneBWinc}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none,colorBbox}{}%
400 %
401 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 \newcommand*{\meshAddPointBWinc}[5][]{%
403   % #1 : optionnal arguments
404   % #2 : the string containing the list of points
405   % (x1,y1);(x2,y2);... or the name file containing the points
406   % #3 : the code to place before the generated one
407   % #4 : the code to place after the generated one
408   \setkeys{MeshAddOneBWinc}{#1} %
409   \def\MeshPoint{\luameshval@api@meshpoint}%
410   \def\NewPoint{\luameshval@api@newpoint}%
411   \ifKV@MeshAddOneBWinc@tikz% if we are using tikz
412   \directlua{%
413     TeXOnePointTikZBWinc("#2","#3","\luaescapestring{\unexpanded{#4}}","\luaescapestring{\unexpanded{#5}}","\luameshval@ap@step","\luameshval@ap@scale","\luameshval@ap@mode","\luameshval@ap@bbox","\luameshval@ap@color","\luameshval@ap@colorback","\luameshval@ap@colornew","\luameshval@ap@colorcircle","\luameshval@ap@colorbbox")%
414   }%
415   \else % we are using MP
416   \mplibcolor{\luameshmpcolor}{\luameshval@api@color}
417   \mplibcolor{\luameshmpcolorBack}{\luameshval@api@colorback}
418   \mplibcolor{\luameshmpcolorNew}{\luameshval@api@colornew}
419   \mplibcolor{\luameshmpcolorCircle}{\luameshval@api@colorcircle}
420   \mplibcolor{\luameshmpcolorBbox}{\luameshval@api@colorbbox}
421   \directlua{%
422     TeXOnePointMPBWinc("#2","#3","\luaescapestring{\unexpanded{#4}}","\luaescapestring{\unexpanded{#5}}","\luameshval@api@step","\luameshval@api@scale","\luameshval@api@mode","\luameshval@api@bbox")%
423   }%
424   %
425   \fi%
426 }%
427 %

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.