# How to nameref to partial part of a ref

For example, I have :

\section {first section}
\label{sec:first}\
...


then I want to refer to the first section, I use it as below:

Please look at \nameref{first} for details.


I will get:

Please look at first section for details.

But if I only want this (without section, only partial part of the reference):

Please look at first for details.

How should I do to get it?

I guess a better example would be:

\section{data.h File Description}
\label{sec:datah}
....
Details are given in \nameref{datah}.


What I really want is:

Details are given in data.h.

But I get:

Details are given in data.h File Description.

I hope this example is clear enought. Is there any way to do this?

-

## migrated from stackoverflow.comSep 22 '12 at 17:33

This question came from our site for professional and enthusiast programmers.

Do you always use \section{first section} ... \section{second section} ... \section{some section}, or does it differ sometimes? Since the sections are numbered and the output is 1 First section, you should consider just writing \section{First} which will output 1 First and yield the appropriate \nameref you're after. – Werner Sep 21 '12 at 17:59
Thanks for your reply. Here it is only an example, not the real contents. – user1558064 Sep 21 '12 at 18:06
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Sep 22 '12 at 17:56
\nameref is not a standard LaTeX command. Please provide a minal example. – Marc van Dongen Sep 22 '12 at 18:13

Since the required return from a \nameref might be anywhere inside the title of a \section, you can use \labelname{<stuff>} as defined below to update the reference text returned:

\documentclass{article}
\usepackage{nameref}% http://ctan.org/pkg/nameref
\makeatletter
\newcommand{\labelname}[1]{% \labelname{<stuff>}
\def\@currentlabelname{#1}}%
\makeatother
\begin{document}
\section{\texttt{data.h} File Description}
\labelname{\texttt{data.h}}\label{sec:datah}% Overwrite title name/reference
Also see \nameref{sec:dataj}.

\section{File Description for \texttt{data.j}}
\label{sec:dataj}% Keep regular title reference
Details are given in \nameref{sec:datah}.
\end{document}


nameref stores the name of the previous title in \@currentlabelname, which is overwritten using \labelname.

This is also compatible with hyperref.

-
The important thing is that \labelname comes before \label. The solution also does not change the label in the TOC. :thumbsup: – koppor Nov 14 '13 at 9:50