3

I would like to find number of occurrence of specific words in a tex file. For example, I need to find out number of "the" used. It is foolish to just "ctrl+F" to find word by word because I am working with a book.

So, I would like to ask if there are any solutions that any commands or extensions can help like: "The total number of "the" is 2345 in the text." (just like the searching function of web browser, Chrome.)

I have been finding old posts but I have found nothing related to my specific problem. I know "texcount" can help the total number of words but it seems it does not suit my current problem.

Thank you in advance.

Here is my example:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
While psychological knowledge is often applied to the assessment and treatment of mental health problems, it is also directed towards understanding and solving problems in many different spheres of human activity. The majority of psychologists are involved in some kind of therapeutic role, practicing in clinical, counseling, or school settings. Many do scientific research on a wide range of topics related to mental processes and behavior, and typically work in university psychology departments or teach in other academic settings (e.g., medical schools, hospitals). Some are employed in industrial and organizational settings, or in other areas[9] such as human development and aging, sports, health, and the media, as well as in forensic investigation and other aspects of law.
\end{document}

So, is there a simple way to sort out number of "the" used in this short paragraph?

nam
  • 161
  • 1
  • 1
  • 4
  • 1
    Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  May 28 '14 at 03:51
  • @Hupfer Thank you for your comments and I have added an example. – nam May 28 '14 at 03:57
  • The problem is, especially with a word like the, that there might be the \the... commands, also being counted, but happily not in the MWE you provided. Texcount does only count the total number of all words, as far as I know (never used it, shame on me ;-)) –  May 28 '14 at 04:01
  • Using xelatex this is a simple task, but you are using (pdf)latex. – Gonzalo Medina May 28 '14 at 04:02
  • @GonzaloMedina: Perhaps, you could provide the solution for XeLaTeX anyway? –  May 28 '14 at 04:04
  • @ChristianHupfer I added a little example in my answer below; I hope you like Cavafy :) – Gonzalo Medina May 28 '14 at 04:12
  • grep -oc Hence file(s).tex – morbusg May 28 '14 at 05:20
  • TeXcount will give a list of counts per word by adding the -freq option. Does that fulfill your needs? – Einar Rødland May 28 '14 at 10:49
  • You could use a deTeX program, and run the output to a word counter. – wendy.krieger May 28 '14 at 04:57
  • I think the OP wanted to have the word count inside the document, such that the counting value can be typeset (wherever needed). External solutions may be possible but they must change the code or make additions to some helper file, say .aux for example. –  May 28 '14 at 05:23

0 Answers0