String 在Tex数中转换Tex字符串

String 在Tex数中转换Tex字符串,string,numbers,latex,tex,String,Numbers,Latex,Tex,在需要数值的参数中使用自动生成的Tex字符串时出现问题(例如,在ifthenelse比较中)。下面是一个示例代码: \newcommand\testC{123} \ifthenelse{\testC<0}{negative}{positive} % works fine ! \newcommand{\testD}{\luaexec{tex.write("123")}} % write to avoid the print carriage return - produces also 1

在需要数值的参数中使用自动生成的Tex字符串时出现问题(例如,在ifthenelse比较中)。下面是一个示例代码:

\newcommand\testC{123}
\ifthenelse{\testC<0}{negative}{positive} % works fine !

\newcommand{\testD}{\luaexec{tex.write("123")}} % write to avoid the print carriage return - produces also 123 as \testC
\testD % prompt 132 just as \testC "apparently"
\ifthenelse{\testD<0}{negative}{positive} % error "! Missing number, treated as zero"

\newcounter{compteur}
\setcounter{compteur}{\testD} % error "! Missing number, treated as zero"
\ifthenelse{\thecompteur<0}{negative}{positive}
\newcommand\testC{123}

\如果{\testC注意,
\luaexec
(requires
\usepackage{luacode}
)不可扩展,因此它不能用于(Lua)TeX在扩展后需要
的地方

\documentclass{article}
\usepackage{luacode}
\usepackage{ifthen}

\begin{document}

\newcommand\testC{123}
\ifthenelse{\testC<0}{negative}{positive} % works fine !

\newcommand{\testD}{\directlua{tex.sprint("123")}} % write to avoid the print carriage return - p$

\testD % prompt 132 just as \testC "apparently"

\ifthenelse{\testD<0}{negative}{positive} % error "! Missing number, treated as zero"

\newcounter{compteur}
\setcounter{compteur}{\testD} % error "! Missing number, treated as zero"
\ifthenelse{\value{compteur}<0}{negative}{positive}

\end{document}
\documentclass{article}
\usepackage{luacode}
\使用包{ifthen}
\开始{document}
\纽科曼\testC{123}
\如果其他{\testC