我正在尝试在报告中自动计算带空格的字符数,这样我就可以显示主内容的字符数和附录的字符数。我查看了 Paul Gessler 的回答 (字符计数命令(包括空格) (在背面)),但如果我有比 main.tex 更多的文件,我就无法让它工作。
到目前为止,我只是尝试计算 main.tex 文件,但出现了错误“缺少数字,视为零”。
% ~~~~~~~~~~~
% Mainmatter - Chapters
% ~~~~~~~~~~~
\mainmatter
\quickwordcount{main}
\quickcharcount{main}
There are \thechar characters and approximately \theword spaces.
That makes approximately \the\numexpr\theword+\thechar\relax\ characters total.
\include{Chapters/1. INDLEDNING}
\include{Chapters/2. PROBLEMFORMULERING}
\include{Chapters/3. TEORI OG METODE}
\include{Chapters/4. PROJEKTRESULTATER}
\include{Chapters/5. DISKUSSION}
\include{Chapters/6. KONKLUSION}
% ~~~~~~~~~~~
% appendix, billag og referancer
% ~~~~~~~~~~~
\pagestyle{empty}
\appendix
\include{App, Bil, Bib/appendix} % Appendix A
在我的序言中,开头用 \input{preamble} 插入
\newread\tmp
\newcommand{\quickcharcount}[1]{%
\immediate\write18{texcount -1 -sum -merge -char #1.tex > #1-chars.sum}%
\openin\tmp=#1-chars.sum%
\read\tmp to \thechar%
\closein\tmp%
}
\newcommand{\quickwordcount}[1]{%
\immediate\write18{texcount -1 -sum -merge #1.tex > #1-words.sum}%
\openin\tmp=#1-words.sum%
\read\tmp to \theword%
\closein\tmp%
}
有什么建议么?