[Tex/LaTex] Problem with \thesistitle in Masters/Doctoral Thesis template

templates

I have downloaded the fantastic template for doctoral thesis available in
https://www.latextemplates.com/template/masters-doctoral-thesis.

I have used it before I had already adapted the contents for my thesis. However, when I tried to compile it with MiKTeX after the last update I got this problem:

("C:\Users\XXXX\AppData\Local\Programs\MiKTeX 2.9\tex\generic\oberdiek\atbegshi.sty"))
! Missing number, treated as zero.
<to be read again> 
               -
l.81 ...end of thesis title}
                                               % Your thesis title, this...

? 

The problem seems to be within the \thesistitle command. However I have checked the .cls file and I can't see any problem with it. I downloaded the original from LaTeXtemplates and got the same results:

("C:\Users\XXXX\AppData\Local\Programs\MiKTeX 2.9\tex\latex\csquotes\csquotes.cfg"))
! Missing number, treated as zero.
<to be read again> 
               -
l.70 \thesistitle{Thesis Title}
                            % Your thesis title, this is used in the tit...

? 

This is a minimal working example that gives the same error. I couldn't get rid of the class dependency though:

\documentclass[11pt, english, singlespacing, headsepline]{MastersDoctoralThesis}

\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters

\thesistitle{Resilience of wastewater resource recovery to multiple stress conditions} 

\begin{document}
\begin{titlepage}

\HRule \\[0.4cm] % Horizontal line
{\huge \bfseries \ttitle\par}\vspace{0.4cm} % Thesis title
\HRule \\[1.5cm] % Horizontal line

\end{titlepage}
\end{document} 

Crosspost on LaTeX.org

UPDATE: The provisional solution would be to replace the \thetitle command part in the .tex file, with:

\newcommand{\ttitle}{Thesis title}
\makeatletter
\renewcommand{\@title}{Thesis title}
\makeatother

Best Answer

The class abuses \DeclareDocumentCommand for defining variables. Anyway, the obvious error is in the second line of

\DeclareDocumentCommand{\thesistitle} { o m }{
        \IfBooleanTF{#1} {\DeclareDocumentCommand{\shorttitle}{ }{#1}
        {\DeclareDocumentCommand{\shorttitle}{}{#2}}}
        \DeclareDocumentCommand{\@title}{ }{#2}
        \DeclareDocumentCommand{\ttitle}{ }{#2}
}

where \IfBooleanTF makes no sense and should be \IfValueTF.

The code should be

\NewDocumentCommand{\thesistitle} { o m }{%
   \IfValueTF{#1}{\def\shorttitle{#1}}{\def\shorttitle{#2}}%
   \def\@title{#2}%
   \def\ttitle{#2}%
}

or, in a slicker way,

\NewDocumentCommand{\thesistitle} { O{#2} m }{%
   \def\shorttitle{#1}%
   \def\@title{#2}%
   \def\ttitle{#2}%
}

You can avoid modifying the class by using in the preamble

\makeatletter
\RenewDocumentCommand{\thesistitle} { O{#2} m }{%
   \def\shorttitle{#1}%
   \def\@title{#2}%
   \def\ttitle{#2}%
}
\makeatother

My preference would go to \def instead of \DeclareDocumentCommand. However, fixing the class would need weeks of work (for example, \null\vfill has no place and the number of unprotected end-of-lines is huge), so I let it go.