I can't get TeXcount to perform a word count on a LaTeX document that runs a Linux shell command to access a shell variable (i.e. the command involves a "$" dollar symbol).


The user's home directory is located at:~\input|"echo $HOME"

This sucessfully compiles with pdflatex --shell-escape example.tex and gives me the location of my home directory. However, running texcount example.tex fails because "$" is a special character in LaTeX and they usually come in pairs.

If I escape the "$" using a backslash (i.e. \$) then TeXcount runs fine but the PDF produced by pdflatex now contains the literal string "$HOME" instead of the location of my home directory.

Is there a way to hide the "$" from TeXcount without hiding it from the shell? (Or could this be a bug in TeXcount?)

  • 1
    Peter Grill has already given a good solution to this: to put it into a macro. I personally also think the code becomes cleaner this way. It also allows you to specify how you want this macro to be counted. Although the $ sign causes the immediate problem, the underlying problem is that TeXcount will try to interpret \input as a file inclusion macro. Jan 10, 2015 at 12:55

1 Answer 1


It seems that if you move the offending material into a macro it works fine:

enter image description here

File: count.tex
Encoding: ascii
Words in text: 7
Words in headers: 0
Words outside text (captions, etc.): 0
Number of headers: 0
Number of floats/tables/figures: 0
Number of math inlines: 0
Number of math displayed: 0



    \input|"echo $HOME"%

The user's home directory is located at:~\HomeDir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.