| 1 |
% extern.tex copyright 1992 Victor Eijkhout |
| 2 |
% copyright 2014--2016 Vafa Khalighi |
| 3 |
% |
| 4 |
% |
| 5 |
% This program is free software: you can redistribute it and/or modify |
| 6 |
% it under the terms of the GNU General Public License as published by |
| 7 |
% the Free Software Foundation, either version 3 of the License, or |
| 8 |
% (at your option) any later version. |
| 9 |
% |
| 10 |
% This program is distributed in the hope that it will be useful, |
| 11 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
% GNU General Public License for more details. |
| 14 |
% |
| 15 |
% You should have received a copy of the GNU General Public License |
| 16 |
% along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
% |
| 18 |
% |
| 19 |
\Chapter[chap:referencing] |
| 20 |
Referencing |
| 21 |
|
| 22 |
In manuals and scientific documents you often want to write something |
| 23 |
like `see Chapter~4'. But what if you shuffle the chapters a bit? It |
| 24 |
would be nice if the number would be updated automatically. With |
| 25 |
\Lollipop, as with many other \TeX\ macro packages, this is easily |
| 26 |
done. |
| 27 |
|
| 28 |
Here is an example to set the mood for the rest of this chapter. |
| 29 |
The sort of thing that is referred to most is a heading. So suppose |
| 30 |
you want to refer to a section number. |
| 31 |
|
| 32 |
\Example |
| 33 |
\DefineHeading:TestSection |
| 34 |
line:start Style:italic TestSectionCounter Spaces:2 title |
| 35 |
line:stop Stop |
| 36 |
\TestSection[one:section?] First section\par |
| 37 |
After this section will come section~\ref[other:section!]. |
| 38 |
|
| 39 |
\TestSection[other:section!] Another section\par |
| 40 |
This is the section that came after section~\ref[one:section?]. |
| 41 |
\ExampleStop |
| 42 |
|
| 43 |
\Section What and how do you reference? |
| 44 |
|
| 45 |
You can reference not only headings but everything that has a |
| 46 |
counter. Thus all generic constructs can be referenced, and in |
| 47 |
addition you can reference item numbers in a list (there are examples |
| 48 |
of this latter possibility in section~\ref[sec:bib]). The simplest way |
| 49 |
of referencing something is to put the key in square brackets behind |
| 50 |
it: |
| 51 |
|
| 52 |
\Ver>\Section[this:section] The title of This Section<Rev |
| 53 |
You can then reference the key by \refcs{ref}, or the page |
| 54 |
where it appeared by~\refcs{pgref}: |
| 55 |
\Ver>Section \ref[this:section] on page \pgref[this:section]<Rev |
| 56 |
|
| 57 |
As you may have guessed from the above examples, keys can contain all |
| 58 |
sorts of characters. Only brackets, braces, and the hash sign are |
| 59 |
excepted. You get an error message if you try to use the same key |
| 60 |
twice. |
| 61 |
|
| 62 |
Another way of declaring a key is to use the command \refcs{label} |
| 63 |
carrying the key |
| 64 |
\Ver>\label[the:key]<Rev |
| 65 |
This can be useful if you want to declare two keys for a single |
| 66 |
reference. Make sure that the \cs{label} command is not part of the |
| 67 |
title. Unexplained phenomena occur if you do that. Instead put the |
| 68 |
label after the construct you want to reference: |
| 69 |
\Ver>\Section Precautions and remedies |
| 70 |
|
| 71 |
\label[sec:precautions]\label[sec:remedies] |
| 72 |
In this section ...<Rev |
| 73 |
|
| 74 |
\Section[sec:shape:reference] The shape of the reference |
| 75 |
|
| 76 |
By default, a reference consists of just the number of the thing you |
| 77 |
reference. There are two ways in which you can change this, one |
| 78 |
systematic, and one on-the-fly. |
| 79 |
|
| 80 |
\SubSection Defining the shape of the reference |
| 81 |
|
| 82 |
You can customize the way an object is |
| 83 |
referenced by using the option \refopt{label} in its definition. For |
| 84 |
instance, often you want things like parentheses around references. |
| 85 |
Putting this information in the label definition saves you a lot of |
| 86 |
work in case you change your mind later. |
| 87 |
|
| 88 |
\Example |
| 89 |
\DefineHeading:TestSection |
| 90 |
line:start Style:italic TestSectionCounter Spaces:2 title line:stop |
| 91 |
label:start ( TestSectionCounter ) label:stop Stop |
| 92 |
\TestSection[one:section?2] First section\par |
| 93 |
After this section will come section~\ref[other:section!2]. |
| 94 |
|
| 95 |
\TestSection[other:section!2] Another section\par |
| 96 |
This is the section that came after section~\ref[one:section?2]. |
| 97 |
\ExampleStop |
| 98 |
|
| 99 |
Another use of customized labels is including other counters in the |
| 100 |
reference: |
| 101 |
|
| 102 |
\Example |
| 103 |
\DefineHeading:TestChapter |
| 104 |
line:start Style:bold TestChapterCounter / title line:stop Stop |
| 105 |
\DefineHeading:TestSection |
| 106 |
line:start Style:italic TestSectionCounter Spaces:2 title line:stop |
| 107 |
label:start TestChapterCounter . |
| 108 |
TestSectionCounter label:stop Stop |
| 109 |
\TestChapter First chapter\par |
| 110 |
Pretty short chapter |
| 111 |
\TestChapter Second chapter\par |
| 112 |
\TestSection[one:section?3] First section\par |
| 113 |
After this section will come section~\ref[other:section!3]. |
| 114 |
|
| 115 |
\TestSection[other:section!3] Another section\par |
| 116 |
This is the section that came after section~\ref[one:section?3]. |
| 117 |
\ExampleStop |
| 118 |
|
| 119 |
A more surprising application of explicit definition of labels is |
| 120 |
inclusion of the title in the reference. |
| 121 |
\Example |
| 122 |
\DefineHeading:TestSection |
| 123 |
line:start Style:italic TestSectionCounter Spaces:2 title line:stop |
| 124 |
label:start TestSectionCounter literal: Spaces:1 |
| 125 |
Style:italic title label:stop Stop |
| 126 |
\TestSection[one:section?4] First section\par |
| 127 |
After this section will come section~\ref[other:section!4]. |
| 128 |
|
| 129 |
\TestSection[other:section!4] Another section\par |
| 130 |
This is the section that came after section~\ref[one:section?4]. |
| 131 |
\ExampleStop |
| 132 |
|
| 133 |
\SubSection[sec:exp-ref] Explicit specification of the reference |
| 134 |
|
| 135 |
For every specific object referenced you can specify the reference by |
| 136 |
using an optional argument before the label key. Have a look at the |
| 137 |
next example. |
| 138 |
|
| 139 |
\Example |
| 140 |
\DefineHeading:TestSection counter:A |
| 141 |
line:start Style:bold TestSectionCounter . Spaces:2 title line:stop |
| 142 |
Stop |
| 143 |
\TestSection[ref:one] Lalala\par |
| 144 |
This is before section \ref[ref:two]. |
| 145 |
\TestSection<`the Didi section'>[ref:two] Dididi\par |
| 146 |
This is after section \ref[ref:one]. |
| 147 |
\ExampleStop |
| 148 |
|
| 149 |
This mechanism is also used in lists, where it's mostly useful for |
| 150 |
bibliographies generated by Bib\TeX; see section~\ref[sec:BibTeX]. |
| 151 |
|
| 152 |
\Section[sec:ref-local] Local references |
| 153 |
|
| 154 |
Some documents are |
| 155 |
collated out of parts that were documents in themselves. |
| 156 |
The \Lollipop\ command \cs{InputFile} facilitates in a number |
| 157 |
of ways working with such a segmented file (see |
| 158 |
section~\ref[sec:InputFile]). One of the problems with input files is |
| 159 |
that in such a case it may happen that the same reference key is used |
| 160 |
in more than one part of the document. This phenomenon is |
| 161 |
not at all unknown in multiple authored documents. Ordinarily this |
| 162 |
would result in incorrect references. |
| 163 |
|
| 164 |
To prevent such collisions \Lollipop\ can use local |
| 165 |
references: the command \refcs{LocalReferences} has default \n{no}, |
| 166 |
and specifying |
| 167 |
\Ver>LocalReferences:yes<Rev |
| 168 |
creates local \file{aux} files for each input file. |
| 169 |
|
| 170 |
\Section[sec:bib] Bibliography citations |
| 171 |
|
| 172 |
\Lollipop\ has an interface to Bib\TeX. However, since a bibliography |
| 173 |
is just a list, referencing items in it is quite easy, even if you |
| 174 |
don't use Bib\TeX. |
| 175 |
|
| 176 |
\SubSection Bibliographies without Bib\TeX |
| 177 |
|
| 178 |
This section doesn't tell you anything that cannot be found elsewhere |
| 179 |
in this manual. The following two examples define a bibliography as |
| 180 |
just a list, and by giving labels to the items you can refer to them. |
| 181 |
|
| 182 |
\Example |
| 183 |
\DefineList:BibList item:left [ itemCounter ] item:stop |
| 184 |
label:start [ itemCounter ] label:stop Stop |
| 185 |
In this example we shall have occasion to refer to |
| 186 |
\ref[Abee80] and~\ref[Ceede79].\par |
| 187 |
\Indent:no Bibliography |
| 188 |
\BibList \item[Ace55] C.D. Ace, Inscrutible title. |
| 189 |
\item[Abee80] E.F. Abee, Worthless drivel. |
| 190 |
\item[Ceede79] G.H. Ceede, Contractual obligation. |
| 191 |
\> |
| 192 |
\ExampleStop |
| 193 |
|
| 194 |
Here is a way to customize the label (if you need to refresh your |
| 195 |
memory about description lists, see |
| 196 |
section~\ref[sec:description:list]). |
| 197 |
|
| 198 |
\Example |
| 199 |
\DefineList:BibList item:left [ itemCounter ] item:stop |
| 200 |
label:start ( description ) label:stop Stop |
| 201 |
In this example we shall have occasion to refer to |
| 202 |
\ref[Abe80] and~\ref[Ceedee79].\par |
| 203 |
\Indent:no Bibliography |
| 204 |
\BibList \item[Aace55] Aace55 |
| 205 |
C.D. Aace, Inscrutible title. |
| 206 |
\item[Abe80] Abe80 |
| 207 |
E.F. Abe, Worthless drivel. |
| 208 |
\item[Ceedee79] Ceedee79 |
| 209 |
G.H. Ceedee, Contractual obligation. |
| 210 |
\> |
| 211 |
\ExampleStop |
| 212 |
|
| 213 |
\SubSection[sec:BibTeX] Bibliographies with Bib\TeX |
| 214 |
|
| 215 |
\Lollipop has an interface to the popular Bib\TeX\ |
| 216 |
bibliography database program, based on the `BtxMac' macros |
| 217 |
by Karl Berry and Oren Patashnik. \Lollipop\ is set up for them, you |
| 218 |
only have to \cs{input} the file \file{btxmac.tex}. (The version |
| 219 |
of btxmac used to test this is \n{0.99h}.) You can find global |
| 220 |
information about Bib\TeX\ in the \LaTeX\ book~{%\tracingmacros=2 |
| 221 |
%\tracingcommands\tracingmacros |
| 222 |
\bibref[La:book]}, |
| 223 |
since Bib\TeX\ was |
| 224 |
originally written for \LaTeX. |
| 225 |
|
| 226 |
Since there is some redefining going on between btxmac and \Lollipop\ |
| 227 |
you have to load the btxmac file before the \cs{Start} command (see |
| 228 |
section~\ref[sec:doc-start-stop]). |
| 229 |
|
| 230 |
Since the btxmac file already has a default way of formatting the |
| 231 |
bibliography you can get away with just putting the lines |
| 232 |
\Ver>\bibliography{ <bfile> } |
| 233 |
\bibliographystyle{ <bstyle> }<Rev |
| 234 |
in your file wherever you want the bibliography. |
| 235 |
|
| 236 |
If you want to define your own bibliography, you have to use |
| 237 |
\refcs{DefineBBL} which is practically a synonym for |
| 238 |
\ver>\DefineList:BBL>, so you can see in the `lists' chapter of this |
| 239 |
manual what options apply. |
| 240 |
|
| 241 |
For example: |
| 242 |
\Ver>\DefineBBL line:start Style:italic literal:Literature line:stop |
| 243 |
item:left [ begingroup Style:bold itemCounter |
| 244 |
endgroup ] item:stop |
| 245 |
Stop<Rev |
| 246 |
|
| 247 |
You refer to a bibliography item by \refcs{bibref}, as in |
| 248 |
\ver>\bibref[Knuth80]>. This command has a very simple definition |
| 249 |
\Ver>\def\bibref[#1]{[\ref[#1]]\nocite{#1}}<Rev |
| 250 |
so you can easily redefine it. For instance |
| 251 |
\Ver>\def\supref[#1]{$^{\rm \ref[#1]}$\nocite{#1}}<Rev |
| 252 |
will make your references into superscripts. |
| 253 |
Make sure that |
| 254 |
the call to \cs{nocite} appears, because that generates the request for |
| 255 |
Bib\TeX. |
| 256 |
|
| 257 |
The \Lollipop\ command \ver>\WriteExtern:no> (see |
| 258 |
section~\ref[sec:write-extern]) defines \cs{noauxfile} to prevent |
| 259 |
regeneration of the bib entries in the \file{.aux} file. |
| 260 |
You don't have to do that anymore. |
| 261 |
|
| 262 |
\Section Obscure details |
| 263 |
|
| 264 |
For the sake of efficiency, not all macros in Lollipop automatically |
| 265 |
accept labels for referencing, only the ones that use the \n{label} |
| 266 |
option, or that have a counter (remember, the default form of the |
| 267 |
reference is just the counter). If you want a macro that has no |
| 268 |
counter and no label specification to accept a label, use the option |
| 269 |
\refopt{haslabel}. One reason for doing this is that you have access to |
| 270 |
the label itself through the control sequence \refcs{RefLabel}. |
| 271 |
|
| 272 |
\Chapter[chap:external-files] External Files |
| 273 |
|
| 274 |
Some document require information to be collected during a run. Such |
| 275 |
information typically is a table of contents or index, and it is |
| 276 |
gathered in an external file. (The reason for gathering such |
| 277 |
information in a file at all is that often some external manipulation, |
| 278 |
for instance sorting of an index, is needed.) Since there are many |
| 279 |
possibilities for external files (mathematical monographs may have a |
| 280 |
list of definitions, or a list of notations) \Lollipop\ does not |
| 281 |
predefine such files, but supplies all of the tools for creating them. |
| 282 |
|
| 283 |
External files involve four actions: |
| 284 |
\Enumerate\item The file should be declared. |
| 285 |
\item It should be specified what information is to be written to the |
| 286 |
file. |
| 287 |
\item The formatting of the contents of the file has to be specified. |
| 288 |
\item The file has to be loaded. |
| 289 |
\> |
| 290 |
|
| 291 |
You can have at most 15 external files per document. |
| 292 |
|
| 293 |
\Section[sec:write-extern] Declaring and loading an external file |
| 294 |
|
| 295 |
The first act, declaring the existence of the external file is very |
| 296 |
easy with the command \refcs{DefineExternalFile}: |
| 297 |
an internal name and a three-character file name extension have |
| 298 |
to be given as parameters. |
| 299 |
\Ver>\DefineExternalFile:contents=toc<Rev |
| 300 |
With this definition, if the document is called \file{book.tex} then |
| 301 |
the `contents' will be gathered in a file called \file{book.toc}. |
| 302 |
(The declaration of an external file has to come before any calls |
| 303 |
to \cs{ExternalItem} or any options \n{external} that write |
| 304 |
to this file.) |
| 305 |
|
| 306 |
For each external file \n{Foo} there is a command to determine whether |
| 307 |
that file will be regenerated in the next run of \TeX: |
| 308 |
\refcs{WriteFoo} with values \n{yes}/\n{no} will allow or prevent the |
| 309 |
file being regenerated. The value \opt{yes} is default. The |
| 310 |
command \refcs{WriteExtern} (values \n{yes}/\n{no}) |
| 311 |
can be used to prevent writing out any external files (including the |
| 312 |
\file{.aux} file that keeps track of references). |
| 313 |
|
| 314 |
The final act, loading an external file, is as easy as declaring it: |
| 315 |
use \refcs{LoadExternalFile} as in |
| 316 |
\Ver>\LoadExternalFile:contents<Rev |
| 317 |
This does not cause any page breaks or headings to be set over the |
| 318 |
loaded material, so you have to do that explicitly. |
| 319 |
|
| 320 |
\Section[sec:ext-option] Generating external files |
| 321 |
|
| 322 |
Next, macros that write to the table of contents have to declare this |
| 323 |
information. The \refopt{external} option is used for this. |
| 324 |
Any counter that the construct has will be written out |
| 325 |
automatically, and the style designer usually has to specify only |
| 326 |
that the title will be written out. |
| 327 |
\Ver>\DefineHeading:Section |
| 328 |
[...] |
| 329 |
external:contents title external:stop<Rev |
| 330 |
|
| 331 |
There is no objection to a construct writing information to more than |
| 332 |
one external file. |
| 333 |
|
| 334 |
If you write more than just \n{title} to an external file, know that |
| 335 |
any control sequence you specify is automatically protected from |
| 336 |
expansion. See section~\ref[opt:csname] for an exception to this. |
| 337 |
|
| 338 |
Other titles can be included by specifying \opt{title:OtherThing}. |
| 339 |
Using \opt{OtherThingTitle} would not work, because of the protection |
| 340 |
of control sequences mentioned above. |
| 341 |
|
| 342 |
You can write arbitrary information to an external file, if you see a |
| 343 |
reason to do so, by \refcs{ToExternalFile}, which takes a file name |
| 344 |
and an text argument. The example below has an instance of this |
| 345 |
command. In order to format this information you have to define an |
| 346 |
external construct of type \cs{anon}. |
| 347 |
|
| 348 |
\Section[sec:ext-item] Formatting an external file |
| 349 |
|
| 350 |
The hardest part is declaring the formatting of an external file. For |
| 351 |
this a separate generic construct exists: the `external item' with |
| 352 |
defining command \refcs{DefineExternalItem}. For example, if |
| 353 |
\cs{Section} writes to \n{contents}, than an external item \n{Section} |
| 354 |
corresponding to this file has to be declared. The option |
| 355 |
\refopt{file} is use to declare to which file the external item |
| 356 |
belongs. This way the same name can be reused for more than one file. |
| 357 |
|
| 358 |
\Ver>\DefineExternalItem:Section file:contents |
| 359 |
[...] Stop<Rev |
| 360 |
|
| 361 |
An external item is basically a list with just one item. Thus, the |
| 362 |
option \refopt{item} is available. The elements of an external item are |
| 363 |
the label (the counter value), the page number where the information |
| 364 |
was generated, and the title. |
| 365 |
For the label (say for a construct \cs{Foo}) |
| 366 |
an option \refopt{FooLabel} is created. |
| 367 |
Thus the typical formating looks like |
| 368 |
\Ver>\DefineExternalItem:Chapter file:contents |
| 369 |
item:left ChapterLabel item:stop |
| 370 |
title begingroup Spaces:2 Style:italic Page endgroup |
| 371 |
Stop<Rev |
| 372 |
In fact, a control sequence \refcs{FooLabel} is created, which |
| 373 |
can be used in other external items. |
| 374 |
|
| 375 |
Since an external item is a list in itself, you have to pull a |
| 376 |
certain trick to get items for subsections to indent further than |
| 377 |
those for sections. This is what the command \cs{PushIndentLevel} was |
| 378 |
designed for. |
| 379 |
|
| 380 |
A typical indented item looks like: |
| 381 |
\Ver>\DefineExternalItem:SubSection file:contents |
| 382 |
PushIndentLevel PushIndentLevel |
| 383 |
item:left SectionLabel . SubSectionLabel item:stop |
| 384 |
title begingroup Spaces:2 Style:italic Page endgroup |
| 385 |
Stop<Rev |
| 386 |
|
| 387 |
\Section Example |
| 388 |
|
| 389 |
The following example is for a typical table of contents that |
| 390 |
records sections and subsections. In good old-fashioned style, the |
| 391 |
subsections are indented with respect to the sections. |
| 392 |
\endinput |
| 393 |
\Example |
| 394 |
\DefineExternalFile:TheContents=tct |
| 395 |
\DefineHeading:TestChapter Style:bold |
| 396 |
line:start TestChapterCounter Spaces:2 title line:stop |
| 397 |
external:TheContents title external:stop Stop |
| 398 |
\DefineExternalItem:TestChapter file:TheContents |
| 399 |
item:left Style:bold TestChapterLabel item:stop title white:5pt |
| 400 |
Page par Stop |
| 401 |
\DefineHeading:TestSection Style:italic |
| 402 |
line:start TestChapterCounter . TestSectionCounter |
| 403 |
Spaces:2 title line:stop |
| 404 |
external:TheContents title external:stop Stop |
| 405 |
\GoverningCounter:TestSection=TestChapter |
| 406 |
\DefineExternalItem:TestSection file:TheContents PushIndentLevel |
| 407 |
item:left Style:bold TestChapterLabel . TestSectionLabel item:stop |
| 408 |
title white:5pt Page par Stop |
| 409 |
\DefineExternalItem:anon file:TheContents begingroup |
| 410 |
Style:italic title white:5pt Page par Stop |
| 411 |
|
| 412 |
\LoadExternalFile:TheContents |
| 413 |
\TestChapter First heading\par |
| 414 |
\TestSection First subheading\par |
| 415 |
Some text might be nice. |
| 416 |
\TestSection Second subheading\par |
| 417 |
Some more text. |
| 418 |
\ToExternalFile:TheContents={Enclosed Graphics} |
| 419 |
\TestChapter Second heading\par |
| 420 |
\TestSection Third subheading\par |
| 421 |
Yet more text. |
| 422 |
\TestSection Fourth subheading\par |
| 423 |
And again: text. |
| 424 |
\ExampleStop |
| 425 |
|
| 426 |
\endinput |
| 427 |
|
| 428 |
% 92/11/26 BibTeX section |