2

For a magazine I have to write a small article of max. 700 words. I'd like to have a wordcount at the end. I found the following code here on StackExchange. But when I tried it myself it didn't work. Unfortunately, I'm not allowed to respond to the topic.

\documentclass{article}

\newcommand\wordcount{\input{|"texcount -inc -sum -0 -template={SUM} \jobname.tex"}}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eleifend pulvinar quam, vel suscipit urna tincidunt eget.

This document has \wordcount words.

\end{document}

I get the following Error:

! LaTeX Error: File `|texcount -inc -sum -0 -template={SUM} test.tex' not found .

Type X to quit or to proceed, or enter new name. (Default extension: tex)

Enter file name:

Does anybody knows what is going wrong?

4
  • My guess is that you didn't use the -shell-escape option.
    – campa
    Jan 12, 2021 at 14:15
  • Hi, do you have texcount installed? Are you calling LaTeX with --shell-escape? And BTW, counting the words in LaTeX is quite difficult... the expansion can create much more words than you have in the source!
    – Rmano
    Jan 12, 2021 at 14:16
  • I have no idea what the -shell-escape option means. I downdloaded the texcount zip and unpacked it within the same folder as my test-document. This is sufficient, isn't it? (I'm not quite sure how it all works, but I'm eager to learn.)
    – KenAdams
    Jan 12, 2021 at 14:21
  • For me it is fine to just count the words within a certain section. I don't use any codes within that section. Is there an easier solution for this problem? I'd like to display the words within the same document.
    – KenAdams
    Jan 12, 2021 at 14:24

1 Answer 1

1

mwe

\documentclass{article}
\parskip1em\parindent0pt
\immediate\write18{texcount -1 -sum  \jobname.tex > wordcount.aux }
\begin{document}
\section*{How to compile this file}
From the command line (The damn buttonless  black window): \par
\hfil\texttt{pdflatex --shell-escape  \jobname .tex}\par  
From  your favourite  \LaTeX\ editor: \par
\hangindent1em\hangafter0 Edit your editor configuration to enable the  option \texttt{--shell-escape} of  the \texttt{pdflatex} compiler. You should {\em not} use this option by foreing  documents (like this) without know if the source is safe.\par

% This part is not counted
%TC:ignore 
 Word count = {\bfseries\large \input{wordcount.aux}}
%TC:endignore   
\end{document}

You must log in to answer this question.

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