
セクション内の文字数をカウントし、その値が制限を下回っているか、範囲内か、上回っているかを表示したい。コードは以下から取得しました。セクション内の単語数を動的にカウントして返す. そして、次のようになります ( でコンパイルしますpdflatex --shell-escape mwe.tex
)。
\documentclass{article}
\newcommand{\wordcount}{%
\immediate\write18{texcount -merge -sub=section \jobname.tex | grep "Section" | sed -e 's/+.*//' | sed -n \thesection p > 'count.txt'} \input{count.txt}}
\usepackage{lipsum}
\begin{document}
\section{test1}
\wordcount
\ifnum\wordcount<1000 Below
\ifnum\worcount>2000 Above
\else Inside
foo bar
\section{test2}
\wordcount
foo bar
foo bar
foo bar
\end{document}
上記のコードは、\wordcount
LaTeX の意味では実際には値ではないため機能しません。コードを機能させるために、実際の値に変換する方法はありますか?
他の解決策としては、内部の単語を数える環境ただし、その場合は各カウンターの値を保存し、後で表示する必要があります。
答え1
PerlスクリプトTeXcount(http://app.uio.no/ifi/texcount/) は、TeX ドキュメントの単語数をセクションごとに表示します。以下に例を示します。.tex ファイルを省略し、-help フラグを追加して、さまざまなオプションを確認することもできます。
$ perl texcount.pl paper.tex
File: paper.tex
Encoding: ascii
Words in text: 5824
Words in headers: 22
Words outside text (captions, etc.): 1032
Number of headers: 8
Number of floats/tables/figures: 18
Number of math inlines: 48
Number of math displayed: 0
Subcounts:
text+headers+captions (#headers/#floats/#inlines/#displayed)
90+12+0 (1/0/6/0) _top_
162+1+0 (1/0/1/0) Section: Abstract
751+1+0 (1/0/1/0) Section: Introduction
795+1+0 (1/0/6/0) Section: Methods
3964+2+0 (1/0/20/0) Section: Results \& Discussion
44+1+0 (1/0/0/0) Section: Acknowledgments
0+2+320 (1/9/0/0) Section: Table Legends
18+2+712 (1/9/14/0) Section: Figure Legends