2

Apologies if this is really simple but I cannot figure this out. I am using the muthesis template for my thesis. A requirement of the University is to include a word count at the end of the toc, lof and lot. Within this template there is already a line for the word count as \def\wordcount{}

I thought this would be a case of simply using the latex word count tool online http://app.uio.no/ifi/texcount/, input each of my chapters, add the numbers up and put this into \def\wordcount{}, e.g. \def\wordcount{57103}. But when I do this, it still comes up with 'word count 999,999'.

What am I doing wrong?

Here is a MWE:

\documentclass[11pt,PhD,twoside]{muthesis}
\usepackage[T1]{fontenc}% recommended
\usepackage{textcomp}
\usepackage{todonotes}
\usepackage{amsmath}
\usepackage{amstext}

\usepackage{enumitem}
% tables
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{booktabs}
% captions and floats
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage[aboveskip=2pt]{subcaption} % aboveskipchanges spacing     beten     caption and figure
\captionsetup[subfigure]   {justification=justified,singlelinecheck=false}     %%% alignment of  subfigure captions

\usepackage{stackengine}
% colour, graphics, diagrams
\PassOptionsToPackage{table}{xcolor}
\usepackage{graphicx}% don't load graphics as well - this covers it all     already
\usepackage{pgfplotstable}
\pgfplotstableset{col sep=comma}
\usepackage[UKenglish]{datetime}
\usepackage{parskip}
\usepackage[none]{hyphenat}
\usepackage{lscape}

% for references

\usepackage{natbib}
%\setlength{\bibhang}{5em}
\renewcommand{\bibfont}{\normalfont\small}

\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{listings}

\usepackage[]{titlesec}
\usepackage{fancyhdr}

% to sort out issues with urls
\usepackage[hyperindex,breaklinks]{hyperref}

\titleformat{\section}
{\normalfont\fontsize{13}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\subsubsubsection}
{\normalfont\fontsize{13}{15}\bfseries}{\thesubsubsubsection}{1em}{}

\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}

\def\afterpreface{\newpage
    \pagestyle{fancy}}
\pagestyle{fancy}
\fancyhf{}
\renewcommand*\headrulewidth{0pt}
\fancyhf[leh,roh]{\thepage}
\fancyhf[loh,reh]{\slshape\leftmark}

\begin{document}

\title{A thesis}
\author{AN Author}

\school{School of}
\faculty{Faculty}
\def\wordcount{57103} %%% Word count required at end of toc/lof and lot

\beforeabstract
\section*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

\begin{spacing}{1.0}
\fontsize{12}{12}\normalfont% faculty requirements for abstract
abstract   abstract   abstract   abstract   abstract   abstract            abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract
\end{spacing}

\afterabstract
\prefacesection{Acknowledgements}
I would like to thank......

\afterpreface

\chapter{Introduction}
\section{Background}
Background Background Background Background Background Background         Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background2}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background3}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\end{document}
  • The problem ist that in class muthesis.cls there is no macro \wordcount used (nor defined), so defining it just gives you a new macro which is not used. In the class file you find \beforeabstract which contains the (hard coded) line Word Count: 999,999 which is what you see. You can change this number to what you like, but that's not the best idea, rather there must be a possibility to patch the command from your document. I don't know how, though... – cauchy42 Sep 24 '15 at 8:39
3

So the best I can come up with is to copy the \beforeabstract macro from muthesis.cls into your preamble and adjust the word count there:

\documentclass[11pt,PhD,twoside]{muthesis}

%Your preamble goes here

\def\beforeabstract{
        \pagenumbering{arabic}
        \pagestyle{plain}
        \titlep
        \ifsigpage\signaturepage\fi
        \tableofcontents
        ~\\
        ~\\
%Here the number can be adjusted
        Word Count: 57103 
        % Download texcount.pl from  http://app.uio.no/ifi/texcount/ and
        % uncomment following lines to have word count handled automatically

        % Run texcount on report.tex and write results to word.count
        \immediate\write18{perl ./texcount.pl -1 -sum -relaxed -inc report.tex > word.count}
        % TC:ignore
        %Word Count: \input{word.count} % texcount ignore around this to stop error message (open recursion on file)
       % TC:endignore
        % note: if this causes an error (word.count missing, or a blank wordcount) you may need to add: " --enable-write18" (win) or "--shell-escape" (Linux) to arguments for LaTeX
        % see http://app.uio.no/ifi/texcount/faq.html for details of this and other possible errors
        ~\\
        \newpage
        \iftablespage
                \addvspace{10pt}
                \listoftables
                \newpage
        \fi
        \iffigurespage
                \addvspace{10pt}
                \listoffigures
                \newpage
        \fi}


\begin{document}

\title{A thesis}
\author{AN Author}

\school{School of}
\faculty{Faculty}


