Changes

Jump to navigation Jump to search
9,603 bytes added ,  20:17, 2 April 2013
→‎Styling the Index: add instructions for mkiv
=Styling the Index=
 
Registers consist of three text elements that can be styled
independently:
the sections headings, the entry text, and a page number (reference).
For formatting purposes each has its own key so it can be referred to
consistently:
 
* <tt>style</tt> refers to the style of ''headings''; ordinarily these are the letters of the alphabet.
* <tt>textstyle</tt> refers to the typeset content of an entry;
* <tt>pagestyle</tt> refers to the typeset page number of an entry;
* page numbers are references so their appearance depends on the [[Interaction|interaction]] settings as well.
 
== MkIV ==
 
=== General Setup ===
The appearance of a register can be configured with {{cmd|setupregister}}.
An example setup for the register ''entity'' could look like:
 
<texcode>
\defineregister [entity]
\setupregister [entity] [
style=sansbold, %% headings
textstyle=slanted, %% entries
pagestyle=bolditalic, %% page refs
n=1, %% columns
]
</texcode>
 
This typesets sections in bold face sans serif, entries with slant, and
page references in italic.
Also, the register will use a single column.
 
In MkIV {{cmd|setupregister}} is consistent with the common interface
to [[Style_Alternatives|text style]].
Thus for every <tt>style</tt> there is a corresponding <tt>color</tt>
option (''color'', ''textcolor'', and ''pagecolor''):
 
<texcode>
\setupregister [entity] [
color=red,
textcolor=green,
pagecolor=blue,
]
</texcode>
 
Naturally, self-defined alternatives are valid as well:
 
<texcode>
\definefontfeature [textfigures] [onum=yes]
 
\definealternativestyle [reg:bigbold] [\bfc] []
\definealternativestyle [reg:tinybold] [\bfxx] []
\definealternativestyle [reg:bignum] [\tfc\addff{textfigures}] []
 
\defineregister [entity]
\setupregister [entity] [
style=reg:bigbold,
textstyle=reg:tinybold,
pagestyle=reg:bignum,
]
</texcode>
 
Use with care!
 
=== Processors ===
 
