1

I am currently writing a research essay and was wondering if it is possible to create a function that links a small part of the output of the texcount function to another location in the file, in my case the title page.

Here is a MWE (minimum working example) of my LaTeX file:

\documentclass[12pt,a4paper,footheight=20pt,footsepline,headheight=20pt,headsepline]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{scrlayer-scrpage,xcolor,lastpage,verbatim,moreverb,lmodern,textcomp,tikz,float,pgf,pgfplots,hyperref}

\pgfplotsset{compat=newest}

\ihead{\color{gray} ...} 
\chead{\color{gray} ...} 
\ohead{\color{gray} ...}
\cfoot{\color{gray} \thepage\ of \pageref{LastPage} }

\setcounter{secnumdepth}{3}
\setlength{\headheight}{25pt}

\usepackage{setspace}
\doublespacing

\addtokomafont{headsepline}{\color{gray}} 
\addtokomafont{footsepline}{\color{gray}} 

\immediate\write18{texcount -sum main.tex > wordcount}

\newcommand\wordcount{\verbatiminput{wordcount}}

\title{...} 
\author{...}
\date{\vspace{8cm} 4000 Words in Essay || 500 Words in RPPF}

\begin{document} 

\maketitle
\thispagestyle{empty}
\newpage
\tableofcontents
\newpage
\section{Introduction}

\newpage
\section{...}

\newpage
\section{Conclusion}

\newpage
\begin{thebibliography}{}
    \bibitem{xxx}
    \bibitem{yyy}
\end{thebibliography}

\newpage
\section{RPPF}

\newpage 
\wordcount
\end{document}

I apologize for the unorthodox use of the date function :D

Essentially what I want to do is replace the "500" in the date by a self-updating word count of the RPPF section.

If this is possible please let me know.

Thanks

1

1 Answer 1

0

I could get the total number of words (including section headers) from texcount by modifying the following idea https://app.uio.no/ifi/texcount/faq.html#latexcall (made some modifications to get the number of words, see MWE below).

To extract the words for the specific subsection, I had to rely on a bash script, see below:

#!/bin/bash
awk '/RPPF/ {print $1}' main.all | awk -F+ '{print $1}'

which I called getwords.sh. This provides the words (excluding the word 'RPPF') in the section 'RPPF'.

The file main.all is the output of texcount. You can put everything together into a single script if you want.

See MWE below.

Since the output files are just a single number, I just have included them instead of importing via verbatiminput. However, I created the commands as well if that's what you need.

Hope this helps.

\documentclass[12pt,a4paper]{article}
\usepackage{verbatim}

\immediate\write18{texcount -out=\jobname.all \jobname.tex; ./getwords.sh > \jobname.sec}
\immediate\write18{texcount -out=\jobname.wrd -template="{word}" \jobname.tex }
\newcommand\allcount{\verbatiminput{\jobname.all}}
\newcommand\wordcount{\verbatiminput{\jobname.wrd}}
\newcommand\seccount{\verbatiminput{\jobname.sec}}

\title{A Title} 
\author{An Author}
\date{}

\begin{document} 

\maketitle
\begin{center}
Total number of words: \input{\jobname.wrd}\\
Total number of words in section RFFP: \input{\jobname.sec}
\end{center}
\thispagestyle{empty}
\newpage
\tableofcontents
\newpage

\section{Introduction}
Test

\section{Problem}
Test Test Test 

\section{Conclusion}

\begin{thebibliography}{}
    \bibitem{xxx}
    \bibitem{yyy}
\end{thebibliography}

\section{RPPF}
Test Test Test 

\newpage 
\allcount
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.