Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

Example:

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

share|improve this question
    
What is the [style=short] supposed to do? –  TH. Sep 20 '10 at 19:29
add comment

1 Answer

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:

\documentclass{book}
\usepackage{hyperref}

\newcommand{\mychapter}[2][???]{\chapter{#2}\label{#1}}
\newcommand{\verylongref}[1]{%
  \hyperref[#1]{\autoref*{#1} with title `\nameref*{#1}' in page \pageref*{#1}}%
}

\begin{document}

\mychapter[hello]{Hello World}

This is \verylongref{hello}.

\end{document}

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{..}?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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