In order to count easily words in a text, i'd like to display for each word its "number",

Context : I'm teaching my students to copy a text and to evaluate them I count how many words they successfully copied.

It's not necessary that the counting is done automatically, I'm using the same text,

This is what I've tried for now :

\newcommand{\wordcount}[2]{\stackunder{\text{#1}}{\scriptstyle \text{#2}}}
\wordcount{{\fontsize{14}{11}\selectfont XII}}{7}

Which give this result :

Some text with number under each word

My problem are multiple :

  • The code is "heavy" I have a long text, ideally I'd like a simple command...
  • It's in math mode
  • Spacing is a nightmare (the 6 and 7 are higher than the 5 and no space between words)...

Any help is appreciated (sorry for any mistake, french here),

Thanks !

  • Also, please provide a complete example that compiles, beginning with \documentclass. Also, no undefined macros like \ieme. You can edit your existing question. Welcome to the site. Apr 29, 2021 at 23:54
  • To get rid of the uneven vertical positioning, \renewcommand\stacktype{L}. Then you can adjust the baselineskip with \setstackgap{L}{<dimen>}. Apr 29, 2021 at 23:57
  • Thanks for the comments, edit done !
    – Jielpe
    May 1, 2021 at 7:10

1 Answer 1


This should hopefully be more painless than what you were using.

  \wordcountaux#2 \relax}
\def\wordcountaux#1 #2\relax{%
  \stackunder{#1}{\scriptsize\thewordcnt}\ %
y = mx + b\quad\wordcount[4]{Jusqu' au \fontsize{14}{11}\selectfont 
  XII\ieme{} siècle}
E= mc^2\quad\wordcount{Count picks up by default}

enter image description here

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.