%You don't need that line
%\def\wordcount{57103} %%% Word count required at end of toc/lof and lot
\beforeabstract


\section*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

\begin{spacing}{1.0}
\fontsize{12}{12}\normalfont% faculty requirements for abstract
abstract   abstract   abstract   abstract   abstract   abstract            abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract
\end{spacing}

\afterabstract
\prefacesection{Acknowledgements}
I would like to thank......

\afterpreface

\chapter{Introduction}
\section{Background}
Background Background Background Background Background Background         Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background2}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background3}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\end{document}

In that way, you don't have to fiddle with the contents of muthesis, which you might want to keep as they are.

EDIT: After inspecting the commented lines in \beforeabstract I managed to do the word count automatically: For that, you need to run pdflatex --shell-escape report.tex and have the following code:

\def\beforeabstract{
        \pagenumbering{arabic}
        \pagestyle{plain}
        \titlep
        \ifsigpage\signaturepage\fi
        \tableofcontents
        ~\\
        ~\\
%        Word Count: 57103 
        % Download texcount.pl from  http://app.uio.no/ifi/texcount/ and
        % uncomment following lines to have word count handled automatically

        % Run texcount on report.tex and write results to word.count
%Insert your file here instead of "filename.tex"    
        \immediate\write18{perl ./texcount.pl -1 -sum -relaxed -inc filename.tex > word.count}
        % TC:ignore
        Word Count: \input{word.count} % texcount ignore around this to stop error message (open recursion on file)
       % TC:endignore
        % note: if this causes an error (word.count missing, or a blank wordcount) you may need to add: " --enable-write18" (win) or "--shell-escape" (Linux) to arguments for LaTeX
        % see http://app.uio.no/ifi/texcount/faq.html for details of this and other possible errors
        ~\\
        \newpage
        \iftablespage
                \addvspace{10pt}
                \listoftables
                \newpage
        \fi
        \iffigurespage
                \addvspace{10pt}
                \listoffigures
                \newpage
        \fi}

Further, you need a local copy of texcount.pl, refer to the links provided in the comments for help there.

  • Yup, that works for me now with some minor modifications, thank you @cauchy42. Will try to upload an example for others for future reference. – MarinaWM Sep 24 '15 at 10:58
  • I used the first example (without the automatic word count as I put below) but then in the pdf version I end up getting the abstract in the bookmarks first and it links to the wrong part of the document. Do you know why? – MarinaWM Sep 24 '15 at 14:02
  • @MarinaWM I don't know. The problem does not arise with my proposed change, but is in the thesis template already. As it is not related, please ask a new question, to get further attention. – cauchy42 Sep 28 '15 at 8:31
0

For future reference to anyone that might be using muthesis template, here is how I managed to get it to work with just manually inputting the word count:

\documentclass[11pt,PhD,twoside]{muthesis}

%Your preamble goes here



\begin{document}

\title{A thesis}
\author{AN Author}

\school{School of}
\faculty{Faculty}

\def\beforeabstract{
    \pagenumbering{arabic}
    \pagestyle{plain}
    \titlep
    \ifsigpage\signaturepage\fi
    \tableofcontents
    % To include a word count generated automatically follow the
% instructions below
    % Download texcount.pl from  http://app.uio.no/ifi/texcount/ and
    % uncomment following lines to have word count handled automatically
%~\\
    ~\\
    \textbf{Word Count:} 57103
    % Run texcount on report.tex and write results to word.count
    %\immediate\write18{perl ./texcount.pl -1 -sum -relaxed -inc report.tex     > word.count}
    % TC:ignore
    %Word Count: \input{word.count} % texcount ignore around this to stop     error message (open recursion on file)
   % TC:endignore
    % note: if this causes an error (word.count missing, or a blank     wordcount) you may need to add: " --enable-write18" (win) or "--shell-escape" (Linux) to arguments for LaTeX
    % see http://app.uio.no/ifi/texcount/faq.html for details of this and other possible errors
    ~\\
    \newpage
    \iftablespage
            \addvspace{10pt}
            \listoftables
            \newpage
    \fi
    \iffigurespage
            \addvspace{10pt}
            \listoffigures
            \newpage
    \fi}
%You don't need that line
%\def\wordcount{57103} %%% Word count required at end of toc/lof and lot
\beforeabstract


\section*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

\begin{spacing}{1.0}
\fontsize{12}{12}\normalfont% faculty requirements for abstract
abstract   abstract   abstract   abstract   abstract   abstract                abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract   abstract
\end{spacing}

\afterabstract
\prefacesection{Acknowledgements}
I would like to thank......

\afterpreface

\chapter{Introduction}
\section{Background}
Background Background Background Background Background Background             Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background2}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background
\clearpage
\section{Background3}
Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background Background   
\end{document}

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.