Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I count the number of characters in the compiled version of a Latex file? This should include spaces and all of the document (index, footnotes, bibliography etc)

share|improve this question
4  
Have you tried the suggests listed at Is there any way to do a correct word count of a LaTeX document? –  Werner Mar 18 '12 at 15:00
3  
How should maths formulae be counted? E.g., \(\sqrt{\sin(x)}\)? –  Bruno Le Floch Mar 18 '12 at 16:13
    
I actually don't have any formulae in my document, but I guess every character would have to be counted. –  Bob Mar 18 '12 at 19:57
    
The word count question delivered no answers which met my criteria, unfortunately. –  Bob Mar 18 '12 at 20:02
    
I am pretty sure that the wordcount solution in the cited question (the fourth) will deliver what you're looking for. –  krlmlr Mar 21 '12 at 22:09
add comment

5 Answers

up vote 8 down vote accepted
+50

This is probably as much as you can get

pdftotext document.pdf -enc UTF-8 - | wc -m

For DVI files one can use

catdvi -e UTF-8 -s document.dvi | wc -m

(Thanks to Bob for having pointed to the -enc option and to catdvi.)

share|improve this answer
1  
Thanks for your answer. This lead me to the idea to use catdvi. Using catdvi -s document.dvi | wc -m it gives me some good results. pdftotext has some problems reproducing special chars. –  Bob Mar 22 '12 at 21:48
    
Ciao @egreg: where exactly is this command pdftotext... to be typed? –  Abhimanyu Arora Jul 2 '12 at 8:23
    
pdftotext is a program coming with xpdf; how to invoke it depends on the operating system: on Unix systems it's called from the command line. –  egreg Jul 2 '12 at 8:29
    
@egreg:Grazie, I have windows XP, can you tell me please whether it applies in this case as well? And is xpdf to be installed via \usepackage? –  Abhimanyu Arora Jul 2 '12 at 8:31
    
@AbhimanyuArora I can only point to this link –  egreg Jul 2 '12 at 8:37
add comment

A completely different approach would be to use the stdpage package. It creates 'standard pages' of 30 lines with 60 characters each (of course you can change this to different values). This approach results from the time, when people where using typewriters to write the manuscripts they hand in to their publisher. Some publishers still ask for standard pages today and pay per standard page.

The stdpage package allows you to switch between ragged and justified lines and you can turn on/off hyphenation and linenumbers. In the best case, the usage is as simple as adding

\usepackage[linenumbers,lines=30,chars=50,noindent]{stdpage}

to your preamble. As this package changes the linespacing and fonts, you will have to adapt the rest of your preamble (I had to remove a couple of packages). I personally hand in two pdfs: one with standard pages and the second one with the same text but using a nicer font, hyphenation, microtype and so on.

share|improve this answer
add comment

How does detex file.tex | wc -C work for you? detex removes all the tex macros, and wc -C returns the number of characters remaining. This should be a good enough proxy for characters in the output file given that there's no maths.

This obviously won't count things like running headers or other automatically generated text. For that, I guess you'd need to parse the .dvi as Bruno Le Floch suggested in comments.

share|improve this answer
    
I think the right option is a lowercase 'c', i.e. detex file.tex | wc -c, otherwise that works fine for me. –  Tom Aug 28 '12 at 19:49
add comment

If you are using winedt then you can count everything. Following is what I got from a count from a file that included \(\sqrt{\sin(x)}\) and white spaces:

Monday, March 19, 2012 at 14:43

C:\Users\test\minmimal.tex
Mode: TeX

Size:    973  bytes

Words:   25      [10%]
Numbers: 12      [1%]

Spaces:        35         [4%] %<--------------------spaces here
Alpha Chars:   100        [10%]
Numeric Chars: 14         [1%]

Lines:              43
Empty Lines:        1
Max Line Length:    93
Average  Length:    21
Environments:       3

Paragraphs:         43         [41%]
"\" Commands:       37         [52%]
"%" Comments:       6          [19%]

LaTeX Math \(?\):   1          [0%]. %<--------------------Math here.

Winedt is a shareware though.

share|improve this answer
1  
That counts chars in the tex file, not the compiled pdf. I wonder if the dvi could be parsed more easily perhaps? –  Bruno Le Floch Mar 19 '12 at 18:11
    
Thanks for your answer. I'll give it a try, but actually I'm more a Linux user than a Windows user ;-) –  Bob Mar 20 '12 at 8:32
add comment

An easy way to do this would be to select the entire text from the pdf document (ctl+a, ctl+c) and copy this to a txt file(ctl+v). Then you can use wc or other tools on the plain txt file

share|improve this answer
2  
Have you tried this? It will probably fail with hyphenated words and ligatures will be counted wrong. –  Martin Schröder Dec 11 '12 at 7:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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