4

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).

example.tex

\documentclass[a4paper,11pt]{article}
\begin{document}
The user's home directory is located at:~\input|"echo $HOME"
\end{document}

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
  • 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

4

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

Code:

\documentclass[a4paper,11pt]{article}

\newcommand*{\HomeDir}{%
    \input|"echo $HOME"%
}

\begin{document}
The user's home directory is located at:~\HomeDir
\end{document}

You must log in to answer this question.

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