1

I am looking for something similar to this solution: Dynamically count and return number of words in a section

However, instead of printing the wordcount for each section at the end or start of a chapter, I would like to add to the first page an overview on how long each section is. I would also like to have a count for the abstract (using \begin{abstract} environment).

I am using TeXstudio 3.0.1 on Windows 10.

Does anyone have an idea how to do that?

Cheers!

1 Answer 1

1

Add the following lines to your preamble:

\newcommand\wordcount{%
  \immediate\write18{texcount -sub=section \jobname.tex | egrep 'Section|_top_' | sed -e '1i \\\\begin{verbatim}' -e 's/+.*)//;s/_top_/Abstract/;$a\\\\end{verbatim}' > 'count.tex'}%
}
\wordcount
\AtBeginDocument{\input{count}}

Add the option --enable-write18 to your LaTeX command, e.g.

pdflatex --enable-write18 mydocument.tex

enter image description here

\documentclass{article}
\newcommand\wordcount{%
  \immediate\write18{texcount -sub=section \jobname.tex | egrep 'Section|_top_' | sed -e '1i \\\\begin{verbatim}' -e 's/+.*)//;s/_top_/Abstract/;$a\\\\end{verbatim}' > 'count.tex'}%
}
\wordcount
\AtBeginDocument{\input{count}}
\begin{document}

\begin{abstract}
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.
\end{abstract}

\section{Introduction}
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.

\section{Main Stuff}
Even though "lorem ipsum" may arouse curiosity because of its resemblance to classical Latin, it is not intended to have meaning. Where text is comprehensible in a document, people tend to focus on the textual content rather than upon overall presentation, so publishers use lorem ipsum when displaying a typeface or design elements and page layout in order to direct the focus to the publication style and not the meaning of the text. In spite of its basis in Latin, use of lorem ipsum is often referred to as greeking, from the phrase "it's all Greek to me," which indicates that this is not meant to be readable text.

\section{Conclusion}
Today's popular version of lorem ipsum was first created for Aldus Corporation's first desktop publishing program Aldus PageMaker in the mid-1980s for the Apple Macintosh. Art director Laura Perry adapted older forms of the lorem text from typography samples — it was, for example, widely used in Letraset catalogs in the 1960s and 1970s (anecdotes suggest that the original use of the "Lorem ipsum" text was by Letraset, which was used for print layouts by advertising agencies as early as the 1970s.) The text was frequently used in PageMaker templates.

\end{document}
4
  • Thank you for your comment! Can I put the \input{count} wherever I want in the document? Also, I tried your minimal example and get the following error message: "File `count.tex' not found. \begin{document}". My pdflatex command looks like this: "pdflatex.exe -synctex=1 -interaction=nonstopmode --shell-escape --enable-write18 %.tex". Do you have any idea what I need to change?
    – Max
    Jan 28, 2021 at 12:59
  • I just noticed, I forgot to add: I am using TeXstudio 3.0.1 on Windows 10
    – Max
    Jan 28, 2021 at 13:25
  • The reason for count.tex not found is probably that something goes wrong in generating it. If you are on Windows, then the commands egrep and sed (used to transform the output of texcount) do not exist automatically. Do you have any tools installed to run linux commands in Windows? (See e.g. https://itsfoss.com/run-linux-commands-in-windows/)
    – gernot
    Jan 28, 2021 at 14:35
  • Would I then need to do all of my compiling within the Linux environment? Or is it enough to have WSL on the computer and then I can use my regular TexStudio on Windows? Also, do I need to install texcount or something like this?
    – Max
    Jan 28, 2021 at 18:05

You must log in to answer this question.

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