# TexWorks XeLaTex section/paragraph word count

I realize this question has been asked a often, but as I do not have admin rights on my PC (i.e. no way to install pearl) and find copy-pasting text to word or elsewhere annoying, I hope I can find help here. Basically, I would like to have the word count next of a given paragraph right next to it, that helps me with the writing.

From the solutions I have found, https://tex.stackexchange.com/a/10034/182896 is the one that seems to work well for paragraphs and does what I need it to do. This is an excerpt of the preamble:

\documentclass{article}
\begingroup
\lccode\~=\ %
\lowercase{%
\gdef\assignment{\setcounter{word}{0}%
\catcode~=\active
\def~{\space\stepcounter{word}}}}%
\endgroup
\newcounter{word}
\def\endassignment{\stepcounter{word}%
\marginpar{\arabic{word} words}}
\usepackage[authordate,backend=biber, hyperref=true]{biblatex-chicago}


It took me ages to figure it out where the problem occured, but if in the main text I do this:

\begin{document}

\begin{assignment}
Some text here~\autocites[see for instance][]{Gallarotti2011}{Lai2013b}{Hayden2012}.\par
\end{assignment}

\end{document}


all is good, but if I do the following:

\begin{document}

\begin{assignment}
Some text here~\autocites[see for instance][]{Gallarotti2011, Hayden2012, Lai2013b}.
\end{assignment}

\end{document}


the document does not compile and instead returns this error:

Missing \endcsname inserted.
\csname\endcsname
l.22 ...e][]{Gallarotti2011, Hayden2012, Lai2013b}
.


So, I do not understand what is causing the problem here aside from it happens somehow in the curly brackets. Of course I can rewrite my citations, but that would take a lot of time. So maybe someone who can help here?

Thanks!

• Catcode changes are always tricky, it is somewhat surprising that this is the only issue you have encountered so far. Maybe you can try a portable version of Perl that doesn't require installing (stackoverflow.com/questions/5869118/…)? – Marijn Jul 31 '19 at 16:40
• Don't use spaces in the citation list. – Ulrike Fischer Jul 31 '19 at 17:01

Making space active like this will break most latex documents, the cases where it gives an error are the lucky cases where you get warning, more worrying are cases where it adversely affects the typesetting (third example here) or simply gives the wrong number (second and third examples).

\documentclass{article}
\begingroup
\lccode\~=\ %
\lowercase{%
\gdef\assignment{\setcounter{word}{0}%
\catcode~=\active
\def~{\space\stepcounter{word}}}}%
\endgroup
\newcounter{word}
\def\endassignment{\stepcounter{word}%
\marginpar{\arabic{word} words}}
\usepackage[authordate,backend=biber, hyperref=true]{biblatex-chicago}

\begin{document}

\begin{assignment}
Some text here
\end{assignment}

\begin{assignment}
Some
text
here
\end{assignment}

\begin{assignment}
Some  text  here
\end{assignment}

\end{document}


Of course in theory it would be possible to make the code more complicated and make these examples give correct output, but more complicated code is even more likely to clash with other packages and give errors.

• Thanks for this honest advise! I just started out, so was looking for the easiest fix as I have no computer background and always struggle if the advise I get involves other programs! – SCW Aug 1 '19 at 8:58