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
- wordcount.png (3.93 KiB) Viewed 66519 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