Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
1  
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
add comment

2 Answers

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
M-F
M-W
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
add comment

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.

\usepackage{xesearch}

\newcounter{words}
\AtBeginDocument{
    \setcounter{words}{0}
    \SearchList!{wordcount}{\stepcounter{words}}
        {a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
    \UndoBoundary{'’-}
    \MakeBoundary{„“‚‘–}
    \SearchOrder{p;}
}
\AtEndDocument{
    \StopSearching
    \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
add comment

Your Answer

 
discard

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.