The [[Registers#Individiual_Entries|traditional approach]] to
fine-tuning entries has not (yet?) been implemented in MkIV
[http://www.ntg.nl/pipermail/ntg-context/2013/070961.html].
Instead, there is a new mechanism called ''processors'' available that
has a similar effect.
 
Processors are created via {{cmd|defineprocessor}}:
 
<texcode>
\defineprocessor [relevant] [style=italic]
</texcode>
 
To apply it to a register entry, we employ the <tt>-&gt;</tt> operator:
<texcode>
Text \entity{foo}text.
Text \entity{relevant->bar}text.
Text \entity{baz}text.
</texcode>
 
This will render ''bar''’s entry in the register ''entity'' in italic
font, while the other two entries remain unchanged.
 
<context mode=mkiv source=no>
\defineregister [entity]
\setupregister [entity] [
style=sansbold,
textstyle=normal,
pagestyle=bolditalic,
n=1,
]
 
\defineprocessor [relevant] [style=italic]
 
\starttext
\placeentity \page
 
Text before.
Text \entity{foo}text.
Text \entity{relevant->bar}text.
Text \entity{baz}text.
Text after.
\stoptext
</context>
 
A processor is not local to a specific register (as it was in MkII).
Once defined it can be applied to different registers, yielding the
same effect:
 
<texcode>
\defineregister [first]
\defineregister [second]
\defineregister [third]
\defineprocessor [relevant] [style=italic,color=blue]
\starttext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\placefirst \placesecond \placethird \page
Text before.
Text \first {foo} \first {relevant->bar 1} \first {baz}text.
Text \second{foo} \second{relevant->bar 2} \second{baz}text.
Text \third {foo} \third {relevant->bar 3} \third {baz}text.
Text after.
\stoptext %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
</texcode>
 
The same processor can be applied to to both entries and page numbers.
(Another difference from MkII.)
For page numbers, apply the <tt>-&gt;</tt> operator on the optional
first argument:
 
<texcode>
\entity[relevant->]{foo}
</texcode>
 
Note that <code>\entity[weird]{foo}</code> is not enough.
Without the <tt>-&gt;</tt>, the first argument is interpreted as sort
key.
However, if in addition to the page number processor you wish to supply
a custom sort key, then the sort key must follow the processor:
 
<texcode>
\entity[relevant->baz]{foo}
</texcode>
 
In this example, the page number will be displayed using the processor
''relevant'' and the entity ''foo'' will be treated like the string
''baz'' for sorting purposes.
Of course, page number and text formatting can be combined:
 
<texcode>
\entity[relevant->]{relevant->foo}
</texcode>
 
Processors work well with multi-level indices:
 
<texcode>
\entity {relevant->foo}
\entity {relevant->foo+bar}
\entity {relevant->foo+bar+baz}
</texcode>
 
''Applying multiple processors to a single entry has no effect.''
Context will ignore any other processor after the first.
(This is probably a feature, as there is no need to repeat the
processor with every entry.)
However, different entries in the page reference list can be formatted
differently:
 
<context mode=mkiv source=yes>
\setupcolor[rgb]
\defineregister [stuff] [style=sansbold,pagestyle=italic,n=1]
\defineprocessor [relevant] [style=bold,color=red]
\defineprocessor [irrelevant] [color=darkgray]
 
\starttext
\placestuff
 
\page Text \stuff {relevant->foo} text.
\page Text \stuff {foo} text.
\page Text \stuff [relevant->] {foo} text.
\page Text \stuff {irrelevant->foo} text. %% no effect!
\page Text \stuff [irrelevant->] {foo} text.
\stoptext
</context>
 
=== Examples ===
==== Simple Setup ====
 
<context mode=mkiv source=yes>
\defineregister [entity]
\setupregister [entity] [
style=sansbold,
textstyle=slanted,
pagestyle=bolditalic,
n=1,
]
 
\starttext
 
\placeentity \page
 
Text before.
Text \entity{foo} \entity{bar} text.\page
Text \entity{foo} \entity{baz} text.\page
Text \entity{foo} \entity{bar} text.\page
Text \entity{foo} \entity{xyzzy} text.\page
Text after.
\stoptext
</context>
 
==== Colorful Setup ====
 
<context mode=mkiv source=yes>
\defineregister [entity]
\setupregister [entity] [
color=red,
textcolor=green,
pagecolor=blue,
n=1,
]
 
\starttext
 
\placeentity \page
 
Text before.
Text \entity{foo} \entity{bar} text.\page
Text \entity{foo} \entity{baz} text.\page
Text \entity{foo} \entity{bar} text.\page
Text \entity{foo} \entity{xyzzy} text.\page
Text after.
\stoptext
</context>
 
==== Setup with Alternatives ====
 
<context mode=mkiv source=yes>
\definefontfeature [textfigures] [onum=yes]
 
\definealternativestyle [reg:bigbold] [\bfc] []
\definealternativestyle [reg:tinybold] [\bfxx] []
\definealternativestyle [reg:bignum] [\tfc\addff{textfigures}] []
 
\defineregister [entity]
\setupregister [entity] [
style=reg:bigbold,
textstyle=reg:tinybold,
pagestyle=reg:bignum,
]
 
\starttext
 
\placeentity \page
 
Text before.
Text \entity{foo} \entity{bar} text.\page
Text \entity{foo} \entity{baz} text.\page
Text \entity{foo} \entity{bar} text.\page
Text \entity{foo} \entity{xyzzy} text.\page
Text after.
\stoptext
</context>
 
==== Complex Setup ====
 
<texcode>
\definefontfeature [textfigures] [onum=yes]
 
\definealternativestyle [reg:heada] [\WORD\ssa\bold]
\definealternativestyle [reg:headb] [\word\tfb\sc]
\definealternativestyle [reg:pageno] [\addff{textfigures}\italic]
 
\defineregister [entity] [style=reg:heada,pagestyle=normal,n=3]
\defineregister [object] [style=reg:headb,pagestyle=reg:pageno,n=2]
 
\defineprocessor [relevant] [style=italic]
\defineprocessor [weird] [style=italic,color=red]
\defineprocessor [striking] [style=bold,color=blue]
 
\starttext
 
\placeentity \blank[3*big] \placeobject \page
 
\dorecurse{3}{
Text before.
\page Text \entity {foo} text.
Text \object {striking->bar} text.
Text \entity {baz+foo} text.
Text \object {foo+bar} text.
\page Text \entity[relevant->] {weird->foo} text.
\page Text \entity {weird->bar} text.
Text \object[weird->] {foo} text.
Text \object {baz} text.
\page Text \entity[weird->foo] {foo} text.
\page Text \entity[weird->] {baz} text.
Text \object {baz} text.
Text \object {bar+baz} text.
Text \entity[weird->] {baz} text.
Text \entity {baz+miranda} text.
Text \entity {baz+xyzzy} text.
Text \object {foo} text.
\page Text \entity {weird->foo} text.
Text \object[striking->] {bar+baz} text.
Text \object {foo} text.
Text \entity[relevant->] {baz+xyzzy} text.
\page Text \entity[weird->foo] {foo} text.
Text \object {bar+xyzzy} text.
Text \object {baz} text.
Text \object {foo} text.
Text \entity[weird->] {baz+xyzzy+meh} text.
\page Text \entity[weird->] {weird->foo} text.
Text \object[striking->] {foo} text.
Text \object {xyzzy} text.
Text \entity {baz+xyzzy} text.
Text after.
}
 
\stoptext
</texcode>
 
== MkII ==
\stoptext
</texcode>
category>+
/context>
 
==== Colorful Setup ====
=More Registers=
188

edits

Navigation menu