Counting words with TeXcount in documents using \markdownInput or \verbatiminput

markdownoverleaftexcountverbatimword count

I'm using \markdownInput (via the markdown package) to include Markdown files in a paper on Overleaf. Overleaf uses the TeXcount utility to count the words. But TeXcount doesn't recognize \markdownInput (or \verbatiminput for that matter).

A minimal working example would be:

\documentclass{article}
\usepackage{markdown}
\usepackage{verbatim}

\begin{document}

% Both inputs won't get counted by TeXcount
\markdownInput{example.txt}
\verbatiminput{example.txt}

\end{document}

With example.txt containing some markdown to test. The word count shown by Overleaf will be 2 in this case. While it would be 2 + the wordcount of the .txt-file if you would add \input{example.txt}.

I've tried using a comment environment \begin{comment} around or something like \phantom and just add the .txt files in addition via \input but I couldn't come up with a good solution.

I'm aware that TeXcount offers a file include option in the form of %TC:fileinclude \input input (manual page 20) but couldn't get that to work either. My current (subpar and temporary) solution was to switch to \input count the words and then switch back to \markdownInput, but a real solution would be great. Especially because I would like to use %TC:ignore inside the markdown files to exclude text that shouldn't be counted.

Any help and suggestions on how to go it in a smart way that doesn't produce warnings and maybe can stay in the document would be highly appreciated!

Best Answer

It should work to include the line

%TC:fileinclude \markdownInput input

which tells TeXcount the \markdownInput should be processed the same way as \input. There are other file inclusion rules than input which may be appropriate if the file is not found, but that would have been reported and thus does not seem to be the issue in your case.

You will need to run TeXcount with either the -inc or -merge option in order to process included files: these will either process included files separately, or merged into the main document.

If you still have problems with this, an alternative to manually replacing the macro with \input when running TeXcount is to have TeXcount do the replacement by inserting the TeXcount instruction

%TC:subst \markdownInput \input

which does a simple text replacement, including in the output.

However, I would not be too confident about having TeXcount processing verbatim or markdown code. Special characters may cause problems, so make sure you inspect the verbose output to verify how the text is being parsed.

Related Question