# Referencing Definition by Name and Optional Argument

I have the following MWE:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}

\newtheorem*{definition}{Definition}

\begin{document}

\section{Section Definitions}

\begin{definition}[symmetric matrix]
\label{def:sym.mat}
A quadratic matrix $X$ is called \emph{symmetric}, if $X^{\dagger} = X$.
\end{definition}

This is a reference to \autoref{def:sym.mat}.
\end{document}


The Output of the reference sentence is:

This is a reference to section 1.

I want to get:

This is a reference to Definition (symmetric matrix).

I know how to cross-reference different theorem-like environments like lemma, theorem with the aliascnt package. But my definitions, unlike theorems, are not numbered but instead contain an unique phrase in rectangular brackets on what they define.

Is there a way to overload \label and \ref or \autoref so that the displayed text for the reference is the composite of the environment name (here 'Definition') and the optional argument (here 'symmetrix matrix')? Maybe analog to this answer in Reference name of description list item in LaTeX.

I want to avoid defining a manual reference display text for each definition environment. I guess I somehow have to update \@currentlabel with \thmnote?
If this questions was already asked & answered, I am happy if somebody points me to it.

-
Maybe trying with cleveref? – Bernard Jul 23 '14 at 12:30

Help \autoref by telling it what kind of reference it's defined.

A new counter is needed so that \autoref will use it for its purpose; next a name for it is needed; then the counter is refstepped when the optional argument is found and the label is set to the name in parentheses.

\documentclass{article}
\usepackage{amsthm}
\usepackage{xparse}
\usepackage{hyperref}

\newtheorem*{innerdefinition}{Definition}
\newcounter{definition}
\providecommand{\definitionname}{Definition}

\makeatletter
\NewDocumentEnvironment{definition}{o}
{%
\IfValueTF{#1}
{\innerdefinition[#1]\refstepcounter{definition}\def\@currentlabel{(#1)}}%
{\innerdefinition}%
}
{%
\endinnerdefinition
}
\makeatother

\begin{document}

\section{Section Definitions}

\begin{definition}[symmetric matrix]
\label{def:sym.mat}
A quadratic matrix $X$ is called \emph{symmetric}, if $X^{\dagger} = X$.
\end{definition}

This is a reference to \autoref{def:sym.mat}.
\end{document}


-
I accepted this answer because for Andrew's answer to work I'd have to redefine my definition environment. – Marco Breitig Jul 23 '14 at 14:37
@MarcoBreitig ...or you could just interchange the roles of Definition and definition in my solution:) – Andrew Jul 24 '14 at 8:42
@egreg there any way to obtain this without hyperref package? – juanuni Jun 7 '15 at 16:08
@juanuni What's the problem with hyperref? – egreg Jun 7 '15 at 16:19
Well, usually I no use this package (is due I no need it) – juanuni Jun 7 '15 at 16:46

Look's like egreg beat me to it, but here is a similar, marginally simpler, solution:

\documentclass{amsart}
\textwidth=20cm\parindent=0pt
\usepackage{amsthm}

\newtheorem*{definition}{Definition}

\makeatletter
\newenvironment{Definition}[1][\relax]%
{\ifx\relax#1\definition\def\@currentlabel{Definition}%
\else\definition[#1]\def\@currentlabel{Definition (#1)}%
\fi}
{\enddefinition}
\makeatother

\begin{document}

\begin{Definition}[symmetric matrix]
\label{def:sym.mat}
A quadratic matrix $X$ is called \emph{symmetric}, if $X^{\dagger} = X$.
\end{Definition}

This is a reference to \autoref{def:sym.mat}.

\end{document}


This produces:

-
The conditional is wrong; try \begin{Definition}[MM]. It should be \ifx\relax#1\relax (but it would fail with the admittedly contrived \begin{Definition}[\relax ABC]). – egreg Jul 23 '14 at 13:01
No, I think it's right (you probably saw it mid edit). – Andrew Jul 23 '14 at 13:01
No, it's wrong, the MM case will follow the true branch. – egreg Jul 23 '14 at 13:03
Ah, I see what you mean. Fixed. Thanks. – Andrew Jul 23 '14 at 13:08
You missed the \relax after #1 that's meant to cover the case \begin{Definition}[] (maybe the author hasn't decided the name yet): in this case \ifx would compare \relax to \definition and gobble the latter: chaos ensues. – egreg Jul 23 '14 at 13:13