Confounding errors when \frontmatter and cleveref interact while using aucklandthesis.cls?

I am currently nearing the end of writing my thesis, and I am using the aucklandthesis class, since it seems to be the closest thing to an official class/template for my institution. Probably importantly, this is based upon the memoir class. The relevant regulations governing my thesis stipulate that page numbering before the first chapter must in Roman numerals, and then everything after in Arabic numerals. Ordinarily, this wouldn't be an issue, since this seems to be precisely what the memoir class does using the \frontmatter and \mainmatter commands.

When using the aucklandthesis class, however, I seem to be experiencing a strange conflict between it and the cleveref package, but only when the \frontmatter command is used. If the \frontmatter command isn't issued, then the cleveref commands work fine, but I do not get the necessary pagination. If \frontmatter is used, then I get warnings along the line of:

LaTeX Warning: Cref reference format for label type ' undefined on input line 40.

wherever I use the \cref or \Cref commands, and the relevant spot in the document just gets question marks. Moreover, when I use \cref and include more than one cross-reference in it, e.g. \cref{chap1,chap2}, I get an error like

Missing number, treated as zero. < l.43 ...Conclusion, building on \cref{chap1,chap2}

The below MWE seems to demonstrate what I am seeing:

\documentclass[11pt]{aucklandthesis}

\usepackage[T1]{fontenc}
\usepackage{hyperref}
\urlstyle{same}
\usepackage{cleveref}

\begin{document}

