The Text Analysis tool in TeXstudio is quite useful, but I seems I can not find a direct and accurate way to obtain the total number of words in the compiled PDF file.

As I understood, this tool counts the phrases in text. Even if set the length each phrase to only one word, I do not get an accurate count in comparison with the word count function in Texmaker.

What do you think?

P.s., I'm using the TeXstudio V2.8.6, MAC.

3 Answers 3


menu: Tools\Analyse Text then: count

From the comments:

In the second drop down box set maximum words per phrase: to 1 (I think this is default) then phrase = word.

Also if you have selected a piece of text, for Source choose Selection

  • 2
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – Symbol 1
    Apr 2, 2015 at 9:02
  • 3
    -1 As the OP mentioned, this seems to count "phrases" not words.
    – LondonRob
    May 20, 2015 at 15:40
  • 5
    In the second drop down box set maximum words per phrase: to 1 (I think this is default) then phrase = word. Sep 1, 2015 at 14:35
  • 2
    Word count is shown under total shown phrases. Slightly unsure as to what text this actually counts though. It looks like it is just paragraph text (i.e. ignores all text within commands e.g. \section{Section heading title} is not included in the count) Sep 1, 2015 at 14:43
  • 1
    For me it works fine. If I have \section{Concluding Remarks}, it is counted as two words - as expected.
    – Mahdi
    Oct 22, 2015 at 8:57

It is possible to do that by using the utilities pdftotext and wc [1]. Integration in texstudio is possible by

  1. Install pdftotext and wc
  2. Create a script

    • Windows: count_pdf_words.bat

      @echo off
      echo Counting words in %1
      echo Result:
      pdftotext %1 - | wc -w

    • Linux: count_pdf_words.sh

      echo Counting words in $1
      echo Result:
      pdftotext $1 - | wc -w

      Make script executable with: chmod +x count_pdf_words.sh

  3. Open texstudio -> Options -> Configure -> Build -> User defined commands -> Add

    • First field: user#:Count words in pdf
    • Second field: <path>/count_pdf_words.<ext> %.pdf
    • Replace # with the actual number of your user command (First field)
    • Replace <path> with the path to the script (Second field)
    • Replace <ext> with the extension of the script (Second field)
  4. Execute the command with:
    texstudio -> Tools -> User -> Count words in pdf
  • It is a "typo" :-) Good remark, thank you very much. I change the post accordingly.
    – keocra
    Nov 1, 2017 at 13:04
  • 2
    Note this also counts 1. Page numbers 2. The title page (the title itself, the date, etc.) 3. Of course references and anything else you have May 24, 2019 at 10:37
  • Important (at least for Linux users): You can search and set your script using the second icon on the right, the one in the middle of 3. This is handy, but ensure to get rid of any double quotes, or it will not work. Otherwise, like a charm ;)
    – runlevel0
    Sep 28, 2022 at 14:39

Adding onto keocra's solution, here is a PowerShell script that works nicely when used the same way on Windows:

If (-not $file) {
    echo "Please provide a file to query"
    exit 1

echo "Counting words in $file"
$result = pdftotext $file - | Measure-Object -Word
$wordCount = $result.Words
echo "Result: $wordCount"

Make sure you prefix the command with either powershell or pwsh in the second (i.e. command) field for your user command, to ensure the script actually runs:

e.g. pwsh "C:\Users\evanjs\scripts\count_pdf_words.ps1" %.pdf

See the Measure-Object documentation for more info on the cmdlet.

Another note: I initially tried using xpdf-utils via Chocolatey, but found that the stdout (-) flag did not work.

While the version of Poppler on Chocolatey seems to be a little outdated, it does output to stdout when given the - flag.

  • Nice to have answers for multiple operating systems. Would be interesting to know if this works on PowerShell Linux too (I assume you know it's multiplatform now).
    – runlevel0
    Sep 28, 2022 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .