[Tex/LaTex] \nameref — How to display section name AND its number

cross-referencinghyperrefnumbering

Is it possible to make \nameref display not only the title of the section but also its number?

\section{First Section}
\label{sec:some_sec}

\subsection*{Unnumbered subsection}
\label{sec:subsec}

[...]

As we defined in section \nameref{sec:some_sec}, yada yada yada, see section \nameref{sec:subsec}

With normal \nameref I get:

"As we defined in section First Section, yada yada yada, see section Unnumbered subsection"

what I want is a combination of numbers (as in \autoref} and section names AND (if possible) unnumbered subsections should inherit the number of the parenting section:

"As we defined in section 1 First Section, yada yada yada, see section 1 Unnumbered subsection"

Best Answer

How about defining a new command \fullref:

\documentclass{article}
\usepackage[colorlinks=true]{hyperref}

% Original definition
% \newcommand\fullref[1]{\autoref{#1} \nameref{#1}} % Two links

% Updated definition, see explanation below
\newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}} % One single link

\begin{document}

\section{First Section}
\label{sec:some_sec}

\subsection*{Unnumbered subsection}
\label{sec:subsec}

[...]

As we defined in \fullref{sec:some_sec}, yada yada yada, see \fullref{sec:subsec}

\end{document}

enter image description here


Update

The \fullref defined above produces two links, one by \autoref, the other by \nameref. Heiko Oberdiek suggests the following definition that combines the two into one single link:

\newcommand*{\fullref}[1]{\hyperref[{#1}]{\autoref*{#1} \nameref*{#1}}}