动态统计并返回特定章节的字数并打印在一页上

动态统计并返回特定章节的字数并打印在一页上

我正在寻找与此解决方案类似的方法: 动态计算并返回某一部分的字数

但是,我不想在章节开头或结尾打印每个部分的字数统计,而是想在第一页添加每个部分的长度概览。我还想对摘要进行计数(使用 \begin{abstract} 环境)。

我在 Windows 10 上使用 TeXstudio 3.0.1。

有人知道该怎么做吗?

干杯!

答案1

将以下几行添加到你的序言中:

\newcommand\wordcount{%
  \immediate\write18{texcount -sub=section \jobname.tex | egrep 'Section|_top_' | sed -e '1i \\\\begin{verbatim}' -e 's/+.*)//;s/_top_/Abstract/;$a\\\\end{verbatim}' > 'count.tex'}%
}
\wordcount
\AtBeginDocument{\input{count}}

将该选项添加--enable-write18到你的 LaTeX 命令中,例如

pdflatex --enable-write18 mydocument.tex

在此处输入图片描述

\documentclass{article}
\newcommand\wordcount{%
  \immediate\write18{texcount -sub=section \jobname.tex | egrep 'Section|_top_' | sed -e '1i \\\\begin{verbatim}' -e 's/+.*)//;s/_top_/Abstract/;$a\\\\end{verbatim}' > 'count.tex'}%
}
\wordcount
\AtBeginDocument{\input{count}}
\begin{document}

\begin{abstract}
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.
\end{abstract}

\section{Introduction}
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.

\section{Main Stuff}
Even though "lorem ipsum" may arouse curiosity because of its resemblance to classical Latin, it is not intended to have meaning. Where text is comprehensible in a document, people tend to focus on the textual content rather than upon overall presentation, so publishers use lorem ipsum when displaying a typeface or design elements and page layout in order to direct the focus to the publication style and not the meaning of the text. In spite of its basis in Latin, use of lorem ipsum is often referred to as greeking, from the phrase "it's all Greek to me," which indicates that this is not meant to be readable text.

\section{Conclusion}
Today's popular version of lorem ipsum was first created for Aldus Corporation's first desktop publishing program Aldus PageMaker in the mid-1980s for the Apple Macintosh. Art director Laura Perry adapted older forms of the lorem text from typography samples — it was, for example, widely used in Letraset catalogs in the 1960s and 1970s (anecdotes suggest that the original use of the "Lorem ipsum" text was by Letraset, which was used for print layouts by advertising agencies as early as the 1970s.) The text was frequently used in PageMaker templates.

\end{document}

相关内容