论文(muthesis)中的字数统计——怎么做?

论文(muthesis)中的字数统计——怎么做?

如果这真的很简单,请原谅,但我搞不懂。我正在使用 muthesis 模板来写我的论文。大学的要求是在 toc、lof 和 lot 的末尾包含字数统计。在这个模板中,已经有一行字数统计了,如下所示 \def\wordcount{}

我以为这只是使用在线 latex 字数统计工具的情况http://app.uio.no/ifi/texcount/,输入我的每一章,将数字加起来,然后将其放入\def\wordcount{},例如\def\wordcount{57103}。但是当我这样做时,它仍然会出现“字数 999,999”。

我究竟做错了什么?

以下是 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}

答案1

因此,我能想到的最好的办法就是将宏复制\beforeabstractmuthesis.cls你的序言中,然后调整那里的字数:

\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}

这样,您就不必摆弄 的内容muthesis,而您可能希望保留其原样。

编辑:检查了注释行后,\beforeabstract我设法自动进行了字数统计:为此,您需要运行pdflatex --shell-escape report.tex并获取以下代码:

\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}

此外,您需要的本地副本texcount.pl,请参阅评论中提供的链接以获取帮助。

答案2

为了供将来可能使用 muthesis 模板的任何人参考,下面是我如何通过手动输入字数来使其工作的:

\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}

相关内容