0

I need words from the glossary to be counted in the texcount when they're used in the body of the document.

I have to include a word count in my thesis. I've edited the \quickwordcount{} function to only include the main chapters. But I've noticed it doesn't include words that I've included from the glossary using \gls{} or glossary descriptions I've included using \glsdesc{}. I need those words included in the final count and I can't seem to figure out how to add them. This is my \quickwordcount{} function:

\newcommand{\quickwordcount}[1]{%
  \immediate\write18{texcount -1 -sum -merge -q -inc -template="{hword}" "1 introduction.tex" "2 preparation.tex" "3 implementation.tex" "4 evaluation.tex" "5 conclusion.tex" 6 output.bbl > #1-words.sum}%
  \input{#1-words.sum} words
}

This is a minimal example:

\quickwordcount{}

testing this \gls{TP} \glsdesc{TP}

enter image description here

It's counting "testing this" as two words and then the glossary entry as one and the description as one.

This is due in a couple of days and is really stressing me out. Thanks in advance for any help!

1
  • Just to confirm Simon Dispa's answer: TeXcount cannot do this as it does not expand macros. Any solution involving TeXcount would require some pre- or post-processing of the \gls and \glsdesc to either convert them to something TeXcount could handle, or count the uses separately and add them to the original count. It would likely be easier and less painful to do the counting on the generated document as he suggests. Commented May 2, 2021 at 9:08

1 Answer 1

2

TeXcount doesn't know how to expand macros so it's a dead end. Lets LaTeX do the job.

I propose an alternative procedure. Sometimes headings should not be included in the word count. If this is your case you have to create a version with empty headers.

It might be also wise to suppress hyphenation. See How to prevent LaTeX from hyphenating the entire document?

Start with CountWords.tex (all headers were removed in this MWE). Then open the file CountWords.pdf with ms word (I'm using 2013 version) and summon the Word Count pop-up, by clicking on the bottom left of nn WORDS.

With large documents with figures, tables, footnotes, etc., I do a chapter-by-chapter count to make sure the pdf to docx conversion has been done correctly and everything is accounted for. Do some tests to see if it is really necessary prevent the hyphenation.

Output: CountWords.pdf

p

CountWords.pdf opened with ms word

w

This is the file CountWords.tex used.

%%% CountWords.tex

\documentclass[12pt,a4paper]{article}

\usepackage{glossaries}
\makeglossaries

\newglossaryentry{TP}
    {name={True Positive},  
    description={a case when predicted outcome and actual outcome are both positive},
    text={true positive (TP)}
    }
\setlength{\parindent}{0pt}

%%%% No hyphen https://tex.stackexchange.com/questions/5036/how-to-prevent-latex-from-hyphenating-the-entire-document
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

\begin{document}
    
\thispagestyle{empty} % remove all headers
    
testing this \gls{TP} \glsdesc{TP}

\end{document}

Bonus benefit: you end up having a docx version of your document (some editing may be necessary) sometimes a requirement from the publishing office or your advisor.

Second option: (free) add to chrome the extension Counting Characters. (From https://chrome.google.com/webstore/detail/counting-characters-1-let/gmaddeabdjpmjkghhhhfdkeemfcnknpl/related?hl=en)

Open the pdf file with chrome, select the text, click the right button of the mouse and select “Count Selected Text” option from a menu option. The pop up will show the number of words.

c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .