I would like to count the "a" word in a text and put output to the PDF file, eg.
This is a document about processing text in TeX.
The document has a new macro but$a = 10$is not counted,
nor\lstinline{a = 2}
nor\begin{lstlisting}a = 1;\end{lstlisting}
Code should output 2, as "a" is only two times mentioned. I do not want to process math, verbatim or lstlisting.
I have seen the answer for a question Environment that counts words inside and I can count only 'b' letters (not words)
\documentclass{article}
\begingroup
\lccode`\~=`\b%
\lowercase{%
\gdef\assignment{\setcounter{word}{0}%
\catcode`~=\active
\def~{b\stepcounter{word}}}}%
\endgroup
\newcounter{word}
\def\endassignment{\marginpar{\arabic{word} words}}
\begin{document}
\begin{assignment}
Here are some bad words.
\end{assignment}
\end{document}
A problem here is that, when I would like to write word bad in bold using \textbf{bad}, the source code is not compiling.
This question is only half-way. I would like to automatically modify every "a word" to "a~word".
%s/\<\(\w\) \(\w\{3,}\)/\1\~\2/g? – morbusg Feb 17 '14 at 22:39printf("Hello, a very nice example");should stay untouched. – faramir Feb 18 '14 at 01:20