![如何检查 token 是否是宏?](https://linux22.com/image/265209/%E5%A6%82%E4%BD%95%E6%A3%80%E6%9F%A5%20token%20%E6%98%AF%E5%90%A6%E6%98%AF%E5%AE%8F%EF%BC%9F.png)
我正在考虑解析 LaTeX 文档的可能性。我真正需要的是跟踪符号的类别代码。据我所知,TeX 会展开其口中的所有宏并跟踪类别代码的变化而不执行任何操作。是否可以检查下一个标记是否是宏,收集未展开的宏(连同参数),执行它并移动到下一个标记?
答案1
目前还不清楚你想做什么,但是这会检测以下标记是否是宏。它区分\centerline
于5
This is a macro: macro:#1->\line {\hss #1\hss }
This is a not macro: the character 5
纯 TeX 示例(更改\bye
为\stop
LaTeX)
\def\tst{\afterassignment\xtst\let\next= }
\def\xtst{%
\edef\tmp{\meaning\next}%
\expandafter\macrotest\tmp.........\relax
\ifx\tmpb\macrotestmacro
\immediate\write20{This is a macro: \meaning\next}%
\else
\immediate\write20{This is a not macro: \meaning\next}%
\fi
}
\def\macrotest#1#2#3#4#5#6#7\relax{\def\tmpb{#1#2#3#4#5#6}}
\expandafter\macrotest\meaning\macrotest.........\relax
\let\macrotestmacro\tmpb
\tst\centerline
\tst 5
\bye