On 2012-04-20 Jelle Huisman <je...@jhnet.nl> wrote:

> Is there a way to extract the value for ["total"] ('122' in this case)
> so that I can use that value somewhere else, e.g. in a project file
> where I want to present a word count.

I used the word count some time ago. Here's the code I used. I have
no idea what has changed since and if it still works.

\startluacode
    userdata = userdata or { }

    function userdata.wordcount(listname)
        filename = file.addsuffix(tex.jobname,"words")
        if lfs.isfile(filename) then
            local w = dofile(filename)
            if w then
                if type(w.categories[listname]) == "table" then
                    context(w.categories[listname].total)
                else
                    context(w.total)
                end
                context.par()
            end
        end
    end
\stopluacode

\def\wordcount{%
    \dosingleempty\dowordcount}

\def\dowordcount[#1]{%
    \ctxlua{userdata.wordcount("#1")}}

\starttext

% Set up the word count
\ctxlua{languages.words.threshold=2}
\setupspellchecking [state=start, method=2]

\setupspellchecking [list=foo]
\startsection [title=Foo]
    Foo Bar
\stopsection

\setupspellchecking [list=lorem]
\startsection [title=Lorem]
    Lorem ipsum dolor sit
\stopsection

\setupspellchecking [list=stop]

\startsubject [title=Statistics]
    Words in Foo:   \wordcount [foo]
    Words in Lorem: \wordcount [lorem]
\stopsubject

\stoptext


Marco


___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to