My school, the University of Rhode Island (URI),
recommends using style files developed by the school for completing theses,
such as a custom document class file, urithesis.cls,
for the \documentclass{} command.

I have determined that this custom document class file
creates an incompatibility between the mathtools and listings packages.

I perused the .cls code and was not able to determine any obvious problems.
(This is expected, as I am not well-versed in custom document class files.)
I notified the owner/creator, and have not yet received a response.

Is this type of issue when using a custom document class
a common and generally easily-resolved issue?
(Both packages are highly-desirable to me.)


In the above link, reiterated here for convenience,
the document class file is provided, as well as a minimum working example (MWE).

Please download the thesis.zip link for the complete MWE.
If the following code is added to the preface of the root file thesis.tex:


then an error message will occur.
Commenting either package out will resolve the issue.


The class does a very wrong thing, which explodes when calc is loaded together with listings.

% line 424

% lines 795-801

The \cl@chapter macro is executed whenever chapter is stepped, so as to do the required resetting. Doing \setcounter inside it is wrong anyway.

You have to fix the class, I'm afraid. The first bit should become

% Counts the number of references in each chapter to determine if there
% is a list of references for that chapter when using chapterref format.

and the second part should be


There are much better methods than to hook in \cl@chapter, though.

I'd suggest removing the redefinition of \cl@chapter, adding


in the proper place (after \LoadClass) and, at the end of the class,

  • 1
    @kando I think I interpreted correctly what the class is doing; essentially, \@elt{chaptercitecount} will do \setcounter{chaptercitecount}{0}, but in a safe way. I'll try and suggest a better fix.
    – egreg
    Jun 20 '17 at 17:15
  • 1
    @kando I added the better fix
    – egreg
    Jun 20 '17 at 17:29
  • 1
    @kando The redefinition of \cl@chapter should be removed; the better definition of the chaptercitecount counter should be as in the previous fix. The new part can go essentially anywhere after \LoadClass. At the end, when all relevant counters are surely defined is a good place.
    – egreg
    Jun 20 '17 at 17:45
  • 1
    @kando Remove from \def\cl@chapter{ up to the matching }.
    – egreg
    Jun 20 '17 at 18:06
  • 1
    @kando REMOVE from \def\cl@chapter{ up to the matching }.
    – egreg
    Jun 20 '17 at 19:10

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.