TeXcount is your friend. It is a perl script for counting words in LaTeX documents. Although the ouput is a separate plain text file, you can include easily verbatim in the own LaTeX document without modify the result, because you can count any arbitrary chunks of text and avoid some parts using the pseudoenvironment comments %TC:ignore ... %TC:endignore
. Moreover, you can obtain subcounts at some section levels and separate counts of words for main text, headers, captions, inlined math and displayed math (and more, although this is out of the question. Run texdoc texcount
for more information).

\documentclass{article}
\usepackage{moreverb,savetrees}
% Compile with --enable-write18 or --shell-escape options
\immediate\write18{texcount -tex -sum \jobname.tex > /tmp/wordcount.tex}
\begin{document}
\section[Count-me]{Count me}
This section is counted. The quick brown fox jumps over the lazy dog.
%TC:ignore
\section{Ignore me}
A litle ignored text in the count.
%TC:endignore
\subsection{This is a subsection}
And some text with inline math ($E=mc^2$).
\subsection{And this is another subsection}
And some more text with display math \[E=mc^2\]
\subsection{One more subsection with a float}
This part of the text include one figure float.
\begin{figure}[h!]
\centering\rule{1cm}{1cm}\caption{A nice black box.}
\end{figure}
%TC:ignore
\subsubsection*{Counts of words}
\verbatiminput{/tmp/wordcount}
%TC:endignore
\end{document}
To count characters instead of words, add simply the -char
option after texcount
:

wc
.