LaTeX forum ⇒ GeneralLaTeX word count Topic is solved

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

LaTeX word count

Postby Epideme90 » Sun Apr 29, 2012 6:41 am

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

\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.

User avatar
cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu May 03, 2012 12:31 pm

site moderator & package author

User avatar
Stefan Kottwitz
Site Admin
Posts: 9679
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu May 03, 2012 4:33 pm

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

\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}


wordcount.png
Word count demonstration
wordcount.png (3.93 KiB) Viewed 51249 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

Postby virgo67 » Wed Aug 05, 2015 5:43 pm

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: 4185
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Aug 05, 2015 5:58 pm

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

Postby faisalmustafa » Mon Nov 30, 2015 10:25 pm

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 33079 times

User avatar
Stefan Kottwitz
Site Admin
Posts: 9679
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Nov 30, 2015 10:31 pm

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

Postby faisalmustafa » Mon Nov 30, 2015 10:36 pm

Finally.....

You are a life savior Stefan.

Many thanks.


Return to “General”

Who is online

Users browsing this forum: No registered users and 8 guests