# count words in latex files with input

Hi is there something like texcount to count all the words of a latex file including the ones linked by input and include?

Solution for linux as well as for windows are fine for me.

-

TeXcount can include subfiles included by \input, \include or the subfiles package. For this, you need to use the option -inc which will automatically parse the subfiles, or -merge which will merge the included subfiles into the main document.

-
Perfect. Thank you: texcount inhalt.tex -inc -total was exactly what I was looking for. – magu_ Jun 4 '14 at 11:37

Save this script as buildFile.pl and run it with Perl or execute it: buildFile.pl < main.tex > mainTotal.tex. Then you have one TeX document which can use texcount or something else. However, sometimes it is easier to create a pdf and count the words with other tools, like pdftotext <file>.pdf - | wc -w

#!/usr/bin/perl -w
##################################################
# build one main file
# (C) 2005 Herbert Voss
##################################################
#
#use strict;
#
# call with
#
# ./buildFile.pl main.tex > mainTotal.tex
#
# in the mainTotal.tex will be comments all starting
# with %%% which will not be of interest
#

sub p_inc {
$fileName = shift; if ( open (my$file, "$fileName.tex") ) { print "%%%---------- open: ",$fileName, "\n";
while (<$file>) { if ((/^\s*\\include{\s+(\S+)/i) or (/^\s*\\input{\s+(\S+)/i)) { my$include = $1; chomp($include);chop($include); print "%%%%%%%%% jump to ",$include, "\n";
p_inc($include); } else { print unless /^\s*(#|$)/; }
}
print "%%%---------- close: ", $fileName, "\n"; close$file;
} else { print "%%%<===== file does'n exist\n"; }
}
#
@lines = (<>);
for $line (@lines) { next if$line =~ /^\s*(%)/;
if (($line =~ /^\s*\\include{\s*(\S+)/i) or ($line =~ /^\s*\\input{\s*(\S+)/i)) {
my $include =$1;
chomp($include); chop($include);
print "%%%%%%%%%%% jump to ", $include, "\n"; p_inc($include);
} else { print \$line; }
}

-
I didn't know about pdftotext. This works like a charm. It does however also count stuff like toc,tof,... – magu_ Jun 4 '14 at 9:24
@magu_ There are options -f -l for pdftotext, you can give the page range and you can exclude toc, tof etc. by this way. – wipet Jun 4 '14 at 9:52
Herbert. This works. It is a very nice way to characterize also non latex files. However I feel a bit more comfortable with the texcount answer, since it does this natively. But thank you anyway since you made me learn something new. – magu_ Jun 4 '14 at 14:37