Correct word-count of a LaTeX document

前端 未结 9 1189
野的像风
野的像风 2021-01-30 01:37

I\'m currently searching for an application or a script that does a correct word count for a LaTeX document.

Up till now, I have only encountered script

相关标签:
9条回答
  • 2021-01-30 01:54

    For a very basic article class document I just look at the number of matches for a regex to find words. I use Sublime Text, so this method may not work for you in a different editor, but I just hit Ctrl+F (Command+F on Mac) and then, with regex enabled, search for

    (^|\s+|"|((h|f|te){)|\()\w+
    

    which should ignore text declaring a floating environment or captions on figures as well as most kinds of basic equations and \usepackage declarations, while including quotations and parentheticals. It also counts footnotes and \emphasized text and will count \hyperref links as one word. It's not perfect, but it's typically accurate to within a few dozen words or so. You could refine it to work for you, but a script is probably a better solution, since LaTeX source code isn't a regular language. Just thought I'd throw this up here.

    0 讨论(0)
  • 2021-01-30 01:55

    I use the following VIM script:

    function! WC()
        let filename = expand("%")
        let cmd = "detex " . filename . " | wc -w | perl -pe 'chomp; s/ +//;'"
        let result = system(cmd)
        echo result . " words"
    endfunction
    

    … but it doesn’t follow links. This would basically entail parsing the TeX file to get all linked files, wouldn’t it?

    The advantage over the other answers is that it doesn’t have to produce an output file (PDF or PS) to compute the word count so it’s potentially (depending on usage) much more efficient.

    Although icio’s comment is theoretically correct, I found that the above method gives quite accurate estimates for the number of words. For most texts, it’s well within the 5% margin that is used in many assignments.

    0 讨论(0)
  • 2021-01-30 01:57

    To add to @aioobe,

    If you use pdflatex, just do

    pdftops file.pdf
    ps2ascii file.ps|wc -w
    

    I compared this count to the count in Microsoft Word in a 1599 word document (according to Word). pdftotext produced a text with 1700+ words. texcount did not include the references and produced 1088 words. ps2ascii returned 1603 words. 4 more than in Word.

    I say that's a pretty good count. I am not sure where's the 4 word difference, though. :)

    0 讨论(0)
  • 2021-01-30 01:59

    I use texcount. The webpage has a Perl script to download (and a manual).

    It will include tex files that are included (\input or \include) in the document (see -inc), supports macros, and has many other nice features.

    When following included files you will get detail about each separate file as well as a total. For example here is the total output for a 12 page document of mine:

    TOTAL COUNT
    Files: 20
    Words in text: 4188
    Words in headers: 26
    Words in float captions: 404
    Number of headers: 12
    Number of floats: 7
    Number of math inlines: 85
    Number of math displayed: 19
    

    If you're only interested in the total, use the -total argument.

    0 讨论(0)
  • 2021-01-30 02:06

    Overleaf has a word count feature:

    Overleaf v2:

    Overleaf v1:

    0 讨论(0)
  • 2021-01-30 02:09

    In Texmaker interface you can get the word count by right clicking in the PDF preview:

    0 讨论(0)
提交回复
热议问题