There are two things that fail, causing different issues.
First, you need to be aware that TeXcount only parses the TeX code, using heuristic rules to try to distinguish text from macros. However, it does not actually run TeX, so it will not actually run the \forloop
and expand the code it produces. It therefore does not run \input
on the files Hoofdstuk1.tex
, Hoofdstuk2.tex
, etc. This is why it will not process these files.
Next, what it does do with the \input
statement is try to parse the line
\input{Hoofdstuk\arabic{Hoofdstuk}/\arabic{Hoofdstuk}}
purely as it stands, and can't make any sense of it since it is not a file name. In fact, I suspect there is a minor bug here as it seems it fails to match up the curly braces correctly, and ends up with a left over }
, which causes the error message.
The reason the \input
statement within \forloop
is parsed by TeXcount is that TeXcount does not come with a macro handling rule for \forloop
, so the parameters to \forloop
are parsed as text. This can be "fixed" by adding a TeXcount instruction providing a macro handling rule:
%TC:macro \forloop [ignore,ignore,ignore,xx]
Inserting this line at any place prior to the first use of \forloop
will tell TeXcount that it takes four arguments, all of which should be ignored: the xx
rule is just a stronger form of ignore which does a little less in terms of trying to process the contents (not sure if it is really needed or if ignore
would be sufficient in general). All this does is make TeXcount ignore \forloop
and its parameters, and thus prevent the error message.
To actually solve the problem of actually including the Hoofdstuk-files, I think the simplest is to change the texcount
instruction so it includes them. I think this might do the trick if these are the only files on the Hoofdstuk*.tex
form:
\immediate\write18{texcount -inc -incbib -sum main.tex Hoofdstuk*.tex > /tmp/wordcount.tex}
This just tells TeXcount explicitly to include all these files as well.
NB: I haven't actually tested this, and it might need a little tweaking to get it to work the way you want. But I think this is the most viable approach.
If you need to be more specific about the selection of files to include, you could accumulate the list of files you have included in a macro variable, say \filelist
, and then run TeXcount with a command like
\immediate\write18{texcount -inc -incbib -sum main.tex \filelist > /tmp/wordcount.tex}
which is basically the same, except you can be more secure that the files counted are the same as those included in the document.
\input{Hoofdstuk<something>/Hoofdstuk<something>}
using vim? See for example vim.fandom.com/wiki/Making_a_list_of_numbers\file
already contians your path, why don't you use\input{\file}
?