Difference between revisions of "References"

From ConTeXt wiki
m (Add subheading)
(wikify Wolfgang's solution on how to put stopper in heading but not reference)
Line 121: Line 121:
  
 
==Putting a separator in the heading but not the reference==
 
==Putting a separator in the heading but not the reference==
 +
 +
Sometimes you want to have a separator in the heading but not the reference.  For example, you want section heading to look like "3. This is a new section" (with a dot after the section number), but references to the section should not have the dot (they should be like "In section 3 we found...").  Wolfgang Schuster gave a solution on the list:
 +
 +
<texcode>
 +
\defineprocessor[dostopper][right=.]
 +
\defineprocessor[nostopper][right=]
 +
 +
\defineconversionset[stopperconversionyes][][dostopper->n]
 +
\defineconversionset[stopperconversionnop][][nostopper->n]
 +
 +
\setuphead[chapter][sectionconversionset=stopperconversionyes]
 +
 +
%\setupreferencestructureprefix[chapter][default][prefixconversionset=stopperconversionnop]
 +
\setupreferencestructureprefix[default][prefixconversionset=stopperconversionnop]
 +
 +
\starttext
 +
 +
\chapter[one]{First heading}
 +
 +
\input knuth
 +
 +
In \in{Chapter}[one] we learn.
 +
 +
\stoptext
 +
 +
</texcode>
  
 
{{todo|Describe what the arguments of the commands do and how the commands work}}
 
{{todo|Describe what the arguments of the commands do and how the commands work}}
  
 
{{Getting started navbox}}`
 
{{Getting started navbox}}`

Revision as of 13:02, 20 April 2013

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

Starting with ConTeXt 2012.06.22, there is a third command: \contentreference[reference][framedsettings]{text} which wraps the text argument inside a \framed. The main difference with \textreference where the text contains a \framed itself is that, when interaction is enabled, \contentreference places the top left of the target area at the top left of the framed box whereas \textreference uses its baseline.

Example

\chapter[preface]{Dear Reader}

\pagereference[zapfquote]\input zapf

\dots

As I have 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)



Adjusting the level of referenced prefixes

When the default chapter and section prefixes are used, the chapters are prefixed by a number, so are the sections. When referring to a section using the command \in{section}[sec:foo] the chapter number is prefixed following by a dot and the according section number.

However, some styles do not show the chapter prefix while displaying the sections. In this case the referencing commands, like \in just output the section number, which is of course ambiguous.

To fix this problem, the command \setupreferencestructureprefix can be incorporated to adjust the prefixes displayed by the referencing commands.

Example

Given that \start/stopchapter output Romannumerals prefixes (I, II, III, …) and \start/stopsection output Character prefixes (A,B, C, …), the following commands give the results provided in the comments.

\setupreferencestructureprefix [default] [prefixsegments=2:2] % nothing
\setupreferencestructureprefix [default] [prefixsegments=2:3] % I
\setupreferencestructureprefix [default] [prefixsegments=2:4] % I.A

\setupreferencestructureprefix [default] [prefixsegments=3:4] % I.A
\setupreferencestructureprefix [default] [prefixsegments=4:4] % A
\setupreferencestructureprefix [default] [prefixsegments=5:4] % nothing


Adjusting the separator in between the referenced prefixes

To adjust the separator between the different structure levels in the referencing commands, like \in, the command \definestructureseparatorset is used.

Example

To change the separator between chapter and section from a dot to a hyphen use \definestructureseparatorset as follows.

\definestructureseparatorset [default] [,,-]

Putting a separator in the heading but not the reference

Sometimes you want to have a separator in the heading but not the reference. For example, you want section heading to look like "3. This is a new section" (with a dot after the section number), but references to the section should not have the dot (they should be like "In section 3 we found..."). Wolfgang Schuster gave a solution on the list:

\defineprocessor[dostopper][right=.]
\defineprocessor[nostopper][right=]

\defineconversionset[stopperconversionyes][][dostopper->n]
\defineconversionset[stopperconversionnop][][nostopper->n]

\setuphead[chapter][sectionconversionset=stopperconversionyes]

%\setupreferencestructureprefix[chapter][default][prefixconversionset=stopperconversionnop]
\setupreferencestructureprefix[default][prefixconversionset=stopperconversionnop]

\starttext

\chapter[one]{First heading}

\input knuth

In \in{Chapter}[one] we learn.

\stoptext


TODO: Describe what the arguments of the commands do and how the commands work (See: To-Do List)


`
https://www.contextgarden.net/index.php?title=References&diff=21550
www.contextgarden.net
crawl=CC-MAIN-2019-47
57434
application/http; msgtype=response
sha1:VBKR3TQM5HP6PDJ5PKBMJN5SBXZI7ZSY
<urn:uuid:3beb18a7-f4c6-499d-96e1-0d00f80d6a50>
2019-11-18T10:03:19Z
5.39.185.232
text/html
sha1:JQVD2KXV6WPSA5T5ZKMGGZLWZZOSFQRC
<urn:uuid:985515dc-102e-4d06-af62-9d2cedc4110c>
https://www.contextgarden.net/index.php?title=References&diff=21550
response
<urn:uuid:728db93d-44ca-4100-a3cb-21bf8062c83f>
isPartOf: CC-MAIN-2019-47
publisher: Common Crawl
description: Wide crawl of the web for November 2019
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-67-67-112.ec2.internal
software: Apache Nutch 1.16 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.1-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/