
이 질문은 질문에 대한 참조를 가지고 있습니다Lua, Luamplib 및 Mpgraph 오류 mplib 내에서 lua 함수를 사용하려고 합니다. 자세한 코드는 여기에 있습니다.
\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}
lua와 mplib를 혼합하는 데 문제가 있는 것 같습니다. 어디에 문제가 있으며 어떻게 해결할 수 있습니까?
답변1
이 함수를 사용하면 mplib 내에서 Lua에 액세스할 수 있습니다 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}