0

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.
<to be read again> 
                   \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!

  • 1
    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 at 16:40
  • 1
    Don't use spaces in the citation list. – Ulrike Fischer Jul 31 at 17:01
1

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).

enter image description here

\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 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.