diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex | 231 |
1 files changed, 138 insertions, 93 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex b/Master/texmf-dist/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex index 1d7a5227dd6..c559a0cc1ba 100644 --- a/Master/texmf-dist/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex @@ -8,7 +8,7 @@ % % See the file doc/generic/pgf/licenses/LICENSE for more details. % -% $Id: pgflibraryluamath.code.tex,v 1.20 2015/06/05 06:23:21 cfeuersaenger Exp $ +% $Id$ % % % This is a library for a LUA math parser and LUA math operations. @@ -76,49 +76,70 @@ % Patch some configuration macros such that the modifications are % available in LUA as well: \pgfkeys{ - /pgf/trig format/deg/.add code={}{\directlua{pgfluamathfunctions.setTrigFormat("deg")}\aftergroup\pgfmath@settrigformat}, - /pgf/trig format/rad/.add code={}{\directlua{pgfluamathfunctions.setTrigFormat("rad")}\aftergroup\pgfmath@settrigformat}, + /pgf/trig format/deg/.add code={}{\directlua{pgfluamathfunctions.setTrigFormat("deg")}\aftergroup\pgfmath@settrigformat}, + /pgf/trig format/rad/.add code={}{\directlua{pgfluamathfunctions.setTrigFormat("rad")}\aftergroup\pgfmath@settrigformat}, } % ... and reactivate the key: \pgfmathiftrigonometricusesdeg{% - \pgfkeys{/pgf/trig format/deg}% + \pgfkeys{/pgf/trig format/deg}% }{% - \pgfkeys{/pgf/trig format/rad}% + \pgfkeys{/pgf/trig format/rad}% }% % re-activates the current trig format. This is important after a TeX % group has been closed. \def\pgfmath@settrigformat{% - \pgfmathiftrigonometricusesdeg{% - \directlua{pgfluamathfunctions.setTrigFormat("deg")}% - }{% - \directlua{pgfluamathfunctions.setTrigFormat("rad")}% - }% + \pgfmathiftrigonometricusesdeg{% + \directlua{pgfluamathfunctions.setTrigFormat("deg")}% + }{% + \directlua{pgfluamathfunctions.setTrigFormat("rad")}% + }% }% \let\pgfmathsetseed@pgfbasic = \pgfmathsetseed \def\pgfmathsetseed#1{% - \pgfmathsetseed@pgfbasic{#1}% - \directlua{pgfluamathfunctions.setRandomSeed(pgfluamathfunctions.tonumber("\pgfmathresult"))}% + \pgfmathsetseed@pgfbasic{#1}% + \directlua{pgfluamathfunctions.setRandomSeed(pgfluamathfunctions.tonumber("\pgfmathresult"))}% }% % Patch 'declare function' such that it communicates the function % directly to LUA. \let\pgfmathnotifynewdeclarefunction@orig=\pgfmathnotifynewdeclarefunction \def\pgfmathnotifynewdeclarefunction#1#2#3{% - \pgfmathnotifynewdeclarefunction@orig{#1}{#2}{#3}% - \directlua{pgfluamathparser.pushLocalExpressionFunction(% - "\pgfutil@luaescapestring{#1}",% - #2,% - "\pgfutil@luaescapestring{#3}")}% - % - % ensure that the local function is removed at the end of the - % scope. To this end, we maintain a stack on the LUA side. - \aftergroup\pgfluamathparse@pop@local@function + \pgfmathnotifynewdeclarefunction@orig{#1}{#2}{#3}% + % + % we have to check if '#3' contains control sequences. + % this is highly tricky as it may contain '#1'... + \begingroup + \toks0={#3}% + \xdef\pgf@marshal@glob{\the\toks0 }% + \endgroup + \pgfutil@command@to@string\pgf@marshal@glob\pgf@marshal + \expandafter\pgfutilifcontainsmacro\expandafter{\pgf@marshal}{% + \def\pgf@temp{1}% + }{% + \def\pgf@temp{0}% + }% + \if1\pgf@temp + % let lua produce an error when evaluating this function -- we cannot possibly expand the macro to its current state: + \directlua{pgfluamathparser.pushLocalExpressionFunction(% + "\pgfutil@luaescapestring{#1}",% + #2,% + "functionMustBeEvaluatedInTeX")}% + \else + \directlua{pgfluamathparser.pushLocalExpressionFunction(% + "\pgfutil@luaescapestring{#1}",% + #2,% + "\pgfutil@luaescapestring{#3}")}% + \fi + % + % ensure that the local function is removed at the end of the + % scope. To this end, we maintain a stack on the LUA side. + \aftergroup\pgfluamathparse@pop@local@function }% \def\pgfluamathparse@pop@local@function{% - \directlua{pgfluamathparser.popLocalExpressionFunction()}% + \directlua{pgfluamathparser.popLocalExpressionFunction()}% }% % End of luatex stuff @@ -147,7 +168,7 @@ % LUA (defined only in TeX) % - some special cases which simply haven't been added to the LUA % parser (yet). -% At the time of this writing, this includes +% At the time of this writing, this includes % -- arrays created via '{}' and indexed with '[]' % -- strings with "<str>" % -- 'scalar' function @@ -163,13 +184,13 @@ \pgfluamath@checkuninstallcmd% \pgfluamath@install% \pgfluamathcomputationactivetrue - \fi} + \fi}% \def\pgfluamath@makecomputationinactive{% \ifpgfluamathcomputationactive \pgfluamath@uninstall% \pgfluamathcomputationactivefalse - \fi} + \fi}% \let\pgfluamath@pgfmathparse\pgfmathparse \def\pgfluamath@makeparseractive{% @@ -177,14 +198,18 @@ \else \let\pgfluamath@pgfmathparse\pgfmathparse \let\pgfmathparse\pgfluamathparse + \let\pgfmath@iftrue=\pgfmathluamath@iftrue \pgfluamathparseractivetrue - \fi} + \fi}% + +\let\pgfmath@iftrue@basic=\pgfmath@iftrue \def\pgfluamath@makeparserinactive{% \ifpgfluamathparseractive \let\pgfmathparse\pgfluamath@pgfmathparse + \let\pgfmath@iftrue=\pgfmath@iftrue@basic \pgfluamathparseractivefalse - \fi} + \fi}% \pgfqkeys{/pgf}{% % Enable lua-side computation of \pgfmathresult @@ -223,23 +248,23 @@ luamath library}% \fi }, - luamath/output format/.is choice, - luamath/output format/fixed/.code= {\def\pgfluamath@outputformat@choice{0}}, - % returns results for use in the FPU - luamath/output format/float/.code= {\def\pgfluamath@outputformat@choice{1}}, - luamath/output format/fixed, - % this is merely useful for debugging purposes, I guess. - luamath/show error message/.is if=pgfluamathshowerrormessage, - luamath/enable TeX fallback/.is choice, - luamath/enable TeX fallback/true/.code={\pgfluamathenableTeXfallbacktrue\pgfluamathshowerrormessagefalse}, - luamath/enable TeX fallback/false/.code={\pgfluamathenableTeXfallbackfalse\pgfluamathshowerrormessagetrue}, - luamath/enable TeX fallback/.default=true, - luamath/enable TeX fallback=true, -} + luamath/output format/.is choice, + luamath/output format/fixed/.code= {\def\pgfluamath@outputformat@choice{0}}, + % returns results for use in the FPU + luamath/output format/float/.code= {\def\pgfluamath@outputformat@choice{1}}, + luamath/output format/fixed, + % this is merely useful for debugging purposes, I guess. + luamath/show error message/.is if=pgfluamathshowerrormessage, + luamath/enable TeX fallback/.is choice, + luamath/enable TeX fallback/true/.code={\pgfluamathenableTeXfallbacktrue\pgfluamathshowerrormessagefalse}, + luamath/enable TeX fallback/false/.code={\pgfluamathenableTeXfallbackfalse\pgfluamathshowerrormessagetrue}, + luamath/enable TeX fallback/.default=true, + luamath/enable TeX fallback=true, +}% \def\pgfluamath@uninstall@appendcmd#1{% \expandafter\gdef\expandafter\pgfluamath@uninstall\expandafter{% - \pgfluamath@uninstall #1}} + \pgfluamath@uninstall #1}}% % If the uninstall command is already assembled, it will skip the % uninstall assemblation. @@ -252,7 +277,7 @@ \def\pgfluamath@uninstall@appendcmd##1{}% \def\pgfluamath@prepareuninstallcmd##1{}% }% -} +}% % This assembles an uninstall command globally ON FIRST USAGE. % See \pgfmathfloat@plots@checkuninstallcmd @@ -262,18 +287,19 @@ \expandafter\gdef\expandafter\pgfluamath@uninstall\expandafter{% \pgfluamath@uninstall \expandafter\let\expandafter#1\csname pgfluamath@backup@\string#1\endcsname}% -} +}% \def\pgfluamath@install@function#1=#2{% \pgfluamath@prepareuninstallcmd{#1}% \let#1=#2% -} +}% \def\pgfluamath@install{% \pgfluamath@install@function\pgfmathadd@=\pgfluamathadd@% \pgfluamath@install@function\pgfmathsubtract@=\pgfluamathsubtract@% \pgfluamath@install@function\pgfmathneg@=\pgfluamathneg@% \pgfluamath@install@function\pgfmathmultiply@=\pgfluamathmultiply@% + \pgfmathfloat@install\pgfmath@iftrue=\pgfmathluamath@iftrue% \pgfluamath@install@function\pgfmathdivide@=\pgfluamathdivide@% % \pgfluamath@install@function\pgfmathdiv@=\pgfluamathdiv@% \pgfluamath@install@function\pgfmathfactorial@=\pgfluamathfactorial@% @@ -349,87 +375,106 @@ % \pgfluamath@install@function@unimplemented{notequal}% \pgfluamath@install@function\pgfmathreciprocal=\pgfluamathreciprocal% \pgfluamath@install@function\pgfpointnormalised=\pgfluamathpointnormalised -} +}% \def\pgfluamathgetresult#1{% - \edef\pgfmathresult{\pgfutil@directlua{tex.print(-1,#1)}}} + \edef\pgfmathresult{\pgfutil@directlua{tex.print(-1,#1)}}}% + +\def\pgfmathluamath@iftrue{% + \if 0\pgfluamath@outputformat@choice + \let\pgfmathluamath@@iftrue@v=\pgfluamathone + \else + \let\pgfmathluamath@@iftrue@v=\pgfluamathfloatone + \fi + \pgfmathluamath@iftrue@ +}% +\def\pgfluamathone{1.0}% +\def\pgfluamathfloatone{1Y1.0e+00]}% +\def\pgfmathluamath@iftrue@#1#2{% + \ifx\pgfmathresult\pgfmathluamath@@iftrue@v + \def\pgfmath@next{#1}% + \else + \def\pgfmath@next{#2}% + \fi + \pgfmath@next +}% \def\pgfluamathpi@{% - \pgfluamathgetresult{pgfluamathfunctions.pi()}} + \pgfluamathgetresult{pgfluamathfunctions.pi()}}% \def\pgfluamathe@{% - \pgfluamathgetresult{pgfluamathfunctions.e()}} + \pgfluamathgetresult{pgfluamathfunctions.e()}}% \def\pgfluamathadd@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.add(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.add(#1,#2)}}% \def\pgfluamathsubtract@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.substract(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.substract(#1,#2)}}% \def\pgfluamathneg@#1{% - \pgfluamathgetresult{pgfluamathfunctions.neg(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.neg(#1)}}% \def\pgfluamathmultiply@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.multiply(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.multiply(#1,#2)}}% \def\pgfluamathdivide@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.divide(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.divide(#1,#2)}}% \def\pgfluamathabs@#1{% - \pgfluamathgetresult{pgfluamathfunctions.abs(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.abs(#1)}}% \def\pgfluamathround@#1{% - \pgfluamathgetresult{pgfluamathfunctions.round(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.round(#1)}}% \def\pgfluamathfloor@#1{% - \pgfluamathgetresult{pgfluamathfunctions.floor(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.floor(#1)}}% \def\pgfluamathceil@#1{% - \pgfluamathgetresult{pgfluamathfunctions.ceil(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.ceil(#1)}}% \def\pgfluamathgcd@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.gcd(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.gcd(#1,#2)}}% \def\pgfluamathisprime@#1{% - \pgfluamathgetresult{pgfluamathfunctions.isprime(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.isprime(#1)}}% \def\pgfluamathmax@#1{% \pgfluamathgetresult{% - math.max(pgfluamathfunctions.split_braces_to_explist("#1"))}} + math.max(pgfluamathfunctions.split_braces_to_explist("#1"))}}% \def\pgfluamathmin@#1{% \pgfluamathgetresult{% - math.min(pgfluamathfunctions.split_braces_to_explist("#1"))}} + math.min(pgfluamathfunctions.split_braces_to_explist("#1"))}}% \def\pgfluamathsin@#1{% - \pgfluamathgetresult{pgfluamathfunctions.Sin(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.Sin(#1)}}% \def\pgfluamathcos@#1{% - \pgfluamathgetresult{pgfluamathfunctions.Cos(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.Cos(#1)}}% \def\pgfluamathtan@#1{% - \pgfluamathgetresult{pgfluamathfunctions.Tan(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.Tan(#1)}}% \def\pgfluamathmod@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.mod(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.mod(#1,#2)}}% \def\pgfluamathMod@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.Mod(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.Mod(#1,#2)}}% \def\pgfluamathrad@#1{% - \pgfluamathgetresult{pgfluamathfunctions.rad(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.rad(#1)}}% \def\pgfluamathdeg@#1{% - \pgfluamathgetresult{pgfluamathfunctions.deg(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.deg(#1)}}% \def\pgfluamathatan@#1{% - \pgfluamathgetresult{pgfluamathfunctions.aTan(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.aTan(#1)}}% \def\pgfluamathatantwo@#1#2{% - \pgfluamathgetresult{pgfluamathfunctions.aTan2(#1,#2)}} + \pgfluamathgetresult{pgfluamathfunctions.aTan2(#1,#2)}}% \def\pgfluamathasin@#1{% - \pgfluamathgetresult{pgfluamathfunctions.aSin(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.aSin(#1)}}% \def\pgfluamathacos@#1{% - \pgfluamathgetresult{pgfluamathfunctions.aCos(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.aCos(#1)}}% \def\pgfluamathcot@#1{% - \pgfluamathgetresult{1/pgfluamathfunctions.Tan(#1)}} + \pgfluamathgetresult{1/pgfluamathfunctions.Tan(#1)}}% \def\pgfluamathsec@#1{% - \pgfluamathgetresult{1/pgfluamathfunctions.Cos(#1)}} + \pgfluamathgetresult{1/pgfluamathfunctions.Cos(#1)}}% \def\pgfluamathcosec@#1{% - \pgfluamathgetresult{1/pgfluamathfunctions.Sin(#1)}} + \pgfluamathgetresult{1/pgfluamathfunctions.Sin(#1)}}% \def\pgfluamathexp@#1{% - \pgfluamathgetresult{pgfluamathfunctions.exp(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.exp(#1)}}% \def\pgfluamathln@#1{% - \pgfluamathgetresult{pgfluamathfunctions.log(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.log(#1)}}% \def\pgfluamathlogten@#1{% - \pgfluamathgetresult{pgfluamathfunctions.log10(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.log10(#1)}}% \def\pgfluamathsqrt@#1{% - \pgfluamathgetresult{pgfluamathfunctions.sqrt(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.sqrt(#1)}}% \def\pgfluamathrnd@{% - \pgfluamathgetresult{pgfluamathfunctions.rnd()}} + \pgfluamathgetresult{pgfluamathfunctions.rnd()}}% \def\pgfluamathrand@{% - \pgfluamathgetresult{pgfluamathfunctions.rand(-1,1)}} + \pgfluamathgetresult{pgfluamathfunctions.rand(-1,1)}}% \def\pgfluamathfactorial@#1{% - \pgfluamathgetresult{pgfluamathfunctions.factorial(#1)}} + \pgfluamathgetresult{pgfluamathfunctions.factorial(#1)}}% \def\pgfluamathreciprocal#1{% - \pgfluamathgetresult{1/#1}} + \pgfluamathgetresult{1/#1}}% % \pgfluamath@install@function\pgfmath@pi=\pgfluamathpi@% % \pgfluamath@install@function\pgfmathpi=\pgfluamathpi@% % \pgfluamath@install@function\pgfmathe@=\pgfluamathe@% @@ -463,7 +508,7 @@ \pgfutil@directlua{% pgfluamathfunctions.pointnormalised(% \pgf@sys@tonumber{\pgf@x},\pgf@sys@tonumber{\pgf@y})}% - \ignorespaces} + \ignorespaces}% % Parser @@ -478,7 +523,7 @@ % LUA (defined only in TeX) % - some special cases which simply haven't been added to the LUA % parser (yet). -% At the time of this writing, this includes +% At the time of this writing, this includes % -- arrays created via '{}' and indexed with '[]' % -- strings with "<str>" % -- 'scalar' function @@ -497,17 +542,17 @@ \def\pgfluamathparse#1{% \pgfluamathusedTeXfallbackfalse \pgfutil@directlua{pgfluamathparser.texCallParser( - "\pgfutil@luaescapestring{#1}", - \pgfluamath@outputformat@choice, - \ifpgfluamathshowerrormessage true\else false\fi)% + "\pgfutil@luaescapestring{#1}", + \pgfluamath@outputformat@choice, + \ifpgfluamathshowerrormessage true\else false\fi)% }% \ifx\pgfmathresult\pgfutil@empty - \ifpgfluamathenableTeXfallback - \pgfluamathusedTeXfallbacktrue - \pgfluamath@pgfmathparse{#1}% - \fi + \ifpgfluamathenableTeXfallback + \pgfluamathusedTeXfallbacktrue + \pgfluamath@pgfmathparse{#1}% + \fi \fi -} +}% \catcode`\"=\pgfliblua@oldcatcodedoublequote \endinput |