1

I have a problem with the cleveref that is exemplified in the following piece of code.

\documentclass[12pt]{article}

\usepackage{amsmath}%
\usepackage{amsthm}%

\theoremstyle{plain}
%
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}
\newtheorem{conjecture}{Conjecture}


\theoremstyle{definition}
%
\newtheorem{condition}[theorem]{Condition}
\newtheorem{problem}{Problem}


\usepackage{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}
%
\hypersetup{colorlinks=true}
%
\newcommand{\MathRef}[2][blue]{%
\hypersetup{linkcolor=#1}%
\Cref{#2}%
\hypersetup{linkcolor=blue}%
}


\begin{document}

\begin{definition}[Bla]
\label{bla}
Bla
\end{definition}

\MathRef{bla}

\begin{problem}[Blabla]
\label{blabla}
Blabla
\end{problem}

\MathRef{blabla}

\begin{condition}[Blabla]
\label{blablabla}
Blabla
\end{condition}

\MathRef{blablabla}

\begin{conjecture}[Bla]
\label{bla1}
Bla
\end{conjecture}

\MathRef{bla1}

\end{document}

As it can be noticed, the command MathRef works well only in the first case, while in the others for – I guess – different reasons, it does not. It looks like cleveref misses the name of some of these environements.

What is the issue?
How can it be solved?

Any feedback will be mostly appreciated.

1 Answer 1

3

The theorem definitions are occuring too early, i.e. before cleveref is loaded, as such, cleveref has no 'grip' to provide a correct \crefname etc.

Push the definitions after loading cleveref.

The reason, why theorem and definition work out of the box is that cleveref has a built-in support for those theorem names (better counters) already.

\documentclass[12pt]{article}

\usepackage{amsmath}%
\usepackage{amsthm}%


\usepackage{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}


\theoremstyle{plain}
%
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}
\newtheorem{conjecture}{Conjecture}


\theoremstyle{definition}
%
\newtheorem{condition}[theorem]{Condition}
\newtheorem{problem}{Problem}


%
\hypersetup{colorlinks=true}
%
\newcommand{\MathRef}[2][blue]{%
  \hypersetup{linkcolor=#1}%
  \Cref{#2}%
  \hypersetup{linkcolor=blue}%
}


\begin{document}

\begin{definition}[Bla]
\label{bla}
Bla
\end{definition}

\MathRef{bla}

\begin{problem}[Blabla]
\label{blabla}
Blabla
\end{problem}

\MathRef{blabla}

\begin{condition}[Blabla]
\label{blablabla}
Blabla
\end{condition}

\MathRef{blablabla}

\begin{conjecture}[Bla]
\label{bla1}
Bla
\end{conjecture}

\MathRef{bla1}

\end{document}

enter image description here

2
  • Thanks a lot! Indeed it works fine. But – just out of curiosity – why did it work before but only for definition and not for the others?
    – Kolmin
    Commented Jan 15, 2018 at 13:39
  • 1
    @Kolmin: definition is already provided by cleveref since that environment name occurs quite often.
    – user31729
    Commented Jan 15, 2018 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .