0

I want to control the size of a piece of text in my Latex document (for an application for research funding), and ignore the latex code. I want to count also the whitespaces. I really want to measure the size of the text generated in the PDF. I coded this macro getting inspiration from here.

\documentclass{article}
\usepackage{stringstrings}

\newcommand{\numchars}[1]{% \convertchar[q]{#1}{ }{} {\noindent \textit{(\stringlength{\thestring} signs)}
#1}}

\begin{document}

\numchars{Longtemps, je me suis couché de bonne heure. Parfois, à peine ma bougie éteinte, mes yeux se fermaient si vite que je n’avais pas le temps de me dire : " Je m’endors. " \label{À la recherche du temps perdu}}

\end{document}

I have three issues here:

  1. Exotic characters like "é" count as several characters
  2. It looks like beyond 500 characters the code fails
  3. Any Latex code, any citation for instance, will generate an error
  • 1
    Try to convert your test file to a regular text with pandoc -t asciidoc test.tex. You could then pipe the output to wc -c. If you want to exclude new line characters insert sed -z "s:\n::g" in the pipe. If you also want to exclude spaces, add \s to the pattern. for instance: pandoc -t asciidoc test.tex | sed -z "s:\n\|\s::g" | wc -c. – Celdor Feb 15 '24 at 13:15
  • 1
    There are approaches that use outside software. If you wanted to stay within LaTeX to perform the operation, https://tex.stackexchange.com/questions/44618/dynamically-count-and-return-number-of-words-in-a-section/587567#587567 provides an approach. By the way, the problem you are looking at is far too complex for stringstrings (which I wrote). Don't use it. – Steven B. Segletes Feb 15 '24 at 19:48

0 Answers0