![如何显示文档中的字数?](https://linux22.com/image/426933/%E5%A6%82%E4%BD%95%E6%98%BE%E7%A4%BA%E6%96%87%E6%A1%A3%E4%B8%AD%E7%9A%84%E5%AD%97%E6%95%B0%EF%BC%9F.png)
我必须为杂志写一篇最多 700 字的小文章。我想在文章末尾添加字数统计。我找到了以下代码这里在 StackExchange 上。但我自己试了一下却不行。不幸的是,我不被允许回复该主题。
\documentclass{article}
\newcommand\wordcount{\input{|"texcount -inc -sum -0 -template={SUM} \jobname.tex"}}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eleifend pulvinar quam, vel suscipit urna tincidunt eget.
This document has \wordcount words.
\end{document}
我收到以下错误:
!LaTeX 错误:未找到文件 `|texcount -inc -sum -0 -template={SUM} test.tex'。
输入 X 退出或继续,或输入新名称。(默认扩展名:tex)
输入文件名:
有人知道发生了什么问题吗?
答案1
\documentclass{article}
\parskip1em\parindent0pt
\immediate\write18{texcount -1 -sum \jobname.tex > wordcount.aux }
\begin{document}
\section*{How to compile this file}
From the command line (The damn buttonless black window): \par
\hfil\texttt{pdflatex --shell-escape \jobname .tex}\par
From your favourite \LaTeX\ editor: \par
\hangindent1em\hangafter0 Edit your editor configuration to enable the option \texttt{--shell-escape} of the \texttt{pdflatex} compiler. You should {\em not} use this option by foreing documents (like this) without know if the source is safe.\par
% This part is not counted
%TC:ignore
Word count = {\bfseries\large \input{wordcount.aux}}
%TC:endignore
\end{document}