I have a problem trying to invoke texcount from LaTeX file. I am using MacOS with MacTeX 2018 installed. texcount comes directly with the MacTeX and it is on the PATH. When I run texcount on command line, it works great. However, when I try to include it in the tex file, I get an error saying:

"sh: texcount: command not found system returned with code 32512".

I have --enable-write18 --shell-escape enabled and I use variety of other shell commands that work like charm on my TeX distribution. Just to verify, I have tried to execute pstopdf from LaTeX to see if it works and it is working great. I don't understand why only texcount doesn't work.

If anyone could throw me some light on what could be the possible problem, that would be great. This is the sample code I am working with:


    \immediate\write18{texcount -sum -1 \jobname.tex -out=count.txt}%

  • It sounds as though the PATH isn’t being passed. Try using the full path to the command: /Library/TeX/texbin/texcount. PS: just use —shell-escape the other is redundant. – Herb Schulz Feb 16 '19 at 21:12
  • Great! It works with full PATH. For example, when I checked pstopdf, it worked and I see pstopdf is at /usr/bin/pstopdf. Apparently, texcount is at different PATH. How can I make sure that LateX always looks at correct PATH? – MahiPai Feb 16 '19 at 22:35
  • No problem with my MacTeX. – egreg Feb 17 '19 at 0:25
  • @MahiPai : are you playing with the PATH variable in your .profile or somewhere else or is it the standard set by MacTeX? What do you get for the PATH when you run echo $PATH in Terminal? – Herb Schulz Feb 18 '19 at 0:30
  • 3
    I'm voting to close this question as off-topic because it is already solved. – user156344 Feb 27 '19 at 13:20