为什么公式中的括号没有按要求显示:C=A·(B)

为什么公式中的括号没有按要求显示:C=A·(B)

在此处输入图片描述

\documentclass[paper=A4, 11pt]{scrreprt}
\usepackage{luacode}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{siunitx}
\sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}}

\begin{luacode*}

function A ( F, L, E, I )
      zz = "\\frac{"..F.." \\num{e3} \\cdot "..L.."^3}{"..E.." \\cdot "..I.." \\num{e4}}"
   tex.sprint ( zz )
end

function B ( xi, a, L )
   local beta, zz
   beta = a / L
      zz = "-\\tfrac{1}{2}\\cdot"..beta.."^2\\cdot"..xi.." + "..beta.."\\cdot"..xi..""
   tex.sprint ( zz )
end

function C ( xi, a, L, F, E, I )
      A = A ( F, L, E, I )
      B = B ( xi, a, L )
      zz = ""..A.." \\cdot \\big( "..B.." \\big)"
   tex.sprint ( zz )
end

\end{luacode*}

% Data
\def\L{8000}
\def\a{6000}
\def\XI{0.5}
\def\Fk{70}
\def\youngsmodu{200000}
\def\I{123}
\def\A{\luadirect{tex.print(A(\Fk ,\L ,\youngsmodu ,\I))}}
\def\B{\luadirect{tex.print(B(\XI ,\a ,\L))}}
\def\C{\luadirect{tex.print(C(\XI ,\a ,\L, \Fk ,\youngsmodu ,\I))}}

\begin{document}
\obeylines
$A=\A \\$ \\
$B=\B \\$ \\
$C=\C \\$

\end{document}

答案1

你的函数B不返回 Lua 值,它只是将字符串打印到 tex 的输入缓冲区中,因此

B = B ( xi, a, L )

将 token 打印到 tex 但设置为Bnil,因此你会得到

[\directlua]:17: attempt to concatenate a nil value (global 'B')
stack traceback:
        [\directlua]:17: in function 'C'
        [\directlua]:1: in main chunk.
\luadirect ... { \luacode@maybe@printdbg {#1} #1 }
                                                  
l.46 $C=\C
         \\$
? 

当你连接..


在此处输入图片描述

\documentclass[paper=A4, 11pt]{scrreprt}
\usepackage{luacode}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{siunitx}
\sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}}

\begin{luacode*}

function A ( F, L, E, I )
      return "\\frac{"..F.." \\num{e3} \\cdot "..L.."^3}{"..E.." \\cdot "..I.." \\num{e4}}"
end

function B ( xi, a, L )
   local beta, zz
   beta = a / L
   return "-\\tfrac{1}{2}\\cdot"..beta.."^2\\cdot"..xi.." + "..beta.."\\cdot"..xi..""
end

function C ( xi, a, L, F, E, I )
      AA = A ( F, L, E, I )
      BB = B ( xi, a, L )
      return ""..AA.." \\cdot \\bigl( "..BB.." \\bigr)"
end

\end{luacode*}

% Data
\def\L{8000}
\def\a{6000}
\def\XI{0.5}
\def\Fk{70}
\def\youngsmodu{200000}
\def\I{123}
\def\A{\luadirect{tex.print(A(\Fk ,\L ,\youngsmodu ,\I))}}
\def\B{\luadirect{tex.print(B(\XI ,\a ,\L))}}
\def\C{\luadirect{tex.print(C(\XI ,\a ,\L, \Fk ,\youngsmodu ,\I))}}

\begin{document}
\obeylines
$A=\A \\$ \\
$B=\B \\$ \\
$C=\C \\$

\end{document}

相关内容