4

I'm submitting to a journal (EJP) that requires the use of their document class for submission. I've already made my whole document using the cleveref package and would like to not go through manually removing it, but the journal's document class breaks it. Here is a minimal working example

\documentclass[EJP]{ejpecp}
% or
%\documentclass{article}
%\newtheorem{proposition}{proposition}

\usepackage{nameref,hyperref,cleveref}
\Crefname{proposition}{Proposition}{Propositions}

\begin{document}
\begin{proposition}\label{prop:zeronotone}
    One has $0 \neq 1$.
\end{proposition}

\Cref{prop:zeronotone} is very useful.

\end{document}

The documentclass ejpecp comes with texlive on linux, but if you do not have it you can obtain it at https://ctan.org/pkg/ejpecp.

For some reason the reference shows up as "Theorem 1" instead of "Proposition 1". Changing the documentclass to article and uncommenting the newtheorem line corrects the reference.

The issue is certainly with the delicate order that all the packages need to be loaded in. The ejpecp class loads hyperref automatically, but not nameref or cleveref. I can fix the problem by modifying the ejpecp.sty file on my machine and adding \RequirePackage{nameref} immediately before their RequirePackage{hyperref} and adding \RequirePackage{cleveref} immediately after it. However, to ease the submission process, I would, if at all possible, like to avoid telling them the document requires them to use a modified version of their documentclass. Of course, I would also not like to manually change the hundreds of references in my document to manually specify Theorem, Proposition, etc. Is there any easy fix?

1

Loading hyperref in a document class is always problematic, because it usually has to come last (except for cleveref and a few other packages).

Anyway, this is not the main problem: the biggest one is that the theorem-like environments are declared before you can load cleveref.

In my opinion the class should provide a cleveref option, so as to load the package at the right spot, that is, after loading hyperref and before declaring theorem-like environments and other counters.

Loading hyperref and cleveref before loading the class is the worst advice I can think to. Modifying the class is out of the question.

You can solve the issue by redeclaring the environments and marking the input so the copy editors will know what's going on.

\documentclass[EJP]{ejpecp}

\usepackage{cleveref}

%%% I have to redefine the theorem-like environments
%%% in order to use cleveref; output will be exactly the
%%% same, because the environments are declared in the
%%% same styles as in the class.
\makeatletter
\def\redeclare@theorems#1{%
  \@for\next:=#1\do{\expandafter\redeclare@theorem\next}%
}
\def\redeclare@theorem#1#2{%
  \expandafter\let\csname #1\endcsname\relax
  \expandafter\let\csname end#1\endcsname\relax
  \newtheorem{#1}[theorem]{#2}%
}
\theoremstyle{ejpecpbodyit}
\redeclare@theorems{%
  {assumptions}{Assumptions},%
  {assumption}{Assumption},%
  {claim}{Claim},%
  {condition}{Condition},%
  {conjecture}{Conjecture},%
  {corollary}{Corollary},%
  {definitions}{Definitions},%
  {definition}{Definition},%
  {facts}{Facts},%
  {fact}{Fact},%
  {heuristics}{Heuristics},%
  {hypothesis}{Hypothesis},%
  {hypotheses}{Hypotheses},%
  {lemma}{Lemma},%
  {notations}{Notations},%
  {notation}{Notation},%
  {proposition}{Proposition}%
}
\theoremstyle{ejpecpbodyrm}
\redeclare@theorems{%
  {example}{Example},%
  {exercise}{Exercise},%
  {problem}{Problem},%
  {question}{Question},%
  {remark}{Remark}%
}
\makeatother
%%% end of modifications

\SHORTTITLE{Title}
\TITLE{Title}
\AUTHORS{Me}

\KEYWORDS{EJP; ECP; typesetting; \LaTeX} % Separate items with ;
\AMSSUBJ{NA} % Edit. Separate items with ;
\SUBMITTED{January 2, 2013} % Edit.
\ACCEPTED{December 13, 2014} % Edit.
\VOLUME{0}
\YEAR{2016}
\PAPERNUM{0}
\DOI{10.1214/YY-TN}

\begin{document}

\section{Introduction}

\begin{proposition}\label{prop:zeronotone}
    One has $0 \neq 1$.
\end{proposition}

\Cref{prop:zeronotone} is very useful.

\begin{theorem}\label{thm:zeronotone}
    One has $0 \neq 1$.
\end{theorem}

\Cref{thm:zeronotone} is very useful.

\end{document}

In the large lists you can of course omit the environments you don't use.

enter image description here

The added code can also be abbreviated, taking into account that all declarations are of the form \newtheorem{foo}[theorem]{Foo}:

%%% I have to redefine the theorem-like environments
%%% in order to use cleveref; output will be exactly the
%%% same, because the environments are declared in the
%%% same styles as in the class.
\makeatletter
\def\redeclare@theorems#1{%
  \@for\next:=#1\do{\expandafter\redeclare@theorem\expandafter{\next}}%
}
\def\redeclare@theorem#1{\lowercase{%
    \expandafter\let\csname #1\endcsname\relax
    \expandafter\let\csname end#1\endcsname\relax
    \newtheorem{#1}}[theorem]{#1}%
}
\theoremstyle{ejpecpbodyit}
\redeclare@theorems
 {Assumptions,Assumption,Claim,Condition,Conjecture,Corollary,%
  Definitions,Definition,Facts,Fact,Heuristics,Hypothesis,%
  Hypotheses,Lemma,Notations,Notation,Proposition}
