[Tex/LaTex] Reference that includes section number and name

cross-referencinghyperref

I'm trying to refer (hyperlink preferably) to another section, or in this spesific case a subsection. I've fixed the problem by creating a new command:

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

So I can type:

As seen in \fullref{subsec:options}.

Which outputs:

As seen in 2.2 Our options.

(The reference being a hyperlink)

Is there any easy way to do this without creating a new command?

Edit: As mentioned by Fran, note that the name \fullref is already used by another package and should be avoided.

Best Answer

Is there any easy way to do this without creating a new command?

Short answer: No.

Long Answer:

Well, of course, you can include this macro in your own package, or in an external macros.tex and then use \input{macros} in the preamble, in order to reuse it and maintain a clear preamble.

But actually this feature is not included in any package (as far I know). Actually there are commands as \cref or \vref, \fullref or \autoref in some packages to obtain together the reference number with the type of reference (section, figure, etc) and/or the page reference (on page 2, on the next page, etc.) but not the equivalent to \ref + \nameref.

Even if you are able to set up some package from the label-reference topic in CTAN to do this, probably the fix will be more complex that this simple macro.

On the other hand, note that among the above cited commands appear \fullref as a already defined command in varioref package, and this is not what you are looking for. Thus, you should choose a different name for your macro (even if you are not using that package, the use of the same name is asking for future problems).

One last option may be ask for this feature to the developers of hyperref or another package about cross-references, who know... A funny quote from the fancyref manual (page 2), explaining the reasons to make this package:

Some lazy people soon had the idea to write a \fullref command to save some keystrokes:

\newcommand*{\fullref}[1]{\ref{#1} on page~\pageref{#1}}

No offence intended with the mention to "lazy people". I am also a terrible lazy typist. The point is show that developers want to help to lazy typists (At the end, LaTeX and most packages were created for that reason) ;)

(Note also that the cite include a \fullref definition different from that of varioref.sty. Although is a example of what not to do, is another reason to search a more original name.)