1

I had a problem that was solved in a previous question, and that now is coming back.

The idea was to use \ref for internal links with color A, and \cref with nameinlink option in cleveref (!) and color B for links with mathematical content.

Audrey Blumsohn kindly provided me the following solution:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames]{xcolor}
\newtheorem{theorem}{Theorem}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage[noabbrev,capitalise,nameinlink]{cleveref}
\hypersetup{colorlinks={true},linkcolor={blue},citecolor=green}

\newcommand{\mref}[3][red]{\hypersetup{linkcolor=#1}\cref{#2}{#3}\hypersetup{linkcolor=blue}}%<<<changed

\begin{document}
\section{Bla}
\label{sec:bla}
\begin{theorem}
\label{th:gauss}
Gauss
\end{theorem}

\section{blabla}

In section \ref{sec:bla} we found \mref{th:gauss}

And again \ref{sec:bla} we found \mref{th:gauss}

\end{document}

But still there is a problem. Namely, this solution does not work when I use it for cross-referencing in a proof environment, to get something like

Proof of the theorem 1.

that in principle I should write

\begin{proof}[Proof of \mref{thm:1}]

with 'theorem 1' written by using \mref.

Is there a way to get the result?

Thanks a lot in advance!

2
  • The link is missing
    – egreg
    Commented Jun 30, 2015 at 19:43
  • Even if was late, I added the link.
    – Kolmin
    Commented Jun 30, 2015 at 19:54

1 Answer 1

2

The command \cref only wants a single argument, not two.

\newcommand{\mref}[2][red]{%
  \hypersetup{linkcolor=#1}%
  \cref{#2}%
  \hypersetup{linkcolor=blue}%
}

This will solve the problem.

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames]{xcolor}


\usepackage{varioref}
\usepackage{hyperref}
\usepackage[noabbrev,capitalise,nameinlink]{cleveref}
\hypersetup{colorlinks={true},linkcolor={blue},citecolor=green}

\newtheorem{theorem}{Theorem}

\newcommand{\mref}[2][red]{%
  \hypersetup{linkcolor=#1}%
  \cref{#2}%
  \hypersetup{linkcolor=blue}%
}

\begin{document}
\section{Bla}
\label{sec:bla}
\begin{theorem}
\label{th:gauss}
Gauss
\end{theorem}

\begin{proof}[Proof of \mref{th:gauss}]
Obvious.
\end{proof}

\section{blabla}

In section \ref{sec:bla} we found \mref{th:gauss} which is nice.

And again \ref{sec:bla} we found \mref{th:gauss} which is nice.

\end{document}

enter image description here

2
  • May I ask you something? When I use \mref I have a spacing problem (the word that comes next is just attached to the cross-referenced one, without spacing). Can this be fixed?
    – Kolmin
    Commented Jun 30, 2015 at 20:04
  • No, you don't, with the definition I gave. See edit.
    – egreg
    Commented Jun 30, 2015 at 20:05

You must log in to answer this question.

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