Penguin
Diff: LatexWordcount
EditPageHistoryDiffInfoLikePages

Differences between version 6 and predecessor to the previous major change of LatexWordcount.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 6 Last edited on Tuesday, August 23, 2005 4:02:13 pm by JohnMcPherson Revert
Older page: version 4 Last edited on Thursday, May 26, 2005 10:08:30 pm by ArthurVanBunningen Revert
@@ -1,4 +1,6 @@
+!!Option 1 - detex  
+  
 If you try to get a wordcount of a latex source file via the shell command 'wc', it will include any macros you have used, and any comments, in the word count. 
  
 A better way is to make use of a tool called [detex|http://www.cs.purdue.edu/homes/trinkle/detex/]. This does a (fairly) good job of stripping out any Latex macros and comments, although it's probably not usable as a .tex -> readable ascii filter (it gets the ordering on included files wrong, for starters). What it does do is automatically include referenced Latex files (at least the ones using \input ), so you don't have to add any numbers. 
  
@@ -29,13 +31,36 @@
 </verbatim> 
  
 A noticeable difference! 
  
--------------------------  
+<tt>detex</tt> isn't 100% accurate though. It doesn't seem to understand conditionals ( \ifx1 do this \else do that \fi) or arguments that aren't part of the content (like \usepackage{hyperref}).  
  
+----  
+  
+!!Option 2 - pdftotext/ps2ascii  
 Alternatively, convert the .tex file to ascii and run through wc: 
  
 <verbatim> 
 $ pdflatex report.tex 
 $ ps2ascii report.pdf | wc -w 
  2003 
 </verbatim> 
+  
+Note that because postscript/pdf is a page description language, this conversion is not completely accurate as it has to heuristically guess where word breaks are. I noticed that this broke some words into two, especially for larger fonts like section headings. Some letter combinations seem to be worse than others... "project" and "object" were consistently broken into "pro ject" and "ob ject". Don't treat the number of words as gospel :)  
+  
+----  
+  
+!!Option 3 - dvi2tty  
+As you can guess from the name, this is designed for rendering a .dvi file to a terminal (or to a file).  
+The disadvantage of this is that you have to be using plain latex instead of pdflatex, so that you can generate a .dvi file. [IMHO] this is a better approach than the previous two because LaTeX has already parsed the source files so it doesn't need to worry about tex/latex commands, but the format still has enough information to keep words intact (except where TeX has hyphenated words at the margin).  
+<verbatim>  
+# -w100 means format for 100 chars wide  
+# perl to remove punctuation so wc doesn't count them  
+# and remove hyphenation at the end of lines  
+dvi2tty -w100 /path/to/file.dvi \  
+ | perl -pe 's/-$// || s/$/ /; chomp; s/[-\._|]//g' | wc -w  
+</verbatim>  
+  
+  
+You want the <tt>dvi2tty</tt> package in Debian Sarge,  
+dev-tex/dvi2tty in Gentoo, or get it from  
+<tt>ftp://ftp.mesa.nl/pub/dvi2tty/dvi2tty-5.3.1.tar.gz</tt>