TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to have a continuous word count for an assignment. This is either in the form of a note in the margin or one parenthesised in-text every 100 words or so. For instance,

----- TEXT ------|- MARGIN -
blahblahblahblah | 100 [100th word appears on this line]

Any ideas on how to do so?

share|improve this question
Please provide some more information about the TeX format you use: Plain, eTeX, xeTeX, or LuaTeX. – Mico Aug 4 '12 at 19:35
What an evil assignment! (I'm tempted to say ridiculous, but there could be extenuating circumstances.) Also, do you need a dynamic word count? A tex solution would be, but this sounds like you only need this count for when you hand it in. – jon Aug 4 '12 at 19:35
Plain TeX. Doesn't need to be dynamic, static is fine. But of course, it would be nice to see it as I edit it. =) – Junkbot Aug 6 '12 at 8:25
How accurate does this have to be? what defines "a word"? Do headings count? do footnotes count ... there are a lot of possibilities to complicate it. If from within TeX then probably only through LuaTeX and even there the programming effort would be considerable. – Frank Mittelbach Aug 6 '12 at 21:02

I know a way with the GNU Emacs application, though the limitation is that it can't recognize latex code (maybe someone has a suggestion?), and therefore would only work if it is stripped from latex code at first:

C-u 100 M-f         ;; forward-word
SPACE               ;; insert space
\                   ;; self-insert-command
marginpar{          ;; self-insert-command * 10
C-y                 ;; yank
}                   ;; self-insert-command
M-b                 ;; backward-word
DEL                 ;; backward-delete-char-untabify

Using F4 (call-last-macro) from then on will then do what you ask every 100 words (make sure to put the cursor at the word after the \marginpar{}

share|improve this answer

This is not a complete answer. The code shows the basics of how one could do a word count with xelatex. I understand this is not your setup at all.


    \newpage \thispagestyle{empty}
    \arabic{words} words in document

It suits my needs to hack a margin note into \addtokomafont{section}{}, but I’m not sure how to invoke a command once a counter hits a certain threshold.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.