一开始我有点困惑,不知道它是如何\romannumeral
工作的。然后我尝试了几次实验,测试了将数字合并到 LaTeX 中的各种方法,结果我更加困惑了。
下表总结了我的一些实验。
\documentclass{article}
\newcounter{mycounter}
\setcounter{mycounter}{8}
\def\mynumber{8}
\begin{document}
\begin{tabular}{cll}
behavior & Code & reults in: \\\hline
as expected & \verb!\ifnum20<\mynumber 2 small\else large\fi! & \ifnum20<\mynumber 2 small\else large\fi \\
as expected & \verb!\romannumeral82! & \romannumeral82 \\
as expected & \verb!\romannumeral\mynumber 2! & \romannumeral\mynumber 2 \\
as expected & \verb!\ifnum20<\number\mynumber2 small \else large\fi! & \ifnum20<\number\mynumber2 small \else large\fi \\
unexpected & \verb!\romannumeral\value{mycounter}2! & \romannumeral\value{mycounter}2 \\
unexpected & \verb!\ifnum1<\value{mycounter}2 small\else large\fi! & \ifnum1<\value{mycounter}2 small\else large\fi \\
unexpected & \verb!\ifnum20<\value{mycounter}2 small\else large\fi! & \ifnum20<\value{mycounter}2 small\else large\fi \\
unexpected & \verb!\ifnum100<\number`Q2 small \else large\fi! & \ifnum100<\number`Q2 small \else large\fi \\
unexpected & \verb!\ifnum100<`Q2 small \else large\fi! & \ifnum100<`Q2 small \else large \fi \\
\end{tabular}
\end{document}
有人可以解释一下为什么底部的六个例子2
没有被读入作为评估或测试的数字测试的一部分吗?
答案1
反引号语法返回指定字符的字符代码,它使用字符标记和可选空格。它不会构造该数字的十进制表示形式(可能会向该数字添加 2)
反过来\number
做返回十进制扩展
\number\mynumber2
扩展为 82,正如在 ifnum 测试中所见。(\number
实际上并没有做任何事情,因为\mynumber
它本身会扩展为 8)