0

I am trying to make an automatic char count with spaces on my report, so that i get a char count on my main mainmatter displayed and one on my appendix. I have looked at Paul Gessler answer (Command for character count including spaces (in overleaf)) but i can't get it to work if i have more files then the main.tex.

So far i have tried just to count the main.tex file but it comes up with an error "Missing number, treated as zero."

% ~~~~~~~~~~~
% Mainmatter - Chapters
% ~~~~~~~~~~~

\mainmatter

\quickwordcount{main} \quickcharcount{main}

There are \thechar characters and approximately \theword spaces. That makes approximately \the\numexpr\theword+\thechar\relax\ characters total.

\include{Chapters/1. INDLEDNING}

\include{Chapters/2. PROBLEMFORMULERING}

\include{Chapters/3. TEORI OG METODE}

\include{Chapters/4. PROJEKTRESULTATER}

\include{Chapters/5. DISKUSSION}

\include{Chapters/6. KONKLUSION}

% ~~~~~~~~~~~ % appendix, billag og referancer % ~~~~~~~~~~~

\pagestyle{empty} \appendix

\include{App, Bil, Bib/appendix} % Appendix A

In my preamble which is put in with \input{preamble} in the beginning i have

 \newread\tmp

\newcommand{\quickcharcount}[1]{% \immediate\write18{texcount -1 -sum -merge -char #1.tex > #1-chars.sum}% \openin\tmp=#1-chars.sum% \read\tmp to \thechar% \closein\tmp% }

\newcommand{\quickwordcount}[1]{% \immediate\write18{texcount -1 -sum -merge #1.tex > #1-words.sum}% \openin\tmp=#1-words.sum% \read\tmp to \theword% \closein\tmp% }

any suggestions?

  • You should check the contents of the two .sum files to see what they contain: each should contain just a single number. However, if texcount produced an error message, the values returned would not be a number which could explain the error message. – Einar Rødland Mar 06 '22 at 15:54
  • Thank you for your answer i made the code a bit shorter
    \immediate\write18{texcount -1 -sum -relaxed -merge  main.tex  > word.sum}
    \newcommand\wordcount{\input{word.sum}}
    \immediate\write18{texcount -1 -sum -relaxed -char -merge  main.tex > char.sum}
    \newcommand\charcount{\input{char.sum}}
    
    There are \charcount characters and \\
    approximately \wordcount spaces. \\
    total \\
    \the\numexpr\charcount+\wordcount\relax
    

    But it seems like it wont treat \charcount and \wordcount like a number that i can add togeather even through they show as numbers above.

    – Mathias Houmøller Mar 07 '22 at 22:27
  • sorry i am not sure hout to check the contents of the two .sum files. – Mathias Houmøller Mar 07 '22 at 22:37

0 Answers0