I want to count the number of characters within a section and then display if that value is below, in, or above the limit. I have grabbed the code from Dynamically count and return number of words in a section. And I have the following (compile it with 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}
The code above doesn't work because \wordcount
is not really a value in LaTeX sense. Is there a way that I can translate to a real value in order for the code to work?
Other solution would be to use Environment that counts words inside, but on that case I would need to save the value of each counter and display it latter.
environ
packageBODY
macro may help.30~GPa
;\upshape next
;minute\ldots\passed
;end\par Beginning
...