# Using \autoref with tcolorbox

Is there a way to refer to a tcolorbox created theorem (created with \newtcbtheorem) using hyperref's \autoref?

I've tried to set \<name>autorefname, as I would have done it for a theorem created with \newtheorem, but it does not seem to work for \newtcbtheorem:

\documentclass{article}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

% tcolorbox theorem
\newtcbtheorem{evidence}{Evidence}{}{ev}
\newcommand{\evidenceautorefname}{Evidence}

% classic theorem
\newtheorem{classicevidence}{Evidence}
\newcommand{\classicevidenceautorefname}{Evidence}

\begin{document}
Find the most important text
in~\autoref{ev:one} % Does not work correctly
and in~\autoref{ev:two}. % Works as expected

\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}

\begin{classicevidence}
\label{ev:two}
This is the classic evidence.
\end{classicevidence}
\end{document}

-
Please post an entire MWE (minimum working example) that show what you've tried so far. As a minimum, please show the exact code you use when creating a new theorem-like environment via \newtcbtheorem. – Mico May 23 '14 at 12:00

When you process your sample document, you get thw warning

Package hyperref Warning: No autoref name for
tcb@cnt@evidence' on input line 18.


which shows that autorefdoesn't recognize the new environment and also shows you the internal name associated to it: tcb@cnt@evidence so, internally, your environment's name is not evidence but tcb@cnt@evidence, which explains why your attempt failed. You need to let autoref know about tcb@cnt@evidence:

\newcommand\tcb@cnt@evidenceautorefname{Evidence}


The code:

\documentclass{article}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

% tcolorbox theorem
\newtcbtheorem{evidence}{Evidence}{}{ev}
\makeatletter
\newcommand\tcb@cnt@evidenceautorefname{Evidence}
\makeatother
% classic theorem
\newtheorem{classicevidence}{Evidence}
\newcommand{\classicevidenceautorefname}{Evidence}

\begin{document}
Find the most important text
in~\autoref{ev:one} % Does not work correctly
and in~\autoref{ev:two}. % Works as expected

\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}

\begin{classicevidence}
\label{ev:two}
This is the classic evidence.
\end{classicevidence}
\end{document}


-
Nice explanation how to interpret the warning. Works as expected. – Manuel Faux May 23 '14 at 13:03

The tcolorbox package provides some nice hooks to make it cooperate with the cleveref package. The solution consists of (a) providing a "label type" when setting up the the theorem and then using a \crefname instruction to tell cleveref how to typeset cross-references of that label type. Finally, the command \cref of the cleveref package can be made to generate cross-references with a look that's identical to that generated by \autoref by loading the cleveref package with the nameinlink option.

For a detailed discussion of various LaTeX cross-referencing packages and macros, including \autoref and \cref, see the posting Cross-reference packages: which to use, which conflict and the associated answers.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

% tcolorbox theorem
\newtcbtheorem{evidence}{Evidence}{label type=evidence}{ev}

\usepackage[nameinlink]{cleveref} % make \cref emulate look of \autoref
\crefname{evidence}{Evidence}{Evidence}

\begin{document}
\noindent
Find the most important text in~\cref{ev:one}. % Now works as expected

\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}
\end{document}

-

You can also use a counter of your liking for \newtcbtheorem. In the following code, the counter classicevidence is taken which would allow a mixed running of both environments.

Alternatively, use \newcounter{mynicecounter} and give this counter to \newtcbtheorem by use counter=mynicecounter.

\documentclass{article}
\usepackage{hyperref}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

% classic theorem
\newtheorem{classicevidence}{Evidence}
\newcommand{\classicevidenceautorefname}{Evidence}

% tcolorbox theorem
\newtcbtheorem[use counter=classicevidence]{evidence}{Evidence}{}{ev}

\begin{document}
Find the most important text
in~\autoref{ev:one} % Works as expected
and in~\autoref{ev:two}. % Works as expected

\begin{evidence}{This is the evidence}{one}
Nothing really important to show here.
\end{evidence}

\begin{classicevidence}
\label{ev:two}
This is the classic evidence.
\end{classicevidence}
\end{document}
`

-