使用字数统计命令

使用字数统计命令

我发现以下代码行可以向我的 latex 文档添加字数统计,但有人能解释一下它是如何工作的吗?它为 overleaf 中的字数统计提供了不同的计数。

\newcommand\wordcount{
\immediate\write18{texcount -inc -sum -0 -template={SUM} main.tex > count.txt}
\input{count.txt}words}

在此处输入图片描述

答案1

当你\wordcount的文档中有当您运行启用了不受限制的 shell 转义的 LaTeX 引擎时,texcount将会产生一个正在运行的进程。

输出将被写出到count.txt随后输入的文件中。

您可以通过将输出直接传输到 LaTeX 引擎来改进工作:

\documentclass{article}

\newcommand\wordcount{\input{|"texcount -inc -sum -0 -template={SUM} \jobname.tex"}}

\begin{document}

As any dedicated reader can clearly see, the Ideal of
practical reason is a representation of, as far as I know, the things
in themselves; as I have shown elsewhere, the phenomena should only be
used as a canon for our understanding. The paralogisms of practical
reason are what first give rise to the architectonic of practical
reason. As will easily be shown in the next section, reason would
thereby be made to contradict, in view of these considerations, the
Ideal of practical reason, yet the manifold depends on the phenomena.
Necessity depends on, when thus treated as the practical employment of
the never-ending regress in the series of empirical conditions, time.
Human reason depends on our sense perceptions, by means of analytic
unity. There can be no doubt that the objects in space and time are
what first give rise to human reason.

Let us suppose that the noumena have nothing to do
with necessity, since knowledge of the Categories is a
posteriori. Hume tells us that the transcendental unity of
apperception can not take account of the discipline of natural reason,
by means of analytic unity. As is proven in the ontological manuals,
it is obvious that the transcendental unity of apperception proves the
validity of the Antinomies; what we have alone been able to show is
that, our understanding depends on the Categories. It remains a
mystery why the Ideal stands in need of reason. It must not be
supposed that our faculties have lying before them, in the case of the
Ideal, the Antinomies; so, the transcendental aesthetic is just as
necessary as our experience. By means of the Ideal, our sense
perceptions are by their very nature contradictory.

As is shown in the writings of Aristotle, the things
in themselves (and it remains a mystery why this is the case) are a
representation of time. Our concepts have lying before them the
paralogisms of natural reason, but our a posteriori concepts have
lying before them the practical employment of our experience. Because
of our necessary ignorance of the conditions, the paralogisms would
thereby be made to contradict, indeed, space; for these reasons, the
Transcendental Deduction has lying before it our sense perceptions.
(Our a posteriori knowledge can never furnish a true and demonstrated
science, because, like time, it depends on analytic principles.) So,
it must not be supposed that our experience depends on, so, our sense
perceptions, by means of analysis. Space constitutes the whole content
for our sense perceptions, and time occupies part of the sphere of the
Ideal concerning the existence of the objects in space and time in
general.

%TC:ignore
This document has \wordcount words.
%TC:endignore

\end{document}

使用\jobname可以使命令移植到其他文档,而无需使其适应主文件的实际文件名。

标签%TC用于避免texcount计算最后一句话。

使用的选项有哪些texcount

  1. -inc还将计算使用\input或编译的文件\include
  2. -sum只产生单词总数
  3. -0输出末尾不添加换行符
  4. -template={SUM}指定输出仅包含总计

在此处输入图片描述

相关内容