0

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!

1 Answer 1

2

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.

5
  • %TC:subst \markdownInput \input did the trick for me. Thank you very much, Einar. In terms of accuracy and processing the code, the results look good enough for my purposes.
    – woerndl
    May 1, 2022 at 17:09
  • @woerndl, what went wrong with the fileinclude instruction? When I tested it on the latest version of TeXcount, it worked fine on my side. May 1, 2022 at 18:16
  • It threw a Invalid %TC:fileinclude parameter: input but maybe I did get the syntax wrong. It also tried various ways like subdir,myfile.txt instead of input. I have no controll over -inc or -merge, since I'm on Overleaf – if that's relevant.
    – woerndl
    May 1, 2022 at 18:36
  • 1
    @woerndl, Thank you for the details on the error. I'll need to check what may be happening here: there's a regex test that fails for no apparent reason, but maybe I have written some code there that has undefined behaviour and different Perl version handle differently. May 1, 2022 at 19:09
  • I thank you. Gladly – let me know if I can be of service.
    – woerndl
    May 1, 2022 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .