섹션의 문자 수를 세고 범위를 확인하세요.

섹션의 문자 수를 세고 범위를 확인하세요.

섹션 내의 문자 수를 계산한 다음 해당 값이 한도 미만인지, 범위 내인지, 초과하는지 표시하고 싶습니다. 나는에서 코드를 가져왔다섹션의 단어 수를 동적으로 계산하고 반환합니다.. 그리고 나는 다음을 가지고 있습니다 (로 컴파일하십시오 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

관련 정보