将“计算器”软件包中的操作应用于条件数值

发布于 2025-02-07 12:00:00 字数 933 浏览 2 评论 0原文

我正在编写一个类似于电子表格的乳胶模板:一个定义了少量变量,并且整个文档进行了相应的调整。

我有三个变量:<代码>级别,pricitybenusCommuniceScore。这是我的MWE:

\documentclass{article}
\usepackage{ifthen}
\usepackage{calculator}

\begin{document}

\newcommand\Level{3}
\newcommand\ProficiencyBonus{%
\ifthenelse{\Level<5}{2}{3}%
}

\newcommand\AbilityScore{%
\ADD{\ProficiencyBonus}{10}{\TMP}%
\TMP%
}

Level: \Level \\
Proficiency Bonus: \ProficiencyBonus \\
Ability Score: \AbilityScore

\end{document}

此片段在加法过程中产生和错误:

Missing number, treated as zero.
Illegal unit of measure (pt inserted).

我怀疑\ ifthenelse以某种方式不返回“纯”数字(是否有“无形”附加令牌?)。但是,我不知道如何调试这个问题:我尝试使用ifthenelse使用\ show> \ show\含义<含义< /代码>。

我感谢任何解决此问题的帮助,或者向我展示如何调试这种情况。

(我使用Xelatex,但此错误也出现在正常的乳胶中。)

I'm writing a LaTeX template that works similar to a spreadsheet: One defines a small number of variables and the whole document is adjusted accordingly.

I have three variables: Level, ProficiencyBonus and AbilityScore. Here is my MWE:

\documentclass{article}
\usepackage{ifthen}
\usepackage{calculator}

\begin{document}

\newcommand\Level{3}
\newcommand\ProficiencyBonus{%
\ifthenelse{\Level<5}{2}{3}%
}

\newcommand\AbilityScore{%
\ADD{\ProficiencyBonus}{10}{\TMP}%
\TMP%
}

Level: \Level \\
Proficiency Bonus: \ProficiencyBonus \\
Ability Score: \AbilityScore

\end{document}

This snippet produces and error during the addition:

Missing number, treated as zero.
Illegal unit of measure (pt inserted).

I suspect that \ifthenelse somehow doesn't return the "pure" number (are there "invisible" additional tokens?). However, I don't know how to debug this problem: I tried unsuccessfully to gain insight in the return value of \ifthenelse using \show and \meaning.

I'd appreciate any help that either solves this problem or shows me how to debug such a situation.

(I use XeLaTeX but this error appears also with normal LaTeX.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2025-02-14 12:00:00

您可以使用\ ifnum进行测试:

\documentclass{article}
\usepackage{ifthen}
\usepackage{calculator}

\begin{document}

\newcommand\Level{3}
\newcommand\ProficiencyBonus{%
\ifnum\Level<5
  2
\else
  3
\fi
}

\newcommand\AbilityScore{%
\ADD{\ProficiencyBonus}{10}{\TMP}%
\TMP%
}

Level: \Level \\
Proficiency Bonus: \ProficiencyBonus \\
Ability Score: \AbilityScore

\end{document}

You can use \ifnum for your test:

\documentclass{article}
\usepackage{ifthen}
\usepackage{calculator}

\begin{document}

\newcommand\Level{3}
\newcommand\ProficiencyBonus{%
\ifnum\Level<5
  2
\else
  3
\fi
}

\newcommand\AbilityScore{%
\ADD{\ProficiencyBonus}{10}{\TMP}%
\TMP%
}

Level: \Level \\
Proficiency Bonus: \ProficiencyBonus \\
Ability Score: \AbilityScore

\end{document}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文