作业(甚至论文)通常都有字数限制。使用 Word 时这不是什么大问题,但我不知道如何使用 LaTeX 来实现这一点。到目前为止,我的解决方案是编译文档,然后对我的 pdf 文件进行粗略的字数统计,有时甚至复制 pdf 文件的内容并粘贴到 Word 中以获得大致正确的字数。
是否有任何工具(甚至是网上工具)、包、脚本或软件可以直接从我的 .tex 文档中执行此操作并仍然获得正确的字数(即忽略命令、方程式等)?
答案1
这是在 TeX FAQ 中.建议的解决方案是:
德特克斯文件名(尝试剥离 LaTeX 命令),然后使用任何字数统计工具。(例如
wc
)latexcount.pl,一个用于字数统计的 Perl 脚本
字数,其中有一个脚本,可以使用一些设置来运行 LaTeX,然后计算日志文件中的单词指示数。
答案2
答案3
下面是我的一段摘录.vimrc
,它能让我轻松地在 Vim 中进行字数统计:
function! WC()
let filename = expand("%")
let cmd = "detex " . filename . " | wc -w | tr -d '[:space:]'"
let result = system(cmd)
echo result . " words"
endfunction
command WC call WC()
现在我可以:WC
在命令模式下调用,让字数显示在状态行中。
答案4
您可以texcount
在自己的 LaTeX 文档中获得结果:
请注意,此 MWE 需要文件名 borra.tex
(或相应地修改代码)。
% CAUTION !!!
% 1) Need --enable-write18 or --shell-escape
% 2) This file MUST be saved
% as "borra.tex" before the compilation
% in your working directory
% 3) This code will write wordcount.tex
% and charcount.tex in /tmp of your disk.
% (Windows users must change this path)
% 4) Do not compile if you are unsure
% of what you are doing.
\documentclass{article}
\usepackage{moreverb} % for verbatim ouput
% Count of words
\immediate\write18{texcount -inc -incbib
-sum borra.tex > /tmp/wordcount.tex}
\newcommand\wordcount{
\verbatiminput{/tmp/wordcount.tex}}
% Count of characters
\immediate\write18{texcount -char -freq
borra.tex > /tmp/charcount.tex}
\newcommand\charcount{
\verbatiminput{/tmp/charcount.tex}}
\begin{document}
\section{Section: text example with a float}
Words and characters of this example file are
automatically counted from the source file
when compiled (therefore generated text as
\textbackslash{}lipsum[1-10] is {\bfseries not}
counted). The results are showed at the end
of the compiled version.
Counts are made in headers, caption floats
and normal text for the whole file. Subcounts
for structured parts (sections, subsections,
etc.) are also made. Number of headers,
floats and math chunks are also counted.
\begin{figure}[h]
\centering
\framebox{This is only a example float}
\caption{This is a example caption}
\end{figure}
\subsection{Subsection: Little text with math chunks}
In line math: $\pi +2 = 2+\pi$ \\
Display math: \[\pi +2 = 2+\pi\]
%TC:ignore
\dotfill End of the example \dotfill
\subsubsection*{Counts of words}
\wordcount
%TC:endignore
\end{document}