GeneralLaTeX word count

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Epideme90
Posts: 21
Joined: Tue Apr 24, 2012 5:41 pm

LaTeX word count

Post by Epideme90 »

Does anyone know of any simple LaTeX word count packages? I was hoping for something simple along the lines of:

Code: Select all

\usepackage{\somewordcountthing}

TEXT...
\wordcount (to display the number of words in the text)
Preferably: Does not include reference or abstract or any of the tables of contents, figure list, table list, and i think if possible, not the text in captions either.

I'm sure there's probably hundreds of ways of doing it, but i just was hoping for something simple and idiot proof, so far i've just been copy and pasting most of it into openoffice and using it's word count and correcting it about 10% for the various commands and stuff.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

LaTeX word count

Post by Stefan Kottwitz »

A way which I recently used, and which I posted to one of the questions linked by Clemens, further modified:

Code: Select all

\documentclass{article}
\usepackage{xesearch}
\newcounter{words}
\newenvironment{counted}{%
  \setcounter{words}{0}
  \SearchList!{wordcount}{\stepcounter{words}}
    {a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
    n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
  \UndoBoundary{'}
  \SearchOrder{p;}}{%
  \StopSearching}
\newcommand{\fivewords}{five words in a macro}
\begin{document}
\begin{counted}
Here are a few words plus \fivewords\ for a word count demonstration.
\end{counted}

Above were \thewords\ words.
\end{document}
Word count demonstration
Word count demonstration
wordcount.png (3.93 KiB) Viewed 66525 times
It requires XeLaTeX, which modern TeX distributions provide and modern editors such as TeXworks directly support.
This way just uses a counted environment, all words within are counted. As you can see, even words within expanded macros are counted, a hyphenated word is counted as one.

That would be a generall problem: if you would count in a LaTeX source document, you would have to expand contained macros to correctly call the words therein too. That's why there are solutions which firstly compile to PDF or to HTML and count words in the result, or even convert it afterwards to .odt or .doc for counting with a word processor. Stripping LaTeX and TeX code would not be exact.

Stefan
LaTeX.org admin
virgo67
Posts: 3
Joined: Fri Jul 24, 2015 1:14 pm

Re: LaTeX word count

Post by virgo67 »

Hi,
How to include the word count in the table of contents of my thesis? I use report as my document class.
I have a master latex document and separate the chapters and appendices in separate latex files. Thank you.

best regards,
Devi
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

LaTeX word count

Post by Johannes_B »

Can't you just write the command to count the words right after \tableofcontents?

Can you prepare a minimal working example to let us reproduce the issue?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
faisalmustafa
Posts: 2
Joined: Mon Nov 30, 2015 10:13 pm

Re: LaTeX word count

Post by faisalmustafa »

Hi Stefan,

I tried your suggestion but this is what is returned. I am complete beginner of latex, sorry if this question should too "basic"
Attachments
Screen Shot 2015-12-01 at 03.19.31.png
Screen Shot 2015-12-01 at 03.19.31.png (67.87 KiB) Viewed 48355 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Re: LaTeX word count

Post by Stefan Kottwitz »

Hi faisalmustafa,

welcome to the forum!

You need to choose XeLaTeX as compiler in your editor for this feature.

Stefan
LaTeX.org admin
faisalmustafa
Posts: 2
Joined: Mon Nov 30, 2015 10:13 pm

Re: LaTeX word count

Post by faisalmustafa »

Finally.....

You are a life savior Stefan.

Many thanks.
Post Reply