计算结果不被识别为值

计算结果不被识别为值

在下面的代码中应该检查 treq 是否<t。

在测试 1 中,treq 指定为 2.93。条件 treq<t 得到满足并变为蓝色(或红色)。\ifthenelse 条件正常工作。

在测试 2 中,xreq 是使用公式计算的。 \ifthenelse 条件不起作用?!这里出了什么问题?

提前感谢您的回复。

\documentclass[12pt,a4paper]{article}
\usepackage{luacode}
\usepackage{ifthen}
\usepackage{xcolor}

\begin{luacode}
    t  = 3
    s  = 454
    p  = 4.51
    k  = 0.00394
    w  = 7.04
    a  = 1.5
\end{luacode}

\begin{luacode*}
    sqrt = math.sqrt

    treq = function (t, s, p, k, w, a) 
            return k *s * sqrt(p / w) + a 
    end

    print = function (d,s) 
        if d == 0 then
         format = "%d"
        else
         format = "%." .. d .. "f"
        end
        tex.sprint(string.format(format,s));
    end
\end{luacode*}

\def\luaprint#1{\directlua{tex.print(#1)}}
\newcommand{\lp}[2][16]{\directlua{print(#1,#2)}}

\begin{document}
%===========================
% CALCULATION WITH CONDITION
% treq is specified here
%===========================
\section{Test 1}
\def\t{\luaprint{t}}
\def\treq{2.93}

t = \t \\

treq = \treq \\

The plating t is to be not less in thickness than treq =\treq

\ifthenelse{\lengthtest{\treq pt < \t pt}}
{{\color{blue}treq < t}}
{{\color{red}treq > t}}

\bigskip

%===========================
% CALCULATION WITH CONDITION
% xreq is calculated. Why is xreq not recognized as value 2.93 ?????
%===========================
\section{Test 2}
\def\xreq{
\lp[2]{treq(\luaprint{t}, \luaprint{s}, \luaprint{p}, \luaprint{k}, \luaprint{w}, \luaprint{a})}
}

t = \t \\

treq = \xreq \\

The plating t is to be not less in thickness than treq =\xreq

\ifthenelse{\lengthtest{\xreq pt < \t pt}}
{{\color{blue}xreq < t}}
{{\color{red}xreq > t}}

\end{document}

相关内容