References

From ConTeXt wiki
Revision as of 10:57, 29 April 2009 by 130.89.11.138 (talk) (→‎Example: Sync context code compiled and shown)
Jump to navigationJump to search

< Structurals | Bibliography >

If you want to refer to any text element, you must first define the target's reference label. All titling commands and a lot of others take one as optional parameter, e.g.

\chapter[preface]{Dear Reader}

Then you can refer to this spot with

As I told you in \in{chapter}[preface] on \at{page}[preface], I really like ConTeXt...

That will typeset the text in braces and add the number of the refered element, e.g. "chapter 1 on page 1".

To define a reference label anywhere you can also use \pagereference[reference] and \textreference[reference]{text}. Everwhere where you can define one label, you can also define more at once, if you separate them with commas. It's also possible to use "namespaces" like [fig:cow].

If you activated interaction, references become links automatically.

Example

\chapter[preface]{Dear Reader}

\pagereference[zapfquote]\input zapf

\dots

As I told you in \in{chapter}[preface] on \at{page}[preface], I really like \ConTeXt.
And Mr.\,Zapf (see \at{page}[zapfquote]) at least likes \TeX\ in general.

Different layouts for different kinds of references

If you want less typing to get special formatting for the references to sections, equations, ... here's Aditya's recipe to do it.

Suppose that you want to get

See equation (2.3) or section 4.2.

where the slanted content is typeset automatically. You first need to define the formatting with \definereferenceformat:

\definereferenceformat[insec][text=section]
\definereferenceformat[ineq] [left=(,right=),text=equation]

Then you can simply type

See \ineq[eq:some equation] or \insec[sec:some section].

A more automated solution uses the following macro:

\def\myin[#1:#2]{%
  \expandafter\ifx\csname in#1\endcsname\relax
    \writestatus{warning}{referenceformat in#1 not defined}%
    \in[#1:#2]%
  \else
    \csname in#1\endcsname[#1:#2]%
  \fi}

and requires you to write the following code:

See \myin[eq:some equation] or \myin[sec:some section].

TODO: complete example would be better (See: To-Do List)