What is the (preferred way of) defining a command that

  • places a heading (like \section, \chapter, etc.)
  • creates a label for this heading that can be referenced
  • places the heading in the TOC (I think the TOC part is pretty automatic, yes?)
  • places the heading in the index

and what is the (preferred way of) defining a referencing command that

  • places a reference to the heading with the name of the heading and it's page number
  • makes this reference a Link when generating a PDF
  • maybe some options on how the referencing should be spelled out

and what packages are needed for this?


\headx[label1]{This is a heading}
\headxx[label12}]{Some sub-heading}
For further details, see \headreference[style=short]{label1}.

(edit) Note: [style=...] could control what details are inserted. E.g. short could mean to only insert the section name as link (and skip the section number and page). Fullcould mean to also insert section number and page as text for the link. (This is just an example to show that I think that such a command should probably have some fine-tuning switches.)

  • What is the [style=short] supposed to do?
    – TH.
    Sep 20, 2010 at 19:29

1 Answer 1


The hyperref package can help you to do pretty much all what you're asking for. Have a look at it's documentation (e.g. by running texdoc hyperref on a command line) and have a close look at the section on “Additional user macros”. Here are some macro definitions to get you started:


  \hyperref[#1]{\autoref*{#1} with title `\nameref*{#1}' in page \pageref*{#1}}%


\mychapter[hello]{Hello World}

This is \verylongref{hello}.


Note that the \mychapter command has the interface you we're looking for, but it has two problems: the “optional” argument is not really optional since (of course) you do need a label to assign to the chapter; and, moreover, \chapter already had an optional argument (which is used as a short title for running headers) and now it's no longer accessible with the \mychapter command. Maybe it's better just to keep writing \chapter{..}\label{..}?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .