在需要数字值的参数中使用自动生成的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}我找不到一种方法从一个字符串转换为一个数字接受算术比较(和其他操作)。
发布于 2015-05-05 21:03:32
请注意,\luaexec (需要\usepackage{luacode})是不可扩展的,因此不能在(Lua)TeX需要扩展后的<number>的地方使用它。
\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}在测试中最好使用\value{compteur}。
https://stackoverflow.com/questions/30050430
复制相似问题