Is it possible to use LuaLaTeX in \pgfmathdeclarefunction?
I tried with sinh which seems to work in pgfmathsetmacro but not in \pgfmathparse and pgfplots. How should I declare a pgf function with Lua correctly?
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\makeatletter
\pgfmathdeclarefunction{luasinh}{1}{%
\begingroup
\edef\pgfmath@arg{#1}%
\directlua{tex.setdimen("pgfmath@x", math.sinh(\pgfmath@arg) .. "pt")}%
\pgfmath@returnone\pgfmath@x%
\endgroup
}%
\makeatother
\begin{document}
\noindent
Lua: \pgfmathsetmacro\luasinh{luasinh(1)}\luasinh\\
PGF: \pgfmathsetmacro\pgfsinh{sinh(1)}\pgfsinh\\
\begin{tikzpicture}
\begin{axis}
\addplot {sinh(x)};
%\addplot {luasinh(x)}; does not work
\end{axis}
\end{tikzpicture}
\end{document}
I think being able to use Lua in LuaLaTeX when declaring pgf functions could be useful. For example, this question "Erf function in LaTeX" could maybe be answered without calling Gnuplot but simply call math.erf (if this exists?) in \directlua.
pgfplotsuses its own internal number format. Put\typeout{#1}into theluasinhdefinition and you will see stuff like2Y4.5833334e0]at the terminal. Lua has no idea what to do with that. If you can convert this internal format into a 'normal' number\Nthen you can just use\edef\pgfmathresult{\directlua{tex.print("" .. math.sinh(\N))}}followed by\pgfmathsmuggle\pgfmathresult\endgroup. – Mark Wibrow Oct 14 '13 at 12:53