From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/99864 Path: news.gmane.org!.POSTED!not-for-mail From: Rik Kabel Newsgroups: gmane.comp.tex.context Subject: Re: Word and character count excluding TeX-directives Date: Tue, 16 Jan 2018 10:09:19 -0500 Message-ID: <6e9700d7-63f2-bb31-157e-25b7930cfc63@rik.users.panix.com> References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============9076681128956191149==" X-Trace: blaine.gmane.org 1516115285 9507 195.159.176.226 (16 Jan 2018 15:08:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 16 Jan 2018 15:08:05 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Tue Jan 16 16:08:00 2018 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ebSq7-0001iR-Lk for gctc-ntg-context-518@m.gmane.org; Tue, 16 Jan 2018 16:07:51 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 188F38A1C27; Tue, 16 Jan 2018 16:09:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id THhusms3iYOu; Tue, 16 Jan 2018 16:09:35 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [IPv6:::1]) by zapf.ntg.nl (Postfix) with ESMTP id 657B28A1C4E; Tue, 16 Jan 2018 16:09:34 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 179AA8A1C49 for ; Tue, 16 Jan 2018 16:09:34 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7dXe97a6c_XU for ; Tue, 16 Jan 2018 16:09:33 +0100 (CET) Original-Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 2C75F8A1C44 for ; Tue, 16 Jan 2018 16:09:23 +0100 (CET) Original-Received: from [192.168.201.10] (cpe-24-194-22-135.nycap.res.rr.com [24.194.22.135]) by mailbackend.panix.com (Postfix) with ESMTPSA id A99021A169 for ; Tue, 16 Jan 2018 10:09:21 -0500 (EST) In-Reply-To: Content-Language: en-US X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.16 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.org gmane.comp.tex.context:99864 Archived-At: This is a multi-part message in MIME format. --===============9076681128956191149== Content-Type: multipart/alternative; boundary="------------11B087A0CCFA53B8EC7EEF2C" Content-Language: en-US This is a multi-part message in MIME format. --------------11B087A0CCFA53B8EC7EEF2C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 2018-01-16 09:26, Dr. Thomas Möbius wrote: > \definestartstop >     [abstract] >     [style=bold, >     after={\blank[big]}] > > \starttext > \title{My title: example of a word and character count} > > {\strut\tfx Formal guidelines: word count of abstract: $x$, character > count of main text: $x$, character count of figure captions: $x$.} > \blank > > \startabstract > This is the abstract. Read this and that. > \stopabstract > > % start of the main text > Some random text with formulas > > \startformula > y = α + βx + ε, \quad ε \sim N(0,σ^2) > \stopformula > > And there are also figures with captions. > > \startplacefigure[ >     location=bottom, >     title={Residual plot with time $t$ on the x-axis and >     residuals $e_{jt}$ on the y-axis}, >     reference={fig:subject-residual}] > \externalfigure[residuals][height=.242\textheight] > \stopplacefigure > > And some more text with $x$ and $y$ and $z$, and \placeformula > > \startformula \startalign > \NC a =\NC b \NR > \NC c =\NC d \NR > \stopalign \stopformula > > And stop. > \stoptext Try something based on this: \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")}} \setupspellchecking[state=start,method=2] \ctxlua{languages.words.threshold=1} \definestartstop     [abstract]     [style=bold,     after={\blank[big]}] \starttext     \setupspellchecking[list=abstract]     \startabstract         This is the abstract. Read this and that.     \stopabstract     \setupspellchecking[list=main]     Some random text with formulas     \startformula         y = α + βx + ε, \quad ε \sim N(0,σ^2)     \stopformula     And there are also figures with captions.     \setupspellchecking[list=figures]     \startplacefigure[       location=bottom,       title={Residual plot with time $t$ on the x-axis and       residuals $e_{jt}$ on the y-axis},       reference={fig:subject-residual}]           \externalfigure[residuals][height=.242\textheight]     \stopplacefigure     \setupspellchecking[list=main]     And some more text with $x$ and $y$ and $z$, and \placeformula     \startformula \startalign         \NC a =\NC b \NR         \NC c =\NC d \NR     \stopalign \stopformula     And stop.     \setupspellchecking[state=stop] \title{My title: example of a word and character count}         Abstract: \wordcount[abstract]         Main: \wordcount[main]         Figures: \wordcount[figures]         Wordcount: \wordcount \stoptext -- Rik --------------11B087A0CCFA53B8EC7EEF2C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 2018-01-16 09:26, Dr. Thomas Möbius wrote:
\definestartstop
    [abstract]
    [style=bold,
    after={\blank[big]}]

\starttext
\title{My title: example of a word and character count}

{\strut\tfx Formal guidelines: word count of abstract: $x$, character
count of main text: $x$, character count of figure captions: $x$.}
\blank

\startabstract
This is the abstract. Read this and that.
\stopabstract

% start of the main text
Some random text with formulas

\startformula
y = α + βx + ε, \quad ε \sim N(0,σ^2)
\stopformula

And there are also figures with captions.

\startplacefigure[
    location=bottom,
    title={Residual plot with time $t$ on the x-axis and
    residuals $e_{jt}$ on the y-axis},
    reference={fig:subject-residual}]
\externalfigure[residuals][height=.242\textheight]
\stopplacefigure

And some more text with $x$ and $y$ and $z$, and \placeformula

\startformula \startalign
\NC a =\NC b \NR
\NC c =\NC d \NR
\stopalign \stopformula

And stop.
\stoptext

Try something based on this:

\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")}}
\setupspellchecking[state=start,method=2]
\ctxlua{languages.words.threshold=1}

\definestartstop
    [abstract]
    [style=bold,
    after={\blank[big]}]

\starttext

    \setupspellchecking[list=abstract]

    \startabstract
        This is the abstract. Read this and that.
    \stopabstract

    \setupspellchecking[list=main]

    Some random text with formulas

    \startformula
        y = α + βx + ε, \quad ε \sim N(0,σ^2)
    \stopformula

    And there are also figures with captions.

    \setupspellchecking[list=figures]

    \startplacefigure[
      location=bottom,
      title={Residual plot with time $t$ on the x-axis and
      residuals $e_{jt}$ on the y-axis},
      reference={fig:subject-residual}]
          \externalfigure[residuals][height=.242\textheight]
    \stopplacefigure

    \setupspellchecking[list=main]

    And some more text with $x$ and $y$ and $z$, and \placeformula

    \startformula \startalign
        \NC a =\NC b \NR
        \NC c =\NC d \NR
    \stopalign \stopformula

    And stop.

    \setupspellchecking[state=stop]

\title{My title: example of a word and character count}

        Abstract: \wordcount[abstract]
        Main: \wordcount[main]
        Figures: \wordcount[figures]
        Wordcount: \wordcount

\stoptext

--
Rik

--------------11B087A0CCFA53B8EC7EEF2C-- --===============9076681128956191149== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f --===============9076681128956191149==--