我正在使用在 stackexchange 上找到的一些代码来计算 LaTeX 文档中的单词数。我在 Mac 上使用 TeXLive,并使用 XeLateX 来生成 pdf 文档。它生成了一个 pdf,但带有错误消息,较长的文档无法生成正确的 pdf。
这是一个最简单的文档:
\documentclass{article}
\usepackage{xesearch}
\newcounter{words}
\newenvironment{wordcount}{%
\setcounter{words}{0}
\SearchList!{wordcount}{\stepcounter{words}}
{a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
\UndoBoundary{'’-}
\MakeBoundary{„“‚‘–}
\SearchOrder{p;}}{%
\StopSearching}
\begin{document}
\begin{wordcount}
Here are some words.
Here are some more words.
\end{wordcount}
\end{document}
错误信息如下:
! Undefined control sequence.
<XeTeXinterchartoks> \xdef \xs@String {\xs@String
e}
l.20 Her
e are some words.
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
我有 XeTeX 版本 3.14159265-2.6-0.99996 (TeX Live 2016),以及 TeXLive 实用程序中可用的最新 xesearch 版本 (0.1)。当我使用 Tex Live 2014 版本时,它运行良好,但现在更新了很多东西,我不知道从哪里开始找出问题所在。
答案1
XeTeX 的最新版本将字符类的数量增加到 4096,但xesearch
仍然假设上限是 255,而不是 4095。
您必须重新进行初始化。
\documentclass{article}
\usepackage{xesearch}
\makeatletter
\chardef\xs@NatDel=\e@alloc@intercharclass@top
\chardef\xs@lrDel=\numexpr\e@alloc@intercharclass@top-1\relax
\chardef\xs@Classes=\numexpr\e@alloc@intercharclass@top-2\relax
\XeTeXinterchartoks\xs@lrDel\xs@Classless={\xs@LearnLetter}
\XeTeXinterchartoks\xs@NatDel\xs@Classless={\xs@LearnLetter}
\XeTeXinterchartoks\xs@NatDel\xs@lrDel{\xs@EndString}
\xs@MakeDel\{\}.,;:!?[()]-'`\xs@end
\makeatother
\newcounter{words}
\newenvironment{wordcount}{%
\setcounter{words}{0}
\SearchList!{wordcount}{\stepcounter{words}}
{a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
\UndoBoundary{'’-}
\MakeBoundary{„“‚‘–}
\SearchOrder{p;}}{%
\StopSearching}
\begin{document}
\begin{wordcount}
Here are some words.
Here are some more words.
\end{wordcount}
Number of words: \thewords
\end{document}
如果发现\e@alloc@intercharclass@top
未定义,请更新您的 TeX 发行版。