在lua中构建Latex / Tex参数(2)

时间:2015-05-06 07:53:33

标签: lua latex tex tikz

Building Lates/Tex arguments in lua相同的问题,案例更为复杂:

第二部分 更合适的型号: 我尝试用lua产品替换绘图参数: 原文:

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[smooth,samples=100,domain=-3.0:2.0] plot(\x,{(\x-1.0)^2.0*(\x+3.0)});
\end{tikzpicture}%

替换为"手册"宏:工作正常

\def\tempD{(\x-1)*(\x-1)*(\x+3)}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[smooth,samples=100,domain=-3.0:2.0] plot(\x,{\tempD}); % works fine
\end{tikzpicture}%

尝试使用lua生成的字符串替换手动宏:仍然有待找到

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
%\draw[smooth,samples=100,domain=-3.0:2.0] plot(\x,{\strfunc??????}); % the correct \strfuncXX is still to be found !
\end{tikzpicture}%

根据egreg的信息找到正确的\strfuncXX的试验:

\def\strfuncA{\luaexec{tex.write("(\\x-1)*(\\x-1)*(\\x+3)")}} % fails in draw, probably because it is not expanded enough as an argument of draw
%\edef\strfuncAA{\luaexec{tex.write("(\\x-1)*(\\x-1)*(\\x+3)")}} % fails because \luaexec non expandable
\def\strfuncB{\directlua{tex.write("(\\x-1)*(\\x-1)*(\\x+3)")}} % fails because \directlua has a problem managing the "\\"
\def\strfuncC{\directlua{tex.write("(x-1)*(x-1)*(x+3)")}}
\edef\strfuncCC{\directlua{tex.write("(x-1)*(x-1)*(x+3)")}} % works fine ... except that we get an expression with xs instead of \xs
\def\strfuncD{\directlua{tex.write("(\string\ x-1)*(\string\ x-1)*(\string\ x+3)")}} % \strfuncD fails (why ?)
%\edef\strfuncDD{\directlua{tex.write("(\string\ x-1)*(\string\ x-1)*(\string\ x+3)")}} % \strfuncD fails so \edef will fail

\luaexec移至\luadirect(或\directlua)会产生强制\x的问题,我必须制作无法解决的问题。

0 个答案:

没有答案