57

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.

51

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

| improve this answer | |
  • 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 '15 at 9:02
  • 1
    -1 As the OP mentioned, this seems to count "phrases" not words. – LondonRob May 20 '15 at 15:40
  • 2
    In the second drop down box set maximum words per phrase: to 1 (I think this is default) then phrase = word. – James Owers Sep 1 '15 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) – James Owers Sep 1 '15 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 '15 at 8:57
5

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
      Content:

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

    • Linux: count_pdf_words.sh
      Content:

      #!/bin/bash
      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
| improve this answer | |
  • It is a "typo" :-) Good remark, thank you very much. I change the post accordingly. – keocra Nov 1 '17 at 13:04
  • 1
    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 – raffaem May 24 '19 at 10:37
0

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

$file=$args[0]
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.