https://wiki.contextgarden.net/api.php?action=feedcontributions&user=128.187.165.186&feedformat=atomWiki - User contributions [en]2024-03-29T07:24:39ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=Registers&diff=6549Registers2006-09-06T00:18:39Z<p>128.187.165.186: /* Tricks */</p>
<hr />
<div>< [[Structurals]] | [[References]] > (It's also in the manual at "Registers")<br />
<br />
=Basics=<br />
<br />
Putting a word into the index as simple as <cmd>index</cmd><tt>{word}</tt>. (Always type <cmd>index</cmd> ''before'' the word you refer to!)<br />
<br />
To sort e.g. <cmd>ConTeXt</cmd> under "C", you write <cmd>index</cmd><tt>[CONTEXT]{\ConTeXt}</tt>.<br />
<br />
If you need multiple levels (up to three), use "+" or "&" separators like in <cmd>index</cmd><tt>{beans+baked}</tt>.<br />
<br />
You get a cross reference in your index with <cmd>seeindex</cmd> like in <cmd>seeindex</cmd><tt>[CONTEXT]{\ConTeXt}{\TeX}</tt> (ConTeXt: see TeX).<br />
<br />
To typeset the index, use <cmd>placeindex</cmd> (without title) or <cmd>completeindex</cmd> (with titling).<br />
<br />
==Example==<br />
<texcode><br />
My \index{dog}dog is a \index{dog+bullterrier}bullterrier named \seeindex{Dolly}{Underware}Dolly.<br />
He doesn't like \index{cat}cats.<br />
There are a lot of \index{cat+stray}stray cats, but only a few of them are \index{cat+Siamese}Siamese.<br />
<br />
\placeindex<br />
</texcode><br />
<context><br />
\tfx<br />
My \index{dog}dog is a \index{dog+bullterrier}bullterrier named \seeindex{Dolly}{Underware}Dolly.<br />
He doesn't like \index{cat}cats. There are a lot of \index{cat+stray}stray cats, but only a few of them are \index{cat+Siamese}Siamese.<br />
<br />
\placeindex<br />
</context><br />
<br />
=Styling the Index=<br />
<br />
<cmd>setupregister</cmd><tt>[index]</tt> is your friend. <cmd>placeindex</cmd> and <cmd>completeindex</cmd> take the same options.<br />
<br />
You can also style single entries with the :: syntax like this (from the manual):<br />
<br />
<texcode><br />
\setupregister[index][form][pagestyle=bold,textstyle=slanted]<br />
\setupregister[index][tb][textstyle=bold]<br />
\setupregister[index][nb][pagestyle=bold]<br />
\setupregister[index][hm][pagestyle=slanted]<br />
<br />
\index{tb::foot+squarefoot} % text in "tb" style<br />
\index[nb::]{squareroot} % number in "nb" style<br />
\index[hm::root]{$\sqrt{2}$} % number in "hm" style, sorted at "root"<br />
</texcode><br />
<br />
=More Registers=<br />
<br />
<cmd>index</cmd> is only one special case of <cmd>register</cmd>. You can define as much different registers as you like:<br />
<br />
<cmd>defineregister</cmd><tt>[singular name][plural name]</tt>, e.g. <br />
<texcode><br />
\defineregister[mouse][mice]<br />
\setupregister[mouse][style=\ss]<br />
<br />
\mouse{rat}<br />
<br />
\placemouse<br />
</texcode><br />
<br />
(Don't know if the plural form is used anywhere...)<br />
<br />
=Tricks=<br />
<br />
* <cmd>startregister</cmd><tt>[index][mymouse]{mouse}</tt> ... <cmd>stopregister</cmd><tt>[index][mymouse]</tt>: to mark several pages for the same entry; becomes e.g. "mouse 12--16". Note that if you have two or more of these ranges, you need them to have different <tt>[key]</tt> values to stop the system treating them as part of a great big range. So, use <cmd>startregister</cmd><tt>[index][mymouse1]{mouse}</tt> ... <cmd>stopregister</cmd><tt>[index][mymouse1]</tt> and then <cmd>startregister</cmd><tt>[index][mymouse2]{mouse}</tt> ... <cmd>stopregister</cmd><tt>[index][mymouse2]</tt> to get two independent ranges in the list. <cmd>startregister</cmd> takes four arguments, of which two are mandatory: <cmd>startregister</cmd><tt>[NAME_OF_REGISTER]{ENTRY_NAME}</tt>. The other arguments are <tt>[KEY_FOR_RANGE]</tt> and <tt>[KEY_FOR_SORTING]</tt>. To give an example: <cmd>startregister</cmd><tt>[index][levi][Levi-Strauss]{Lévi|-|Strauss}</tt>. This will start a range with the key <tt>levi</tt> which will put the entry "Lévi-Strauss" in the register "index" (the "normal" register) and sort it under "Levi-Strauss." To mark the end of the range, you write <cmd>stopregister</cmd><tt>[index][levi]</tt>.<br />
* <cmd>writetoregister</cmd> (sometimes needed to avoid macro expansion issues)<br />
* A register per chapter: <cmd>placeregister</cmd><tt>[index][criterium=chapter]</tt><br />
* Place a word in text ''and'' index: <tt>\def\Tindex#1{\index{#1}#1}</tt> -- Please someone enhance this to get space correction, [] sorting etc.!<br />
* The name that you will get in the head of \completeregister can be set with: \setupheadtext[register=My new index]<br />
<br />
=Coupled Registers=<br />
<br />
This is a special feature for documents that are only used on screen: Make a word clickable to jump to the index, the first or last occurrence.<br />
<br />
Enable it with <cmd>setupregister</cmd><tt>[index][coupling=yes]</tt>.<br />
Substitute <cmd>index</cmd> with <cmd>coupledindex</cmd> and enjoy!<br />
<br />
=Impact on vertical spacing=<br />
<br />
In some situations, placing an <cmd>index</cmd> (or related command) might affect vertical spacing and the page-breaking mechanism. In those situations it is advisable to wrap the command in a <cmd>doflushatpar</cmd> as shown below (needs a ConTeXt version dated after 14th Dec 2005):<br />
<br />
<texcode><br />
\starttext<br />
\section{Tufte}<br />
\dorecurse{4}{\input tufte \par}<br />
\section{Knuth}<br />
\doflushatpar{\index{Knuth}}<br />
\input knuth \par<br />
\stoptext<br />
</texcode><br />
<br />
This will stop bad-page breaking between the section title and the following para, for example.<br />
<br />
==Technical note==<br />
<br />
The above command is defined as follows:<br />
<br />
<texcode><br />
\long\def\doflushatpar#1%<br />
% {\dogotopar{\dontleavehmode#1}} % this one can introduce empty lines<br />
{\dogotopar{#1\ifvmode\nobreak\fi}} % while this one can mess up vertical space<br />
</texcode><br />
<br />
Note the two possible definitions, and the pitfalls with each one. If you are still having trouble with specific <cmd>index</cmd> commands, try using the alternative definition. When they are used in the right context, these three possible ways of placing an index term (the plain <cmd>index</cmd>, or it wrapped in one of the two possible <cmd>doflushatpar</cmd>s, should solve any problem.</div>128.187.165.186https://wiki.contextgarden.net/index.php?title=Registers&diff=6548Registers2006-09-05T21:13:25Z<p>128.187.165.186: Corrected } to ]</p>
<hr />
<div>< [[Structurals]] | [[References]] > (It's also in the manual at "Registers")<br />
<br />
=Basics=<br />
<br />
Putting a word into the index as simple as <cmd>index</cmd><tt>{word}</tt>. (Always type <cmd>index</cmd> ''before'' the word you refer to!)<br />
<br />
To sort e.g. <cmd>ConTeXt</cmd> under "C", you write <cmd>index</cmd><tt>[CONTEXT]{\ConTeXt}</tt>.<br />
<br />
If you need multiple levels (up to three), use "+" or "&" separators like in <cmd>index</cmd><tt>{beans+baked}</tt>.<br />
<br />
You get a cross reference in your index with <cmd>seeindex</cmd> like in <cmd>seeindex</cmd><tt>[CONTEXT]{\ConTeXt}{\TeX}</tt> (ConTeXt: see TeX).<br />
<br />
To typeset the index, use <cmd>placeindex</cmd> (without title) or <cmd>completeindex</cmd> (with titling).<br />
<br />
==Example==<br />
<texcode><br />
My \index{dog}dog is a \index{dog+bullterrier}bullterrier named \seeindex{Dolly}{Underware}Dolly.<br />
He doesn't like \index{cat}cats.<br />
There are a lot of \index{cat+stray}stray cats, but only a few of them are \index{cat+Siamese}Siamese.<br />
<br />
\placeindex<br />
</texcode><br />
<context><br />
\tfx<br />
My \index{dog}dog is a \index{dog+bullterrier}bullterrier named \seeindex{Dolly}{Underware}Dolly.<br />
He doesn't like \index{cat}cats. There are a lot of \index{cat+stray}stray cats, but only a few of them are \index{cat+Siamese}Siamese.<br />
<br />
\placeindex<br />
</context><br />
<br />
=Styling the Index=<br />
<br />
<cmd>setupregister</cmd><tt>[index]</tt> is your friend. <cmd>placeindex</cmd> and <cmd>completeindex</cmd> take the same options.<br />
<br />
You can also style single entries with the :: syntax like this (from the manual):<br />
<br />
<texcode><br />
\setupregister[index][form][pagestyle=bold,textstyle=slanted]<br />
\setupregister[index][tb][textstyle=bold]<br />
\setupregister[index][nb][pagestyle=bold]<br />
\setupregister[index][hm][pagestyle=slanted]<br />
<br />
\index{tb::foot+squarefoot} % text in "tb" style<br />
\index[nb::]{squareroot} % number in "nb" style<br />
\index[hm::root]{$\sqrt{2}$} % number in "hm" style, sorted at "root"<br />
</texcode><br />
<br />
=More Registers=<br />
<br />
<cmd>index</cmd> is only one special case of <cmd>register</cmd>. You can define as much different registers as you like:<br />
<br />
<cmd>defineregister</cmd><tt>[singular name][plural name]</tt>, e.g. <br />
<texcode><br />
\defineregister[mouse][mice]<br />
\setupregister[mouse][style=\ss]<br />
<br />
\mouse{rat}<br />
<br />
\placemouse<br />
</texcode><br />
<br />
(Don't know if the plural form is used anywhere...)<br />
<br />
=Tricks=<br />
<br />
* <cmd>startregister</cmd><tt>[mymouse]{mouse}</tt> ... <cmd>stopregister</cmd><tt>[mymouse]</tt>: to mark several pages for the same entry; becomes e.g. "mouse 12--16". Note that if you have two or more of these ranges, you need them to have different <tt>[key]</tt> values to stop the system treating them as part of a great big range. So, use <cmd>startregister</cmd><tt>[mymouse1]{mouse}</tt> ... <cmd>stopregister</cmd><tt>[mymouse1]</tt> and then <cmd>startregister</cmd><tt>[mymouse2]{mouse}</tt> ... <cmd>stopregister</cmd><tt>[mymouse2]</tt> to get two independent ranges in the list. <cmd>startregister</cmd> takes four arguments, of which two are mandatory: <cmd>startregister</cmd><tt>[NAME_OF_REGISTER]{ENTRY_NAME}</tt>. The other arguments are <tt>[KEY_FOR_RANGE]</tt> and <tt>[KEY_FOR_SORTING]</tt>. To give an example: <cmd>startregister</cmd><tt>[index][levi][Levi-Strauss]{Lévi|-|Strauss}</tt>. This will start a range with the key <tt>levi</tt> which will put the entry "Lévi-Strauss" in the register "index" (the "normal" register) and sort it under "Levi-Strauss." To mark the end of the range, you write <cmd>stopregister</cmd><tt>[index][levi]</tt>.<br />
* <cmd>writetoregister</cmd> (sometimes needed to avoid macro expansion issues)<br />
* A register per chapter: <cmd>placeregister</cmd><tt>[index][criterium=chapter]</tt><br />
* Place a word in text ''and'' index: <tt>\def\Tindex#1{\index{#1}#1}</tt> -- Please someone enhance this to get space correction, [] sorting etc.!<br />
* The name that you will get in the head of \completeregister can be set with: \setupheadtext[register=My new index]<br />
<br />
=Coupled Registers=<br />
<br />
This is a special feature for documents that are only used on screen: Make a word clickable to jump to the index, the first or last occurrence.<br />
<br />
Enable it with <cmd>setupregister</cmd><tt>[index][coupling=yes]</tt>.<br />
Substitute <cmd>index</cmd> with <cmd>coupledindex</cmd> and enjoy!<br />
<br />
=Impact on vertical spacing=<br />
<br />
In some situations, placing an <cmd>index</cmd> (or related command) might affect vertical spacing and the page-breaking mechanism. In those situations it is advisable to wrap the command in a <cmd>doflushatpar</cmd> as shown below (needs a ConTeXt version dated after 14th Dec 2005):<br />
<br />
<texcode><br />
\starttext<br />
\section{Tufte}<br />
\dorecurse{4}{\input tufte \par}<br />
\section{Knuth}<br />
\doflushatpar{\index{Knuth}}<br />
\input knuth \par<br />
\stoptext<br />
</texcode><br />
<br />
This will stop bad-page breaking between the section title and the following para, for example.<br />
<br />
==Technical note==<br />
<br />
The above command is defined as follows:<br />
<br />
<texcode><br />
\long\def\doflushatpar#1%<br />
% {\dogotopar{\dontleavehmode#1}} % this one can introduce empty lines<br />
{\dogotopar{#1\ifvmode\nobreak\fi}} % while this one can mess up vertical space<br />
</texcode><br />
<br />
Note the two possible definitions, and the pitfalls with each one. If you are still having trouble with specific <cmd>index</cmd> commands, try using the alternative definition. When they are used in the right context, these three possible ways of placing an index term (the plain <cmd>index</cmd>, or it wrapped in one of the two possible <cmd>doflushatpar</cmd>s, should solve any problem.</div>128.187.165.186