\theoremstyle{ejpecpbodyrm}
\redeclare@theorems{Example,Exercise,Problem,Question,Remark}
\makeatother
%%% end of modifications
2

You may get around the package-loading issues posed by the ejpecp class by inserting the instruction

\RequirePackage{amsthm,nameref,hyperref,cleveref}

immediately before

\documentclass[EJP]{ejpecp}

With this setup, you won't even need the instruction \Crefname{proposition}{Proposition}{Propositions} (since it's provided by default by the cleveref package).

One doesn't usually place package-loading instructions before the \documentclass instruction. However, it's actually entirely possible to do so by using the \RequirePackage instruction.


Addendum: Here are the modified MWE (minimum working example) and an associated screenshot.

\RequirePackage{amsthm,nameref,hyperref,cleveref}
\documentclass[EJP]{ejpecp}
\begin{document}

\setcounter{section}{2} % just for this example
\begin{proposition}\label{prop:zeronotone}
One has $0 \neq 1$.
\end{proposition}
\Cref{prop:zeronotone} is very useful.
\end{document}

enter image description here

  • This solution didn't work for me, the EJP bell curve text doesn't show and many errors are given when I try it. – nullUser Nov 10 '18 at 19:14
  • @nullUser - The reason for the "many errors" is, almost certainly, the complete absence of the directives \TITLE, \SHORTTITLE, \AUTHORS, etc. You didn't provide those directives in your own code snippet. This led me to believe that you already knew how to take care of them and that you had omitted them because they weren't the focus of your inquiry. If this assumption does not apply, you might have indicated as much in your query. – Mico Nov 10 '18 at 19:43
  • you are correct that the reason title, etc. were not included in my MWE is that I already know how to take care of them and have omitted them because they were not the focus of my inquiry. Your solution did solve my reference issue but it also created new issues, such as the EJP bell curve disappearing and OTHER errors on compilation. These are likely due to other packages not mentioned in the MWE that I did not deem relevant enough to include in my MWE. I do not know which other packages are the problem, but I don't have the time or need to because the accepted answer works. – nullUser Nov 13 '18 at 17:38
1

The problem is the following: ejpecp.cls defines the "proposition" environment as

\newtheorem{proposition}[theorem]{Proposition},

which implies the environment uses the same counter as the "theorem". According to "cleveref" documentation, when you say

\Crefname{<type>}{<singular>}{<plural>},

the <type> should generally be the name of the counter for the environment (see section 8.1.2 of the documentation). Since "proposition" and "theorem" are sharing the counter, this seems to be causing the problem.

One way to obtain the desired behavior is to create labels indicating the parameter. For example,

\label[<type>]{<label>}

or, for your particular case,

\label[proposition]{prop:zeronotone}

According to cleveref's documentation, amsthm should give enough information so that environments that share the same counter should be referenced correctly. So the problem seems to be in ejpecp.cls. Indeed, if you go to the line

\newtheorem{proposition}[theorem]{Proposition}

and change it for

    \newtheorem{proposition}{Proposition}

(deleting the "[theorem]"), the problem disappears. Maybe you should report this to the authors of ejpecp.cls, so they can check the code.

One last thing: If you copy the definitions for theorems, propositions, etc. from ejpecp.cls into your LaTeX document, the problem disappears. To see this, you can add the following code to your document:

\theoremstyle{ejpecpbodyit}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{assumptions}[theorem]{Assumptions}
\newtheorem{assumption}[theorem]{Assumption}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definitions}[theorem]{Definitions}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{facts}[theorem]{Facts}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{heuristics}[theorem]{Heuristics}
\newtheorem{hypothesis}[theorem]{Hypothesis}
\newtheorem{hypotheses}[theorem]{Hypotheses}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notations}[theorem]{Notations}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{ejpecpbodyrm}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{question}[theorem]{Question}
\newtheorem{remark}[theorem]{Remark}

You should, of course, delete/comment the same lines in the .cls file so there are no clashes. This will maintain the same style as your example document, but it will not cause the problem you report. This makes me think there is something in the .cls causing the strange behavior (worth reporting it too).

I hope this helps!

  • The advice you give -- to replace \newtheorem{proposition}[theorem]{Proposition} with \newtheorem{proposition}{Proposition} in the class file -- is not likely to sit well with the journal's editing staff. Your earlier observation, that "According to cleveref's documentation, amsthm should give enough information so that environments that share the same counter should be referenced correctly" isn't entirely helpful here; the user guide of the cleveref package also states that \newtheorem directives should be issued only after both amsthm and cleveref are loaded. – Mico Nov 10 '18 at 6:50
  • Sorry, @Mico, you misunderstood my words. Actually, replacing \newtheorem{proposition}[theorem]{Proposition} with \newtheorem{proposition}{Proposition} is not an advice nor a potential solution, but is a way to explain why I believe this part of the code is causing the problem. On the other hand, reference to cleveref's documentation is an effort to discard that cleveref or amsthm are the problem here (so it has to be the class). I suppose you're right: cleveref should be loaded before \newtheorems. Perhaps the authors of the .cls could implement that for the future. – Diego Sejas Nov 10 '18 at 17:44

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.