Debian Codegraph @

texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_pgflibraryluamath.code.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%% This file is a copy of some part of PGF/Tikz.
3 %%% It has been copied here to provide :
4 %%% - compatibility with older PGF versions
5 %%% - availability of PGF contributions by Christian Feuersaenger
6 %%% which are necessary or helpful for pgfplots.
7 %%%
8 %%% For reasons of simplicity, I have copied the whole file, including own contributions AND
9 %%% PGF parts. The copyrights are as they appear in PGF.
10 %%%
11 %%% Note that pgfplots has compatible licenses.
12 %%%
13 %%% This copy has been modified in the following ways:
14 %%% - nested \input commands have been updated
15 %%%
16 %
17 % Support for the contents of this file will NOT be done by the PGF/TikZ team.
18 % Please contact the author and/or maintainer of pgfplots (Christian Feuersaenger) if you need assistance in conjunction
19 % with the deployment of this patch or partial content of PGF. Note that the author and/or maintainer of pgfplots has no obligation to fix anything:
20 % This file comes without any warranty as the rest of pgfplots; there is no obligation for help.
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %%% Date of this copy: Mo 30. Apr 17:24:35 CEST 2018 %%%
23
24
25
26 % Copyright 2011 by Christophe Jorssen and Mark Wibrow
27 % Copyright 2014 by Christian Feuersänger
28 %
29 % This file may be distributed and/or modified
30 %
31 % 1. under the LaTeX Project Public License and/or
32 % 2. under the GNU Public License.
33 %
34 % See the file doc/generic/pgf/licenses/LICENSE for more details.
35 %
36 % $Id$
37 %
38 %
39 % This is a library for a LUA math parser and LUA math operations.
40 % Advantage compared to its TeX pendant: it is FASTER and has HIGHER
41 % ACCURACY.
42 % Disadvantage: any function declared by means of
43 % \pgfmathdeclarefunction is NOT automatically transported to the LUA
44 % side (at the time of this writing).
45 % LUA functions need to be defined by means of LUA code
46 %
47 % function pgfluamathfunctions.myoperation(a,b)
48 % return a*2*b
49 % end
50 %
51 % this will automatically set up 'myoperation' for use in
52 % \pgfluamathparse{myoperation(4,2)}
53 %
54 % The library has TWO use-cases which are more or less distinct: one
55 % is to use LUA for all math function, but not for math expression
56 % parsing -- this was still under control of the TeX math parser.
57 % This approach works like the 'fpu' library.
58 %
59 % The second approach is to use LUA to parse all math expressions -
60 % but if someone calls \pgfmathadd@{1}{2}, it would use the TeX
61 % command. This approach is relatively lightweight because it does not
62 % need to substitute all \pgfmath* macros.
63 %
64 % One can mix both modes.
65
66 % *******************************************************************
67 % Some luatex stuff. Should be put elsewhere (e.g. in
68 % pgfutil-luatex-engine).
69
70 \edef\pgfliblua@oldcatcodedoublequote{\the\catcode`\"}%
71 \catcode`\"=12
72
73 % We assume luatex version > 0.39:
74 % - \directlua <general text> will work
75 % - \directlua is the only luatex primitive that we can assume
76 % accessible without being prefixed by the format via
77 % tex.enableprimitives.
78 % Ideas taken from the ifluatex package (Heiko Oberdiek)
79 \let\pgfutil@ifluatex\iffalse
80 \begingroup\expandafter\expandafter\expandafter\endgroup
81 \expandafter\ifx\csname directlua\endcsname\relax
82 \else
83 \expandafter\let\csname pgfutil@ifluatex\expandafter\endcsname
84 \csname iftrue\endcsname
85 \fi
86
87 \pgfutil@ifluatex
88 \let\pgfutil@directlua\directlua
89 \pgfutil@directlua{%
90 tex.enableprimitives('pgfutil@',{'luaescapestring'})}
91 \else
92 \def\pgfutil@directlua#1{}
93 \def\pgfutil@luaescapestring#1{}
94 \fi
95
96 \pgfutil@directlua{%
97 pgfluamathfunctions = require("pgfplotsoldpgfsupp.luamath.functions")
98 pgfluamathparser = require("pgfplotsoldpgfsupp.luamath.parser")}
99
100
101 % Patch some configuration macros such that the modifications are
102 % available in LUA as well:
103 \pgfkeys{
104 /pgf/trig format/deg/.add code={}{\directlua{pgfluamathfunctions.setTrigFormat("deg")}\aftergroup\pgfmath@settrigformat},
105 /pgf/trig format/rad/.add code={}{\directlua{pgfluamathfunctions.setTrigFormat("rad")}\aftergroup\pgfmath@settrigformat},
106 }
107 % ... and reactivate the key:
108 \pgfmathiftrigonometricusesdeg{%
109 \pgfkeys{/pgf/trig format/deg}%
110 }{%
111 \pgfkeys{/pgf/trig format/rad}%
112 }%
113
114 % re-activates the current trig format. This is important after a TeX
115 % group has been closed.
116 \def\pgfmath@settrigformat{%
117 \pgfmathiftrigonometricusesdeg{%
118 \directlua{pgfluamathfunctions.setTrigFormat("deg")}%
119 }{%
120 \directlua{pgfluamathfunctions.setTrigFormat("rad")}%
121 }%
122 }%
123
124 \let\pgfmathsetseed@pgfbasic = \pgfmathsetseed
125 \def\pgfmathsetseed#1{%
126 \pgfmathsetseed@pgfbasic{#1}%
127 \directlua{pgfluamathfunctions.setRandomSeed(pgfluamathfunctions.tonumber("\pgfmathresult"))}%
128 }%
129
130 % Patch 'declare function' such that it communicates the function
131 % directly to LUA.
132 \let\pgfmathnotifynewdeclarefunction@orig=\pgfmathnotifynewdeclarefunction
133 \def\pgfmathnotifynewdeclarefunction#1#2#3{%
134 \pgfmathnotifynewdeclarefunction@orig{#1}{#2}{#3}%
135 %
136 % we have to check if '#3' contains control sequences.
137 % this is highly tricky as it may contain '#1'...
138 \begingroup
139 \toks0={#3}%
140 \xdef\pgf@marshal@glob{\the\toks0 }%
141 \endgroup
142 \pgfutil@command@to@string\pgf@marshal@glob\pgf@marshal
143 \expandafter\pgfutilifcontainsmacro\expandafter{\pgf@marshal}{%
144 \def\pgf@temp{1}%
145 }{%
146 \def\pgf@temp{0}%
147 }%
148 \if1\pgf@temp
149 % let lua produce an error when evaluating this function -- we cannot possibly expand the macro to its current state:
150 \directlua{pgfluamathparser.pushLocalExpressionFunction(%
151 "\pgfutil@luaescapestring{#1}",%
152 #2,%
153 "functionMustBeEvaluatedInTeX")}%
154 \else
155 \directlua{pgfluamathparser.pushLocalExpressionFunction(%
156 "\pgfutil@luaescapestring{#1}",%
157 #2,%
158 "\pgfutil@luaescapestring{#3}")}%
159 \fi
160 %
161 % ensure that the local function is removed at the end of the
162 % scope. To this end, we maintain a stack on the LUA side.
163 \aftergroup\pgfluamathparse@pop@local@function
164 }%
165
166 \def\pgfluamathparse@pop@local@function{%
167 \directlua{pgfluamathparser.popLocalExpressionFunction()}%
168 }%
169
170 % End of luatex stuff
171 % *******************************************************************
172
173 % Loading part: based on fpu library
174
175
176 % if LUA failed to evaluate the expression, it will be evaluated in
177 % TeX as fallback. This boolean defines if the error message shall be
178 % shown or suppressed. The default is to suppress it and show any
179 % resulting TeX errors.
180 %
181 % If LUA fails \pgfmathresult will be empty.
182 %
183 % This is actually only for debugging; it will be set implicitly when
184 % activating/deactivating TeX fallback.
185 \newif\ifpgfluamathshowerrormessage
186
187 % Defines what happens if LUA failed to evaluate the expression: if
188 % this is true, the TeX parser will be invoked as fallback.
189 %
190 % This happens
191 % - for \chardef'ed boxes for which LUA lacks evaluation capabilities
192 % - if the expression includes some function which is unavailable in
193 % LUA (defined only in TeX)
194 % - some special cases which simply haven't been added to the LUA
195 % parser (yet).
196 % At the time of this writing, this includes
197 % -- arrays created via '{}' and indexed with '[]'
198 % -- strings with "<str>"
199 % -- 'scalar' function
200 % -- hex/octal/binary input
201 \newif\ifpgfluamathenableTeXfallback
202
203 \newif\ifpgfluamathcomputationactive
204 \newif\ifpgfluamathparseractive
205
206 \def\pgfluamath@makecomputationactive{%
207 \ifpgfluamathcomputationactive
208 \else
209 \pgfluamath@checkuninstallcmd%
210 \pgfluamath@install%
211 \pgfluamathcomputationactivetrue
212 \fi}
213
214 \def\pgfluamath@makecomputationinactive{%
215 \ifpgfluamathcomputationactive
216 \pgfluamath@uninstall%
217 \pgfluamathcomputationactivefalse
218 \fi}
219
220 \let\pgfluamath@pgfmathparse\pgfmathparse
221 \def\pgfluamath@makeparseractive{%
222 \ifpgfluamathparseractive
223 \else
224 \let\pgfluamath@pgfmathparse\pgfmathparse
225 \let\pgfmathparse\pgfluamathparse
226 \let\pgfmath@iftrue=\pgfmathluamath@iftrue
227 \pgfluamathparseractivetrue
228 \fi}
229
230 \let\pgfmath@iftrue@basic=\pgfmath@iftrue
231
232 \def\pgfluamath@makeparserinactive{%
233 \ifpgfluamathparseractive
234 \let\pgfmathparse\pgfluamath@pgfmathparse
235 \let\pgfmath@iftrue=\pgfmath@iftrue@basic
236 \pgfluamathparseractivefalse
237 \fi}
238
239 \pgfqkeys{/pgf}{%
240 % Enable lua-side computation of \pgfmathresult
241 % (will be deactivated after the current TeX group)
242 luamath/.is choice,
243 luamath/only computation/.code={%
244 \pgfutil@ifluatex
245 \pgfluamath@makecomputationactive
246 \pgfluamath@makeparserinactive
247 \else
248 \pgfmath@error{Sorry, you need the luaTeX engine to use the
249 luamath library}%
250 \fi},
251 luamath/parser and computation/.code={%
252 \pgfutil@ifluatex
253 \pgfluamath@makecomputationactive
254 \pgfluamath@makeparseractive
255 \else
256 \pgfmath@error{Sorry, you need the luaTeX engine to use the
257 luamath library}%
258 \fi},
259 luamath/off/.code={%
260 \pgfluamath@makecomputationinactive
261 \pgfluamath@makeparserinactive},
262 luamath/.default=only computation,
263 %
264 % activates ONLY the parser. This is fast and does not replace the
265 % \pgfmath* functions.
266 % @see |parser and computation| which also allows to write
267 % \pgfmathadd{1}{2} to call LUA
268 luamath/parser/.code={%
269 \pgfutil@ifluatex
270 \pgfluamath@makeparseractive
271 \else
272 \pgfmath@error{Sorry, you need the luaTeX engine to use the
273 luamath library}%
274 \fi
275 },
276 luamath/output format/.is choice,
277 luamath/output format/fixed/.code= {\def\pgfluamath@outputformat@choice{0}},
278 % returns results for use in the FPU
279 luamath/output format/float/.code= {\def\pgfluamath@outputformat@choice{1}},
280 luamath/output format/fixed,
281 % this is merely useful for debugging purposes, I guess.
282 luamath/show error message/.is if=pgfluamathshowerrormessage,
283 luamath/enable TeX fallback/.is choice,
284 luamath/enable TeX fallback/true/.code={\pgfluamathenableTeXfallbacktrue\pgfluamathshowerrormessagefalse},
285 luamath/enable TeX fallback/false/.code={\pgfluamathenableTeXfallbackfalse\pgfluamathshowerrormessagetrue},
286 luamath/enable TeX fallback/.default=true,
287 luamath/enable TeX fallback=true,
288 }
289
290 \def\pgfluamath@uninstall@appendcmd#1{%
291 \expandafter\gdef\expandafter\pgfluamath@uninstall\expandafter{%
292 \pgfluamath@uninstall #1}}
293
294 % If the uninstall command is already assembled, it will skip the
295 % uninstall assemblation.
296 \def\pgfluamath@checkuninstallcmd{%
297 \pgfutil@ifundefined{pgfluamath@uninstall}{%
298 \global\let\pgfluamath@uninstall=\pgfutil@empty
299 }{%
300 % We already HAVE an uninstall command (prepared globally).
301 % So: don't waste time assembling one!
302 \def\pgfluamath@uninstall@appendcmd##1{}%
303 \def\pgfluamath@prepareuninstallcmd##1{}%
304 }%
305 }
306
307 % This assembles an uninstall command globally ON FIRST USAGE.
308 % See \pgfmathfloat@plots@checkuninstallcmd
309 \def\pgfluamath@prepareuninstallcmd#1{%
310 \expandafter\global\expandafter\let
311 \csname pgfluamath@backup@\string#1\endcsname=#1%
312 \expandafter\gdef\expandafter\pgfluamath@uninstall\expandafter{%
313 \pgfluamath@uninstall
314 \expandafter\let\expandafter#1\csname pgfluamath@backup@\string#1\endcsname}%
315 }
316
317 \def\pgfluamath@install@function#1=#2{%
318 \pgfluamath@prepareuninstallcmd{#1}%
319 \let#1=#2%
320 }
321
322 \def\pgfluamath@install{%
323 \pgfluamath@install@function\pgfmathadd@=\pgfluamathadd@%
324 \pgfluamath@install@function\pgfmathsubtract@=\pgfluamathsubtract@%
325 \pgfluamath@install@function\pgfmathneg@=\pgfluamathneg@%
326 \pgfluamath@install@function\pgfmathmultiply@=\pgfluamathmultiply@%
327 \pgfmathfloat@install\pgfmath@iftrue=\pgfmathluamath@iftrue
328 \pgfluamath@install@function\pgfmathdivide@=\pgfluamathdivide@%
329 % \pgfluamath@install@function\pgfmathdiv@=\pgfluamathdiv@%
330 \pgfluamath@install@function\pgfmathfactorial@=\pgfluamathfactorial@%
331 \pgfluamath@install@function\pgfmathsqrt@=\pgfluamathsqrt@%
332 % \pgfluamath@install@function\pgfmathpow@=\pgfluamathpow@%
333 \pgfluamath@install@function\pgfmathe@=\pgfluamathe@%
334 \pgfluamath@install@function\pgfmathexp@=\pgfluamathexp@%
335 \pgfluamath@install@function\pgfmathln@=\pgfluamathln@%
336 \pgfluamath@install@function\pgfmathlogten@=\pgfluamathlogten@%
337 % \pgfluamath@install@function\pgfmathlogtwo@=\pgfluamathlogtwo@%
338 \pgfluamath@install@function\pgfmathabs@=\pgfluamathabs@%
339 \pgfluamath@install@function\pgfmathmod@=\pgfluamathmod@%
340 \pgfluamath@install@function\pgfmathMod@=\pgfluamathMod@%
341 \pgfluamath@install@function\pgfmathround@=\pgfluamathround@%
342 \pgfluamath@install@function\pgfmathfloor@=\pgfluamathfloor@%
343 \pgfluamath@install@function\pgfmathceil@=\pgfluamathceil@%
344 % \pgfluamath@install@function\pgfmathint@=\pgfluamathint@%
345 % \pgfluamath@install@function\pgfmathfrac@=\pgfluamathfrac@%
346 % \pgfluamath@install@function\pgfmathreal@=\pgfluamathreal@%
347 \pgfluamath@install@function\pgfmathgcd@=\pgfluamathgcd@%
348 \pgfluamath@install@function\pgfmathisprime@=\pgfluamathisprime@%
349 \pgfluamath@install@function\pgfmathpi@=\pgfluamathpi@%
350 \pgfluamath@install@function\pgfmathrad@=\pgfluamathrad@%
351 \pgfluamath@install@function\pgfmathdeg@=\pgfluamathdeg@%
352 \pgfluamath@install@function\pgfmathsin@=\pgfluamathsin@%
353 \pgfluamath@install@function\pgfmathcos@=\pgfluamathcos@%
354 \pgfluamath@install@function\pgfmathtan@=\pgfluamathtan@%
355 \pgfluamath@install@function\pgfmathsec@=\pgfluamathsec@%
356 \pgfluamath@install@function\pgfmathcosec@=\pgfluamathcosec@%
357 \pgfluamath@install@function\pgfmathcot@=\pgfluamathcot@%
358 \pgfluamath@install@function\pgfmathasin@=\pgfluamathasin@%
359 \pgfluamath@install@function\pgfmathacos@=\pgfluamathacos@%
360 \pgfluamath@install@function\pgfmathatan@=\pgfluamathatan@%
361 \pgfluamath@install@function\pgfmathatantwo@=\pgfluamathatantwo@%
362 \pgfluamath@install@function\pgfmathmax@=\pgfluamathmax@%
363 \pgfluamath@install@function\pgfmathmin@=\pgfluamathmin@%
364 % \pgfluamath@install@function\pgfmath@pi=\pgfluamathpi@%
365 % \pgfluamath@install@function\pgfmathpi=\pgfluamathpi@%
366 % \pgfluamath@install@function\pgfmathe@=\pgfluamathe@%
367 % \pgfluamath@install@function\pgfmathe=\pgfluamathe@%
368 % \pgfluamath@install@function\pgfmathlessthan@=\pgfluamathlessthan@%
369 % \pgfluamath@install@function\pgfmathless@=\pgfluamathlessthan@%
370 % \pgfluamath@install@function\pgfmathgreaterthan@=\pgfluamathgreaterthan@%
371 % \pgfluamath@install@function\pgfmathgreater@=\pgfluamathgreaterthan@%
372 % \pgfluamath@install@function\pgfmathpow@=\pgfluamathpow@
373 \pgfluamath@install@function\pgfmathrand@=\pgfluamathrand@
374 \pgfluamath@install@function\pgfmathrand=\pgfluamathrand@
375 \pgfluamath@install@function\pgfmathrnd@=\pgfluamathrnd@
376 \pgfluamath@install@function\pgfmathrnd=\pgfluamathrnd@
377 % \pgfluamath@install@function\pgfmathtrue@=\pgfluamathtrue@
378 % \pgfluamath@install@function\pgfmathfalse@=\pgfluamathfalse@
379 % \pgfluamath@install@function\pgfmathnot@=\pgfluamathnot@
380 % \pgfluamath@install@function\pgfmathhex@=\pgfluamathhex@
381 % \pgfluamath@install@function\pgfmathHex@=\pgfluamathHex@
382 % \pgfluamath@install@function\pgfmathoct@=\pgfluamathoct@
383 % \pgfluamath@install@function\pgfmathbin@=\pgfluamathbin@
384 % \pgfluamath@install@function\pgfmathand@=\pgfluamathand@
385 % \pgfluamath@install@function\pgfmathor@=\pgfluamathor@
386 % \pgfluamath@install@function\pgfmathfactorial@=\pgfluamathfactorial@
387 % \pgfluamath@install@function\pgfmathveclen@=\pgfluamathveclen@
388 % \pgfluamath@install@function\pgfmathcosh@=\pgfluamathcosh@
389 % \pgfluamath@install@function\pgfmathsinh@=\pgfluamathsinh@
390 % \pgfluamath@install@function\pgfmathtanh@=\pgfluamathtanh@
391 % \pgfluamath@install@function@unimplemented{ceil}%
392 % \pgfluamath@install@function@unimplemented{frac}%
393 % \pgfluamath@install@function@unimplemented{log2}%
394 % \pgfluamath@install@function@unimplemented{log10}%
395 % \pgfluamath@install@function@unimplemented{equalto}%
396 % \pgfluamath@install@function@unimplemented{random}%
397 % \pgfluamath@install@function@unimplemented{setseed}%
398 % \pgfluamath@install@function@unimplemented{Mod}%
399 % \pgfluamath@install@function@unimplemented{real}%
400 % \pgfluamath@install@function@unimplemented{notequal}%
401 \pgfluamath@install@function\pgfmathreciprocal=\pgfluamathreciprocal%
402 \pgfluamath@install@function\pgfpointnormalised=\pgfluamathpointnormalised
403 }
404
405 \def\pgfluamathgetresult#1{%
406 \edef\pgfmathresult{\pgfutil@directlua{tex.print(-1,#1)}}}
407
408 \def\pgfmathluamath@iftrue{%
409 \if 0\pgfluamath@outputformat@choice
410 \let\pgfmathluamath@@iftrue@v=\pgfluamathone
411 \else
412 \let\pgfmathluamath@@iftrue@v=\pgfluamathfloatone
413 \fi
414 \pgfmathluamath@iftrue@
415 }%
416 \def\pgfluamathone{1.0}%
417 \def\pgfluamathfloatone{1Y1.0e+00]}%
418 \def\pgfmathluamath@iftrue@#1#2{%
419 \ifx\pgfmathresult\pgfmathluamath@@iftrue@v
420 \def\pgfmath@next{#1}%
421 \else
422 \def\pgfmath@next{#2}%
423 \fi
424 \pgfmath@next
425 }%
426
427 \def\pgfluamathpi@{%
428 \pgfluamathgetresult{pgfluamathfunctions.pi()}}
429 \def\pgfluamathe@{%
430 \pgfluamathgetresult{pgfluamathfunctions.e()}}
431 \def\pgfluamathadd@#1#2{%
432 \pgfluamathgetresult{pgfluamathfunctions.add(#1,#2)}}
433 \def\pgfluamathsubtract@#1#2{%
434 \pgfluamathgetresult{pgfluamathfunctions.substract(#1,#2)}}
435 \def\pgfluamathneg@#1{%
436 \pgfluamathgetresult{pgfluamathfunctions.neg(#1)}}
437 \def\pgfluamathmultiply@#1#2{%
438 \pgfluamathgetresult{pgfluamathfunctions.multiply(#1,#2)}}
439 \def\pgfluamathdivide@#1#2{%
440 \pgfluamathgetresult{pgfluamathfunctions.divide(#1,#2)}}
441 \def\pgfluamathabs@#1{%
442 \pgfluamathgetresult{pgfluamathfunctions.abs(#1)}}
443 \def\pgfluamathround@#1{%
444 \pgfluamathgetresult{pgfluamathfunctions.round(#1)}}
445 \def\pgfluamathfloor@#1{%
446 \pgfluamathgetresult{pgfluamathfunctions.floor(#1)}}
447 \def\pgfluamathceil@#1{%
448 \pgfluamathgetresult{pgfluamathfunctions.ceil(#1)}}
449 \def\pgfluamathgcd@#1#2{%
450 \pgfluamathgetresult{pgfluamathfunctions.gcd(#1,#2)}}
451 \def\pgfluamathisprime@#1{%
452 \pgfluamathgetresult{pgfluamathfunctions.isprime(#1)}}
453 \def\pgfluamathmax@#1{%
454 \pgfluamathgetresult{%
455 math.max(pgfluamathfunctions.split_braces_to_explist("#1"))}}
456 \def\pgfluamathmin@#1{%
457 \pgfluamathgetresult{%
458 math.min(pgfluamathfunctions.split_braces_to_explist("#1"))}}
459 \def\pgfluamathsin@#1{%
460 \pgfluamathgetresult{pgfluamathfunctions.Sin(#1)}}
461 \def\pgfluamathcos@#1{%
462 \pgfluamathgetresult{pgfluamathfunctions.Cos(#1)}}
463 \def\pgfluamathtan@#1{%
464 \pgfluamathgetresult{pgfluamathfunctions.Tan(#1)}}
465 \def\pgfluamathmod@#1#2{%
466 \pgfluamathgetresult{pgfluamathfunctions.mod(#1,#2)}}
467 \def\pgfluamathMod@#1#2{%
468 \pgfluamathgetresult{pgfluamathfunctions.Mod(#1,#2)}}
469 \def\pgfluamathrad@#1{%
470 \pgfluamathgetresult{pgfluamathfunctions.rad(#1)}}
471 \def\pgfluamathdeg@#1{%
472 \pgfluamathgetresult{pgfluamathfunctions.deg(#1)}}
473 \def\pgfluamathatan@#1{%
474 \pgfluamathgetresult{pgfluamathfunctions.aTan(#1)}}
475 \def\pgfluamathatantwo@#1#2{%
476 \pgfluamathgetresult{pgfluamathfunctions.aTan2(#1,#2)}}
477 \def\pgfluamathasin@#1{%
478 \pgfluamathgetresult{pgfluamathfunctions.aSin(#1)}}
479 \def\pgfluamathacos@#1{%
480 \pgfluamathgetresult{pgfluamathfunctions.aCos(#1)}}
481 \def\pgfluamathcot@#1{%
482 \pgfluamathgetresult{1/pgfluamathfunctions.Tan(#1)}}
483 \def\pgfluamathsec@#1{%
484 \pgfluamathgetresult{1/pgfluamathfunctions.Cos(#1)}}
485 \def\pgfluamathcosec@#1{%
486 \pgfluamathgetresult{1/pgfluamathfunctions.Sin(#1)}}
487 \def\pgfluamathexp@#1{%
488 \pgfluamathgetresult{pgfluamathfunctions.exp(#1)}}
489 \def\pgfluamathln@#1{%
490 \pgfluamathgetresult{pgfluamathfunctions.log(#1)}}
491 \def\pgfluamathlogten@#1{%
492 \pgfluamathgetresult{pgfluamathfunctions.log10(#1)}}
493 \def\pgfluamathsqrt@#1{%
494 \pgfluamathgetresult{pgfluamathfunctions.sqrt(#1)}}
495 \def\pgfluamathrnd@{%
496 \pgfluamathgetresult{pgfluamathfunctions.rnd()}}
497 \def\pgfluamathrand@{%
498 \pgfluamathgetresult{pgfluamathfunctions.rand(-1,1)}}
499 \def\pgfluamathfactorial@#1{%
500 \pgfluamathgetresult{pgfluamathfunctions.factorial(#1)}}
501 \def\pgfluamathreciprocal#1{%
502 \pgfluamathgetresult{1/#1}}
503 % \pgfluamath@install@function\pgfmath@pi=\pgfluamathpi@%
504 % \pgfluamath@install@function\pgfmathpi=\pgfluamathpi@%
505 % \pgfluamath@install@function\pgfmathe@=\pgfluamathe@%
506 % \pgfluamath@install@function\pgfmathe=\pgfluamathe@%
507 % \pgfluamath@install@function\pgfmathlessthan@=\pgfluamathlessthan@%
508 % \pgfluamath@install@function\pgfmathless@=\pgfluamathlessthan@%
509 % \pgfluamath@install@function\pgfmathgreaterthan@=\pgfluamathgreaterthan@%
510 % \pgfluamath@install@function\pgfmathgreater@=\pgfluamathgreaterthan@%
511 % \pgfluamath@install@function\pgfmathpow@=\pgfluamathpow@
512 % \pgfluamath@install@function\pgfmathrand@=\pgfluamathrand@
513 % \pgfluamath@install@function\pgfmathrand=\pgfluamathrand@
514 % \pgfluamath@install@function\pgfmathrnd@=\pgfluamathrnd@
515 % \pgfluamath@install@function\pgfmathrnd=\pgfluamathrnd@
516 % \pgfluamath@install@function\pgfmathtrue@=\pgfluamathtrue@
517 % \pgfluamath@install@function\pgfmathfalse@=\pgfluamathfalse@
518 % \pgfluamath@install@function\pgfmathnot@=\pgfluamathnot@
519 % \pgfluamath@install@function\pgfmathhex@=\pgfluamathhex@
520 % \pgfluamath@install@function\pgfmathHex@=\pgfluamathHex@
521 % \pgfluamath@install@function\pgfmathoct@=\pgfluamathoct@
522 % \pgfluamath@install@function\pgfmathbin@=\pgfluamathbin@
523 % \pgfluamath@install@function\pgfmathand@=\pgfluamathand@
524 % \pgfluamath@install@function\pgfmathor@=\pgfluamathor@
525 % \pgfluamath@install@function\pgfmathfactorial@=\pgfluamathfactorial@
526 % \pgfluamath@install@function\pgfmathveclen@=\pgfluamathveclen@
527 % \pgfluamath@install@function\pgfmathcosh@=\pgfluamathcosh@
528 % \pgfluamath@install@function\pgfmathsinh@=\pgfluamathsinh@
529 % \pgfluamath@install@function\pgfmathtanh@=\pgfluamathtanh@
530
531 \def\pgfluamathpointnormalised#1{%
532 \pgf@process{#1}%
533 \pgfutil@directlua{%
534 pgfluamathfunctions.pointnormalised(%
535 \pgf@sys@tonumber{\pgf@x},\pgf@sys@tonumber{\pgf@y})}%
536 \ignorespaces}
537
538 % Parser
539
540 \newif\ifpgfluamathunitsdeclared
541
542 % true if and only if LUA failed to evaluate the expression and the
543 % expression was evaluated by means of the TeX parser as fallback.
544 %
545 % This happens
546 % - for \chardef'ed boxes for which LUA lacks evaluation capabilities
547 % - if the expression includes some function which is unavailable in
548 % LUA (defined only in TeX)
549 % - some special cases which simply haven't been added to the LUA
550 % parser (yet).
551 % At the time of this writing, this includes
552 % -- arrays created via '{}' and indexed with '[]'
553 % -- strings with "<str>"
554 % -- 'scalar' function
555 % -- hex/octal/binary input
556 \newif\ifpgfluamathusedTeXfallback
557
558 % Parses the math expression and defines \pgfmathresult and
559 % \ifpgfmathunitsdeclared to contain the result.
560 %
561 % If \ifpgfluamathparseractive then the result is also assigned to
562 % \pgfmathresult. Furthermore, if the expression cannot be evaluated (because LUA does not support
563 % it), it will be evaluated by mean of TeX as fallback.
564 %
565 % @see \ifpgfluamathusedTeXfallback
566 % @see \ifpgfluamathshowerrormessage
567 \def\pgfluamathparse#1{%
568 \pgfluamathusedTeXfallbackfalse
569 \pgfutil@directlua{pgfluamathparser.texCallParser(
570 "\pgfutil@luaescapestring{#1}",
571 \pgfluamath@outputformat@choice,
572 \ifpgfluamathshowerrormessage true\else false\fi)%
573 }%
574 \ifx\pgfmathresult\pgfutil@empty
575 \ifpgfluamathenableTeXfallback
576 \pgfluamathusedTeXfallbacktrue
577 \pgfluamath@pgfmathparse{#1}%
578 \fi
579 \fi
580 }
581
582 \catcode`\"=\pgfliblua@oldcatcodedoublequote
583 \endinput