首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >转换Tex号中的Tex字符串

转换Tex号中的Tex字符串
EN

Stack Overflow用户
提问于 2015-05-05 10:25:33
回答 1查看 3.8K关注 0票数 3

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

代码语言:javascript
复制
\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}

我找不到一种方法从一个字符串转换为一个数字接受算术比较(和其他操作)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-05 21:03:32

请注意,\luaexec (需要\usepackage{luacode})是不可扩展的,因此不能在(Lua)TeX需要扩展后的<number>的地方使用它。

代码语言:javascript
复制
\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}

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30050430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档