有些字符在纯 TeX 中是活动的(例如~
),有些软件包(例如babel
使其他字符活动"
)是活动的。有没有办法从 TeX 中获取所有活动字符的列表?或者,是否有一个参考列表列出了哪些字符通过常用软件包活动?
类似的字符列表\mathcode
"8000
也很好。
答案1
您可以遍历所有字符,测试每个字符的 catcode。然后只需打印 active/mathactive( \mathcode="8000
) 即可:
\documentclass{article}
\begin{document}
\newcount\currentchar
\currentchar=0
\loop
\ifnum\active=\catcode\currentchar
Character code \number\currentchar, aka ``\texttt{\char\currentchar}'', is active. It's meaning is:\\
\texttt{%
\lccode`\~=\currentchar\lowercase{\meaning~}
}.\par
\else
\ifnum"8000=\mathcode\currentchar
Character code \number\currentchar, aka ``\texttt{\char\currentchar}'', is mathactive. It's meaning is:\\
\texttt{%
\lccode`\~=\currentchar\lowercase{\meaning~}
}.\par
\fi
\fi
\advance \currentchar by 1
\ifnum\currentchar<256
\repeat
\end{document}
这还会尝试输出字符(当然,这只有在该位置有可打印字符时才有效)和定义。您会发现有很多活动字符,大部分来自inputenc
。
对于 XeLaTeX 和 LuaLaTeX 等 Unicode 引擎,您必须256
用"110000
(Unicode 代码点的数量)和"8000
替换"1000000
。因此您得到
\documentclass{article}
\begin{document}
\newcount\currentchar
\currentchar=0
\loop
\ifnum\active=\catcode\currentchar
Character code \number\currentchar, aka ``\texttt{\char\currentchar}'', is active. It's meaning is:\\
\texttt{%
\lccode`\~=\currentchar\lowercase{\meaning~}
}.\par
\else
\ifnum"1000000=\mathcode\currentchar
Character code \number\currentchar, aka ``\texttt{\char\currentchar}'', is mathactive. It's meaning is:\\
\texttt{%
\lccode`\~=\currentchar\lowercase{\meaning~}
}.\par
\fi
\fi
\advance \currentchar by 1
\ifnum\currentchar<"110000
\repeat
\end{document}
这里,inputenc
不需要,所以你只能得到你所期望的(这是 LuaLaTeX,因为 XeTeX 的\mathcode
工作方式略有不同):