LaTeX Tips

While teaching somebody how to use LaTeX recently I noticed that my webpage of useful LaTeX tips and links was no longer accessible.

Counting words in LaTeX

You can count the words in a normal text file using the wc command, but if you run this on a LaTeX source file, then it will also count the LaTeX commands as words. One solution is:
sed 's/[a-zA-Z]*//g' file.tex | wc -w
although this will probably give you a false result if you have many mathematical formulæ in your file.

A better alternative might be to use this Perl script which I hacked up whilst writing my PartII dissertation. It strips out the majority of the LaTeX commands, and attempts to understand the difference between commands that contain “text” within the curly brackets (e.g. section headings), commands that have text within the curly brackets that should be ignored (e.g. cite) and commands where everything between begin{} and end{} should be ignored (e.g. equation). You can then pipe the output to wc. stripTex.pl.