
Diese Frage bezieht sich auf die FrageFehler mit Lua, Luamplib und Mpgraph Ich versuche, Lua-Funktionen in mplib zu verwenden. Der detaillierte Code ist hier.
\documentclass{article}
\usepackage{luacode}
\usepackage{luamplib}
\begin{document}
\begin{luacode}
require("math")
local sin=math.sin;
\end{luacode}
\def\plot{%
\directlua{
luamplib.process_mplibcode([[
input graph ;
beginfig(0)
draw begingraph(5cm,3cm)
gdraw (0,sin(0)) for x = 1 upto 3: .. (x, sin(x)) endfor ;
endgraph ;
endfig ;
]])}%
}
\plot
\end{document}
Es scheint ein Problem mit der Vermischung von Lua und MPlib zu geben. Wo liegt das Problem und wie kann es behoben werden?
Antwort1
Sie können mithilfe der Funktion von mplib aus auf Lua zugreifen runscript
.
\documentclass{article}
\usepackage{luamplib}
\begin{document}
\def\plot{%
\directlua{luamplib.process_mplibcode([[
vardef sin primary x =
runscript("mp.print(math.sin(" & decimal x & "))")
enddef ;
input graph ;
beginfig(0)
draw begingraph(5cm,3cm)
gdraw (0,sin(0)) for x = 1 upto 3: .. (x, sin(x)) endfor ;
endgraph ;
endfig ;
]])}%
}
\plot
\end{document}