Doc: ajout des commandes à lstlisting
[delaunay.git] / doc / luamesh-doc.tex
1 % luamesh: compute and draw meshes with lua, luamplib and tikz
2 %
3 % Originally written by Maxime Chupin <mc@melusine.eu.org>,
4 % 2010.
5 %
6 % Distributed under the terms of the GNU free documentation licence:
7 % http://www.gnu.org/licenses/fdl.html
8 % without any invariant section or cover text.
9
10 \documentclass{lltxdoc}
11 \usepackage{tcolorbox}
12 \usepackage{xargs}
13 \usepackage{enumitem}
14 \usepackage[tikz]{bclogo}
15 \usepackage{wrapfig}
16 \title{\Verb+luamesh+: compute and draw meshes with \lualatex}
17 \author{Maxime Chupin \email{mc@melusine.eu.org}}
18 \date{\today}
19
20 \newcommand*\commande{\noindent\hspace{-30pt}%
21 \SaveVerb[aftersave={%
22 \UseVerb{Vitem}
23 }%
24 ]{Vitem}}
25
26 \newcommand*\textme[1]{\textcolor{black}{\rmfamily\textit{#1}}}
27 \newcommand*\meta[1]{% % meta
28 \textme{\ensuremath{\langle}#1\ensuremath{\rangle}}}
29 \newcommand*\optstar{% % optional star
30 \meta{\ensuremath{*}}\xspace}
31 \DefineShortVerb{\|}
32
33 \setlength{\fboxsep}{2pt}
34 \fvset{%
35 codes={\catcode`\«\active \catcode`\×\active },
36 defineactive={\makefancyog\makefancytimes},
37 formatcom=\color{red},
38 frame=single
39 }
40 % rendre «...» équivalent à \meta{...}
41 {\catcode`\«\active
42 \newcommandx\makefancyog[0][addprefix=\global]{%
43 \def«##1»{\meta{##1}}}}
44 % rendre × équivalent à \optstar
45 {\catcode`\×\active
46 \newcommandx\makefancytimes[0][addprefix=\global]{%
47 \def×{\optstar{}}}}
48
49
50 \tcbuselibrary{listings,breakable}
51
52 \definecolor{vert}{rgb}{0.1,0.4,0.1}
53 \definecolor{bleu}{rgb}{0.1,0.1,0.4}
54 \lstset{
55 numberstyle=\footnotesize\color{vert},
56 keywordstyle=\ttfamily\bfseries\color{blue},
57 basicstyle=\ttfamily\footnotesize,
58 commentstyle=\itshape\color{vert},
59 stringstyle=\ttfamily,
60 showstringspaces=false,
61 language=[LaTeX]TeX,
62 breaklines=true,
63 breakindent=30pt,
64 defaultdialect=[LaTeX]TeX,
65 morekeywords={buildMeshBW,buildMeshBWinc,drawPointsMesh,
66 drawPointsMeshinc, meshAddPointBW, meshAddPointBWinc}% frame=tb
67 }
68
69 \lstdefinelanguage{lua}
70 {morekeywords={for,end,function,do,if,else,elseif,then,
71 tex.print,tex.sprint,io.read,io.open,string.find,string.explode,require},
72 morecomment=[l]{--},
73 morecomment=[s]{--[[}{]]},
74 morestring=[b]''
75 }
76
77 \newtcblisting{Exemple}{%
78 arc=0pt,outer arc=0pt,
79 colback=red!2!white,
80 colframe=red!75!black,
81 breakable,
82 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle =
83 3pt, toptitle=3pt,
84 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt, toprule at break =
85 0pt, bottomrule at break = 0pt,
86 listing options={breaklines},
87 }
88
89 \newtcblisting{commandshell}{colback=black,colupper=white,colframe=black,
90 arc=0pt,
91 listing only,boxsep=0pt,listing
92 options={style=tcblatex,language=sh},
93 every listing line={\textcolor{red}{\small\ttfamily\bfseries user \$> }}}
94
95 \newtcblisting{latexcode}{
96 arc=0pt,
97 listing only,boxsep=0pt,listing
98 options={style=tcblatex}}
99
100
101 \newcommand\luamesh{\Verb+luamesh+\xspace}
102
103 \newenvironment{optionsenum}[1][]
104 {\begin{description}[font=\color{red}\ttfamily]}
105 {\end{description}}
106
107 \newenvironment{warning}{%
108 \setlength{\logowidth}{24pt}
109 \tcbset{%
110 arc=0pt,outer arc=0pt,colback=gray!10!white,colframe=gray!60!white,
111 boxsep=0pt,left=5pt,right=5pt,top=5pt,bottom=5pt, bottomtitle = 3pt, toptitle=3pt,
112 boxrule=0pt,bottomrule=0.5pt,toprule=0.5pt}
113 \medskip
114 \begin{tcolorbox}%
115 \begin{wrapfigure}[2]{L}{17pt}%
116 % \raisebox{-5pt}{
117 \vspace*{-0.55cm}
118 \bcinfo
119 % }%
120 \end{wrapfigure}
121 }%
122 {\end{tcolorbox}\medskip}
123
124
125
126 \begin{document}
127 %% === Page de garde ===================================================
128 \thispagestyle{empty}
129 \begin{tikzpicture}[remember picture, overlay]
130 \node[below right, shift={(-4pt,4pt)}] at (current page.north west) {%
131 \includegraphics{fond.pdf}%
132 };
133 \end{tikzpicture}%
134
135 \noindent
136 \includegraphics{luamesh}\\
137 {\large compute and draw meshes with \lualatex}\\[1cm]
138 \parbox{0.6\textwidth}{
139 \meshAddPointBW[
140 mode=ext,step=badtriangles,
141 colorNew =green!20!red,
142 colorBack=red!10,
143 colorCircle = blue,
144 bbox = show,
145 colorBbox = black!30
146 ]
147 {meshgarde.txt}{7}
148 }\hfill
149 \parbox{0.4\textwidth}{\Large\raggedleft
150 \textbf{Contributor}\\
151 Maxime \textsc{Chupin}
152 }
153 \vfill
154 \begin{center}
155 Version 0.1, 25 novembre 2016\\
156 \url{http://melusine.eu.org/syracuse/G/delaunay/}
157 \end{center}
158 %% == Page de garde ====================================================
159 \newpage
160
161 \maketitle
162
163 \begin{abstract}
164 The package \Verb|luamesh| allows to compute and draw 2D triangulation
165 of Delaunay. The algorithm is written with lua, and depending of the
166 choice of the ``engine'', the draw is done by MetaPost (with
167 \Verb|luamplib|) or by \Verb|tikz|.
168
169 The Delaunay triangulation algorithm is the Bowyer and Watson
170 algorithm. Several macros are provided to draw the global mesh, the
171 set of points, a particular step of the algorithm.
172 \end{abstract}
173
174 \section{Installation}
175
176 \subsection{With Linux}
177
178 To install \luamesh with \TeX live, you have to create the local
179 \Verb+texmf+ directory in your \Verb+home+.
180
181 \begin{commandshell}
182 mkdir ~/texmf
183 \end{commandshell}
184
185 Then we have to files to place in the correct directories. First, the
186 \Verb+luamesh.sty+ file must be in the directory:
187 \begin{center}
188 \Verb+~/texmf/tex/latex/luamesh/+
189 \end{center}
190 and secondly, the \Verb+luamesh.lua+ must be in the directory:
191 \begin{center}
192 \Verb+~/texmf/scripts/luamesh/+
193 \end{center}
194
195 Once you have done this, \luamesh can be included in your document
196 with
197 \begin{latexcode}
198 \usepackage{luamesh}
199 \end{latexcode}
200
201 \subsection{Dependencies}
202
203 This package is built upon two main packages to draw the
204 triangulations :
205 \begin{enumerate}
206 \item \Verb+luamplib+ to use MetaPost via the \luatex library
207 \Verb+mplib+;
208 \item or \Verb+tikz+.
209 \end{enumerate}
210 We will see how to choose between these two \emph{drawing engines}.
211
212 Moreover, the following packages are necessary:
213 \begin{enumerate}
214 \item \Verb+xkeyval+ to manage the optional arguments;
215 \item \Verb+xcolor+ to use colors (needed by \Verb+luamplib+);
216 \item \Verb+ifthen+ to help the programming with \TeX.
217 \end{enumerate}
218
219
220 \section{The Basic Macros}
221
222 If you want to use this package, you must compile your document with
223 \Verb+lualatex+:
224
225 \begin{commandshell}
226 lualatex mylatexfile.tex
227 \end{commandshell}
228
229 Let us recall that this package provides macros to draw two
230 dimensional triangulations (or meshes).
231
232 \subsection{Draw a Complete Mesh}
233
234 \commande|\buildMeshBW[«options»]{«list of points» or «file name»}|\medskip
235
236 This macro produce the Delaunay triangulation (using the Bowyer and
237 Watson algorithm) of the given \meta{list of points}. The list of
238 points must be given in the following way :
239 \begin{center}
240 \verb+(x1,y1);(x2,y2);(x3,y3);...;(xn,yn)+
241 \end{center}
242
243 \begin{Exemple}
244 \buildMeshBW{(0.3,0.3);(1.5,1);(4,0);(4.5,2.5);(1.81,2.14);(2.5,0.5);(2.8,1.5)}
245 \end{Exemple}
246
247 \subsubsection{The Options}
248
249 There are several options to customize the drawing.
250 \begin{optionsenum}
251 \item[mode = int (default) or ext:] this option allows to
252 use either the previously described set of point in the argument, or
253 a file, containing, line by line (2 columns), the points. Such a
254 file looks like :
255 \begin{verbatim}
256 x1 y1
257 x2 y2
258 x3 y3
259 ...
260 xn yn
261 \end{verbatim}
262 \item[bbox = none (default) or show:] this option allows to draw the
263 added points to form a \emph{bounding box}\footnote{The bounding
264 box is defined by four points place at 15\% around the box
265 defined by $(x_{\min},y_{\min})$, $(x_{\min},y_{\max})$,
266 $(x_{\max},y_{\max})$, and $(x_{\min},y_{\max})$.} and the corresponding
267 triangulation. By default, these triangles are removed at the end of
268 the algorithm.
269 \item[color = \meta{value} (default: black):] The color of the
270 drawing.
271 \item[colorBbox = \meta{value} (default: black):] The color of the
272 drawing for the elements (points and triangles) belonging to the
273 bounding box.
274 \item[print = none (default) or points:] To label the vertices of the
275 triangulations with an adding dot.
276 \item[meshpoint = \meta{value} (default: P):] The letter(s) used to
277 label the vertices of the triangulation. It is include in the math
278 mode delimiters \Verb+$...$+. The bounding box points are labeled
279 with a star exponent, and numbered from 1 to 4.
280 \item[tikz (boolean, default:false):] By default, this boolean is set
281 to \Verb+false+, and MetaPost (with \Verb+luamplib+) is used to draw
282 the picture. With this option, it is \Verb+tikz+ the \textit{drawing
283 engine}.
284 \item[scale = \meta{value} (default: 1cm):] The scale option defines
285 the scale at which the picture is draw (the same for the two
286 axis). It must contain the unit of length (cm,
287 pt, etc.).
288 \end{optionsenum}
289
290 To illustrate the options, let us show you an example. We consider a
291 file \Verb+mesh.txt+:
292 \begin{verbatim}
293 0.3 0.3
294 1.5 1
295 4 0
296 4.5 2.5
297 1.81 2.14
298 2.5 0.5
299 2.8 1.5
300 \end{verbatim}
301 \begin{Exemple}
302 \buildMeshBW[%
303 tikz,
304 mode = ext,
305 bbox = show,
306 color = red,
307 colorBbox = blue!30,
308 print = points,
309 meshpoint = x,
310 scale = 1.3cm,
311 ]{mesh.txt}
312 \end{Exemple}
313
314 \begin{warning}
315 The drawing engine is not here very relevant. But it is useful to
316 understand how the drawing is made. However, the engine will make sens
317 for the so called \emph{inc} macros (section~\ref{sec:inc}), where we
318 will be allowed to add code before and after the generated one by
319 \luamesh.
320 \end{warning}
321
322 \subsection{Draw the Set of Points}
323
324 \commande|\drawPointsMesh[«options»]{«list of points» or «file name»}|
325
326
327 \subsection{Draw a Step of the Bowyer and Watson Algorithm}
328
329 \commande|\meshAddPointBW[«options»]{«list of points» or «file name»}{«point» or «number of line»}|
330
331
332 \section{The \emph{inc} Macros}\label{sec:inc}
333
334 \section{Gallery of Examples}
335
336 \end{document}
337
338
339
340 %%% Local Variables:
341 %%% flyspell-mode: 1
342 %%% ispell-local-dictionary: "american"
343 %%% End:

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.