I am referencing some sections (actually those will be custom defined in the end) by number, type and name. But it happens that there is no name. So I want to leave it out. How can I test for that?
A MWE:
\documentclass{article}
\usepackage{xcolor}
\definecolor{darkred}{rgb}{0.5,0,0}
\usepackage[colorlinks, linkcolor=darkred]{hyperref}
\newcommand\doubleref[1]{\autoref{#1} (\nameref{#1})}
\begin{document}
\section{This and That about Everything}\label{sec:thisthat}
Some text.
\section{}\label{sec:two}
Like meantioned in \doubleref{sec:thisthat} and \doubleref{sec:two}.
\end{document}
So in this example the second reference should automatically only be section 2 and not section 2 ().
I tried
\newcommand\doubleref[1]{\autoref{#1}\edef\nae@tmp{\nameref{#1}}\ifx\empty\name@tmp\relax\else\ (\name@tmp)\fi}
but \nameref does not seem to return an expandable version of the name.