该xparse
包使编写命令更加容易和灵活。该ifthen
包对条件语句也起到同样的作用。是否有类似的数字表达式包?如果它能与 TiKZ 很好地交互就更好了,也就是说在tikzpicture
.
答案1
答案2
使用etoolbox
。
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\isSuccessor}[2]% successor, number
{%
\numdef{\prev}{#1-1}%
#1 is
\ifnumequal{\prev}{#2}{indeed}{not}
the successor of #2.%
}
\begin{document}
\isSuccessor{42}{41}\par
\isSuccessor{43}{41}\par
\isSuccessor{41}{42}
\end{document}
用于pgfmath
数学计算、\edef
变量赋值和ifthen
条件。
\documentclass{article}
\usepackage{ifthen}
\usepackage{pgfmath}
\newcommand{\isSuccessor}[2]
{
\pgfmathparse{int(#1-1)}%
\edef\prev{\pgfmathresult}%
#1 is
\ifthenelse{\prev=#2}{indeed}{not}
the successor of #2.%
}
\begin{document}
\isSuccessor{42}{41}\par
\isSuccessor{43}{41}\par
\isSuccessor{41}{42}
\end{document}
输出就是如上保存的内容。