\title{[thesis title]}
\subtitle{[subtitle]}
\author{[candidate's name]}
\degreesought{[degree]}
\degreediscipline{[discipline]}
\degreecompletionyear{[year]}

\maketitle
\frontmatter

\begin{abstract}
Apparently, some people refer to category theory as abstract nonsense.''
\end{abstract}

\chapter{Acknowledgements}
I want to thank the Academy, and my enormous ego, I mean talent.

Hey, check out this neat website:  \url{https://www.auckland.ac.nz/en.html}
It's totally not phishing or rickrolling, really...

\settocdepth{section}
\cleardoublepage\tableofcontents

\mainmatter

\chapter{Hello}\label{chap1}
Beginnings and Introductions
\clearpage
\chapter{The Middle}\label{chap2}
Shocking revelations.  \Cref{chap1} has the details!
\clearpage
\chapter{This is the end, my friend}
Thrilling Conclusion, building on \cref{chap1,chap2}.

\backmatter
\cleardoublepage
\appendixpage*
\chapter{Appendix 1}

\end{document}


For comparison's sake, I tried to compile the same thing, but just using memoir as the class instead of the aucklandthesis class (they're not completely identical, since the first one uses a few commands that are custom to aucklandthesis):

\documentclass[11pt]{memoir}

\usepackage[T1]{fontenc}
\usepackage{hyperref}
\urlstyle{same}
\usepackage{cleveref}

\begin{document}

\title{[thesis title]}
\author{[candidate's name]}

\maketitle

\frontmatter

\begin{abstract}
Apparently, some people refer to category theory as abstract nonsense.''
\end{abstract}

\chapter{Acknowledgements}
I want to thank the Academy, and my enormous ego, I mean talent.

Hey, check out this neat website:  \url{https://www.auckland.ac.nz/en.html}
It's totally not phishing or rickrolling, really...

\settocdepth{section}
\cleardoublepage\tableofcontents

\mainmatter

\chapter{Hello}\label{chap1}
Beginnings and Introductions
\clearpage
\chapter{The Middle}\label{chap2}
Shocking revelations.  \Cref{chap1} has the details!
\clearpage
\chapter{This is the end, my friend}
Thrilling Conclusion, building on \cref{chap1,chap2}.

\backmatter
\cleardoublepage
\appendixpage*
\chapter{Appendix 1}

\end{document}


This version seems to build fine, and give the correct pagination results, while working with cleveref. I checked the memoir documentation and couldn't find anything about interactions with cleveref. Memoir apparently defines its own \Cref command, but I'm guessing cleveref overwrites it. All of this leads me to conclude that there is almost certainly an issue with the aucklandthesis class, but my knowledge of memoir and related is far too limited to be able to work out what is going on.

Is there some (reasonably simple) thing I can do to fix this? Preferably one which doesn't involve dropping cleveref. Unfortunately, the original author of the class seems to be long gone from my institution, so I can't ask them about it, and there doesn't seem to be anyone else responsible for maintaining it these days. I find this all perplexing, since the aucklandthesis class doesn't even seem to do anything to the \frontmatter command. I have noticed that sometimes the results from a given run of pdflatex can vary somewhat based on what was or wasn't commented-out in the previous run, but ultimately in the end I cannot get the necessary result no matter what.

Oh, I should probably also mention that I'm working in Overleaf, just in case that makes a difference. I figure maybe someone would suggest some sort of wizardry with the build system, but I doubt that's an option here, I'm afraid. And I probably also should point out that the aucklandthesis class hasn't been updated in some years, so possibly the problem stems from some change to more recent versions of memoir that hasn't been accounted for in aucklandthesis.

• try with \makeatletter \@mainmattertrue \makeatother after \mainmatter. Sep 19, 2021 at 9:21
• That indeed seems to be missing, but add also \setcounter{secnumdepth}{\value{maxsecnumdepth}} to the mix suggested by Ulrike. Sep 19, 2021 at 11:39

The underlying problem has little to do with cleveref in this case. What happens is that calling \frontmatter in aucklandthesis.cls messes up memoir's setup for secnumdepth and, hence, all of your sectioning commands are unnumbered. Therefore, in the MWE at least, \refstepcounter is never called, and your labels miss the information cleveref complains about. If you remove the calls to \cref your document compiles, but with all chapters unnumbered.

The documentclass appears to assume \frontmatter is not to be used at all, since it calls \mainmatter straight from de definition of \maketitle...

It is true that aucklandthesis.cls does not redefine \frontmatter, but it does redefine \mainmatter and, in so doing, leaves out important things of the memoir original. As far as I can tell, you can get things working doing by hand what the class does not do:

\mainmatter
\makeatletter
\@mainmattertrue
\makeatother
\setcounter{secnumdepth}{\value{maxsecnumdepth}}
\pagenumbering{arabic}


But, in this case, it appears this documentclass is not really official to your institution, which means you are not required to use it. In which case you might be better off simply starting from one of the standard classes, memoir itself, or KOMA-Script.

Unfortunately, the original author of the class seems to be long gone from my institution, so I can't ask them about it, and there doesn't seem to be anyone else responsible for maintaining it these days.

Formally, it is a package published on CTAN. Whether its maintainer is still on the institution or not does not change their role wrt to CTAN. Well, that in theory, in practice things might be different... And I did check the documentation and it seems there is no contact information for you to attempt to report this. If you really think sticking to the document class is worth it, you might want to try some contact through CTAN itself. Or, if your institution does advertise this document class as something "official", even if not "required" but just "recommended", you probably should report this to someone at the University.

• Yeah, I'm not sure the original creator was a memoir guru, so it's quite possible they made a mistake. I'll try to mention all this to someone in an appropriate position. Anyway, your fixes almost work completely, but for some reason the page numbering doesn't reset to Arabic starting from 1 again by itself 😕 Resetting it manually immediately after the first chapter declaration seems to work, though 🤷‍♂️ Anyway, thanks! :) Sep 19, 2021 at 22:59
• Well... who knows what other surprises are hidden there? ;-) I can only reiterate the advice: if you can, do consider choosing a more traditional document class. Sep 19, 2021 at 23:07
• For the record, what memoir does there too is \pagenumbering{arabic}. I added that to the answer. Sep 19, 2021 at 23:11
• And, if you are curious, take a look at the template.tex` which comes with the document class. I guess it gives you an idea of the document structure the author had in mind. Sep 19, 2021 at 23:14