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:

\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.

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Is there any problem with defining a new macro? I don't think this is possible without a customized macro. – user11232 Mar 4 '14 at 0:42
  • No, since hyperref (Heiko?) didn't consider every possible way people would want to use it. Why does using \fullref not feel right? Even if you were to patch \ref to do this automatically, it would technically be similar in nature to creating a new command. Moreover, if you use \fullref as-is and change your mind later, it's easy to modify it to be equivalent to \ref. – Werner Mar 4 '14 at 1:05
  • are you looking for the \autoref command from package hyperref? it does not include the name, only the number but it does say section, or subsection etc... – user4686 Mar 4 '14 at 10:30
  • This nice question illustrates several lovely things about TeX. First, you can make it do pretty much whatever you want. Second, it may already do what you want. Third, this community can answer your questions and point you in good directions. Thanks for asking. – Ethan Bolker Mar 8 '14 at 13:31

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.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.