* Word and character count excluding TeX-directives
@ 2018-01-16 14:26 Dr. Thomas Möbius
2018-01-16 15:09 ` Rik Kabel
0 siblings, 1 reply; 2+ messages in thread
From: Dr. Thomas Möbius @ 2018-01-16 14:26 UTC (permalink / raw)
To: ConTeXt Mailing List
To meet some formal guidelines, I need to provide a word count of my
abstract and a character count of the main text, and a character count
of all the text appearing in figure captions.
Is this possible (maybe using some lua-magic)?
Thank you!
Thomas
Minimal example:
\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
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Word and character count excluding TeX-directives
2018-01-16 14:26 Word and character count excluding TeX-directives Dr. Thomas Möbius
@ 2018-01-16 15:09 ` Rik Kabel
0 siblings, 0 replies; 2+ messages in thread
From: Rik Kabel @ 2018-01-16 15:09 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1.1: Type: text/plain, Size: 3639 bytes --]
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
[-- Attachment #1.2: Type: text/html, Size: 5267 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 bytes --]
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-16 15:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-16 14:26 Word and character count excluding TeX-directives Dr. Thomas Möbius
2018-01-16 15:09 ` Rik Kabel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).