6

I search for a package or a script, that can count the number of characters including spaces in my document. I have tried to search for it, and I have found many solutions, that should do this, but I can't get it to work. I'm using Miktex and Texmaker.

\documentclass{report}
\begin{document}
\input{A_File} % This is a file that can contain everything, eq. figures, equations, minpages etc. To make it simple , let 's say that it contains the following text and equation
This is an example
\begin{equation}
2+2=4 \text{A text}
\end{equation}

\end{document}

So the file A_File contains 'This is an example' and 'A text' which should be counted. I now want to count the the number of characters with spaces in my document. As it can be seen there are 4 characters in 'This', 2 in 'is', 2 in 'an', 7 in 'example' and 3 spaces. Furthermore there are 5 characters in ' A text' with 1 space. This gives 24 number of characters including spaces.

The script should then display:

Total number of characters including spaces = 24.

I'm not so good at latex, so I just want a script I can copy and insert, and then it works.

13
  • Welcome to TeX.SX! There's texcount, an external (perl?) script. It's easy to run it under Linux/MacOS, but windows?
    – user31729
    Dec 28, 2015 at 18:57
  • I use windows. How does this 'perl' works. Is it something in Texmaker ? Can you perhaps give an minimal example of the use ?
    – Morten
    Dec 28, 2015 at 19:02
  • perl is a powerful scripting language and the perl binaries must be installed of course to run other perl scripts. I don't know whether texcount is shipped with MikTeX at all, I don't use that stuff
    – user31729
    Dec 28, 2015 at 19:06
  • 1
    Have you seen this question: How to count all characters including spaces?
    – Alenanno
    Dec 28, 2015 at 19:31
  • 1
    TeXcount may be asked to count the number of word or characters, but not including spaces. Count spaces in LaTeX source is rather problematic. How many spaces are in "x<space><space><space><space><space>x" ? One or five? And how many spaces are "x\hspace{5em}x"? And how to now if the space in "this<space>space" will be lost in the pdf, due to a linebreak?
    – Fran
    Dec 28, 2015 at 21:05

1 Answer 1

2

Without counting spaces, probably TeXcount is the best solution. Otherwise, assuming that additional normal spaces characters in the source code can be safely ignored (but not space commands as \quad, including even \\ and \par ...) one solution that could work reasonably for simple documents (not for child documents and text in math mode, sorry) is convert from .tex to .lyx using:

  • LyX menu : File > ImportFile > LaTeX (plain) ...

  • tex2lyx directly (e.g, at the system prompt type tex2lyx -c report test.tex test.lyx, and next lyx test.lyx).

Then, simply ask for the statistics in LyX Tools > Statitistics...

Example:

Source code test.tex:

\documentclass{report}
\begin{document}
This is an example.
This is a file that can contain everything, eq. figures, equations, minpages etc. To make it simple , let 's say that it contains the following text and equation
\begin{equation}
2+2=4 \text{A text}
\end{equation}
\end{document}

Result:

mwe

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.