lbl.ms 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. .\" (C) C.D.F. Miller, Heriot-Watt University, March 1984
  2. .\"
  3. .\" This file should be formatted by
  4. .\" lbl lbl | nroff -ms
  5. .L= delimiter #
  6. .ND
  7. .TL
  8. LBL - Symbolic Labels in Text Documents
  9. .NH 1
  10. Introduction
  11. .L= sec 1 intro
  12. .PP
  13. .I lbl
  14. is a pre-processor for
  15. .I troff
  16. and
  17. .I nroff
  18. which allows Sections, Figures, Tables, etc., to be referred to by
  19. symbolic names rather than by absolute number.
  20. It will handle forward references as well as backward ones.
  21. .PP
  22. Uses of a label in the text are indicated by a delimiter character (default '@',
  23. but resettable), followed by a
  24. .I type
  25. name (e.g. "TABLE", "EQN", etc.), followed by the label itself
  26. (e.g. "Profits-1983").
  27. Each such occurrence is replaced by a reference number; the default
  28. style of numbering is a sequence of period-separated arabic numbers
  29. (e.g. 2.4.1) but this is resettable.
  30. Finally, another delimiter is required to close the reference
  31. (cf. the use of delimiters in
  32. .I eqn
  33. for in-line equations).
  34. .LP
  35. Examples:
  36. .DS
  37. For full details refer to Table @TABLE Profits-1983@.
  38. As we saw in Chapter @chap intro@, ...
  39. Figure @fig wing-profile@ shows the airflow patterns ...
  40. .DE
  41. .PP
  42. Labels may be defined at any point in the text.
  43. The definition looks like a
  44. .I troff
  45. macro, and the definition line is retained in the original text.
  46. By default, the macro used is ".L=", but this can be reset.
  47. The macro takes 3 arguments: a type-name, a level-number, and
  48. a label-name.
  49. .PP
  50. The type-name corresponds to that used to signal a label occurrence in
  51. the text.
  52. There is no restriction on the choice of name; any sequence of
  53. non-blank characters may be used.
  54. Upper- and lower-case letters
  55. .I are
  56. distinguished.
  57. .PP
  58. The level-number corresponds to the header-level numbers used
  59. by the .NH macro in
  60. .I ms ,
  61. the .sh macro in
  62. .I me ,
  63. etc.
  64. The index at the given level is incremented by 1, and all higher indexes
  65. set to 0.
  66. Initially, all indexes are set to 0 by default, but other starting values
  67. may be chosen.
  68. There is an implementation-defined restriction on the number
  69. of levels of index (currently 20);
  70. it is not anticipated that this will lead to problems.
  71. .PP
  72. The label may be any sequence of non-blank characters;
  73. the same label may be used in more than one type.
  74. Furthermore, the special label-name ``*'' can be used to increment the
  75. appropriate level-counter without defining a label at all;
  76. this is useful, for example, when all tables, figures, etc., in a section
  77. take their initial index from the section number: two ways of doing this
  78. would be:
  79. .DS L
  80. a.
  81. .L= section 1 this-section
  82. .L= last table 0
  83. .L= last figure 0
  84. ...
  85. ... refer to table @section this-section@.@table profits@ ...
  86. ... see figure @section this-section@.@figure structure@ ...
  87. ...
  88. .L= table 1 profits
  89. ...
  90. .L= figure 1 structure
  91. ...
  92. (see section #sec directives# for the use of
  93. ``.L=\ last\ ...'')
  94. b.
  95. .L= section 1 this-section
  96. .L= table 1 *
  97. .L= figure 1 *
  98. ...
  99. ... refer to table @table profits@ ...
  100. ... see figure @figure structure@ ...
  101. ...
  102. .L= table 2 profits
  103. ...
  104. .L= figure 2 structure
  105. ...
  106. .DE
  107. It is largely a matter of taste which technique is used;
  108. the former is more long-winded, but avoids the need to remember to
  109. keep the tables and figures in step every time the section is
  110. updated.
  111. Yet a third possibility (similar to the first) would be:
  112. .DS L
  113. c.
  114. .L= section 1 this-section
  115. .ds Sc "@section this-section@
  116. .L= last table 0
  117. ...
  118. ... refer to table \*(Sc.@table profits@
  119. etc.
  120. .DE
  121. making use of the string-definition facility within
  122. .I nroff .
  123. .PP
  124. It is important to be aware that all processing on labels is done
  125. before
  126. .I troff
  127. processes the text; attempts to build label-references by
  128. using macros or
  129. .I troff
  130. strings registers will almost certainly not work as expected.
  131. .NH 1
  132. Command Line Options
  133. .L= sec 1 options
  134. .PP
  135. Options to
  136. .I lbl
  137. are set in the command line, which has the form
  138. .DS
  139. lbl [ -d\fIdelim\fR ] [ -m\fImacro\fR ] [ -l ] [ -s ]
  140. .DE
  141. .IP -d
  142. .I \fIdelim\fR
  143. is the character used to delimit in-line occurrences of label
  144. references (default ``@'');
  145. .IP -m
  146. .I macro
  147. is the 2-character name of
  148. a
  149. .I troff
  150. macro which introduces label definitions, etc. (default ``L='');
  151. .IP -l
  152. causes a listing of label-definitions to be written to the standard
  153. error stream.
  154. Each label-type is listed, together with its print format, followed by
  155. a line for each label of that type, showing label-name, file and line
  156. where it is defined, and value;
  157. .IP -s
  158. causes the generation of the
  159. .I troff
  160. input file to be suppressed;
  161. setting
  162. .I -s
  163. automatically also sets
  164. .I -l .
  165. .NH 1
  166. Control directives
  167. .L= sec 1 directives
  168. .PP
  169. In addition to defining labels, the \fB.L=\fR macro (or its substitute)
  170. can be used for several other purposes.
  171. These are all indicated by commands of the form
  172. .DS
  173. \&.L= \fIcommand\fR \fIargument\fR ...
  174. .DE
  175. where the \fIcommand\fRs are reserved words which may not be used as
  176. type-names.
  177. These commands allow control over the initialisation of label values,
  178. the print format of labels, and thelabel reference delimiter.
  179. .IP "\&.L= delimiter off"
  180. .br
  181. turns off interpretation of the delimiter character altogether;
  182. subsequent text is copied literally until another \fIdelimiter\fR
  183. command is encountered;
  184. .IP "\&.L= delimiter \fIcharacter\fR"
  185. .br
  186. resets the delimiter in subsequent text to the given character;
  187. .IP "\&.L= format \fItypename\fR \fIstring\fR"
  188. .br
  189. sets the print format for labels of the given type - see section
  190. #sec formats#;
  191. .IP "\&.L= last \fItypename\fR \fIcount1\fR \fIcount2\fR ..."
  192. .br
  193. resets the counters for \fItypename\fR as though the last label
  194. generated had been \fIcount1.count2...\fR (with all omitted counts
  195. taken as 0).
  196. .NH 2
  197. Print formats
  198. .L= sec 2 formats
  199. .PP
  200. The default print format for a label is as a sequence of period-separated
  201. arabic numerals.
  202. However, it is also possible to specify alphabetic or roman labels,
  203. or a mixture, and to have separators other than a period.
  204. This is governed by the format given in a ``.LE\ format'' command.
  205. .PP
  206. Such a format contains escape sequences (flagged by a ``%'' character)
  207. and literal text.
  208. The text is copied until an escape sequence is encountered; such a
  209. sequence is replaced by the index for the next level of the label
  210. value, printed in one of the following formats:
  211. .IP %1
  212. Arabic numerals (without non-significant leading zeros);
  213. .IP %0
  214. As %1, but offset by 1 so that the first value printed will be 0 rather
  215. than 1;
  216. .IP %a
  217. Lower-case alphabetics, starting at ``a''; ``z'' is followed by ``aa'',
  218. etc.;
  219. .IP %A
  220. Upper-case alphabetics;
  221. .IP %i
  222. Lower-case roman numerals (with some odd choices for large numbers,
  223. consistent with the roman numerals printed by
  224. .I troff ).
  225. .IP %I
  226. Upper-case roman numerals.
  227. .LP
  228. A ``%'' followed by any other character (in particular another ``%'') prints
  229. as that character.
  230. .NH 1
  231. Limits
  232. .L= sec 1 limits
  233. .PP
  234. .I Lbl
  235. imposes no limit on the size of text to be processed, but (like
  236. .I refer )
  237. needs to act on a text as a whole, rather than processing individual
  238. files.
  239. The limit on the number of levels of header is unlikely to prove a problem.
  240. The number of labels which may be used is limited only by the amount
  241. of memory available to a process; even on a small machine it is
  242. possible to handle a few hundred label definitions.
  243. .NH 1
  244. Further Examples
  245. .L= sec 1 examples
  246. .PP
  247. The copying of the definition macros makes it possible to use them
  248. as
  249. .I troff
  250. macros, as in the following example:
  251. .DS
  252. \&.de L=
  253. \&.ie '\e\e$1'sec' .NH \e\e$2
  254. \&.el .ie '\e\e$1'table' .if !'\e\e$3'*' \e{
  255. \&.DS C
  256. \&Table '\e\e$3' about here
  257. \&.DE
  258. \&\e}
  259. \&.el .if '\e\e$1'fig' .if !'\e\e$3'*' \e{
  260. \&.DS C
  261. \&Figure '\e\e$3' about here
  262. \&.DE
  263. \&\e}
  264. \&..
  265. \&.nr LL 5i
  266. \&.ND
  267. \&.TL
  268. \&Example of LBL
  269. \&.L= sec 1 intro
  270. \&Introduction
  271. \&.L= table 1 *
  272. \&.PP
  273. \&We begin with a small table (Table @table opening@).
  274. \&.L= table 2 opening
  275. \&and consider things in more detail in Section
  276. \&@sec cont@.
  277. \&.L= sec 1 cont
  278. \&Continuation
  279. \&.L= table 1 *
  280. \&.PP
  281. \&In this continuation we refer back to Section
  282. \&@sec intro@, which contained
  283. \&Table @table opening@, and present more detailed
  284. \&information in Table
  285. \&@table detail@.
  286. \&.L= table 2 detail
  287. \&.L= sec 2 subcont
  288. \&Sub-continuation
  289. \&.PP
  290. \&In which we further refine things, as shown in
  291. \&Table @table mega-detail@ below.
  292. \&.L= table 2 mega-detail
  293. .DE
  294. In the above, the ``.L=\ sec'' macros automatically generate the
  295. numbered headings by expanding to the \fIms\fR ``.NH'' macros,
  296. while the ``table'' definitions cause the insertion of figures
  297. such as
  298. .DS C
  299. Table 'detail' about here
  300. .DE
  301. The above example thus produces the following:
  302. .DS
  303. Example of LBL
  304. \fI1. Introduction\fR
  305. We begin with a small table (Table 1.1).
  306. Table 'opening' about here
  307. and consider things in more detail in Section 2.
  308. \fI2. Continuation\fR
  309. In this continuation we refer back to Section
  310. 1, which contained Table 1.1, and present more
  311. detailed information in Table 2.1.
  312. Table 'detail' about here
  313. \fI2.1. Sub-continuation\fR
  314. In which we further refine things, as shown
  315. in Table 2.2 below.
  316. Table 'mega-detail' about here
  317. .DE
  318. .PP
  319. The alphabetic formats may be useful for such things as appendices,
  320. e.g.
  321. .DS
  322. \&.L= format appendix %A
  323. \&.L= appendix 1 trade-marks
  324. \&.SH
  325. \&Appendix @appendix trade-marks@:
  326. \&List of Registered Trade Marks
  327. \&.LP
  328. \&(For the addresses of the proprietors see
  329. \&@appendix props@).
  330. \& ...
  331. \&.L= appendix 1 props
  332. .DE
  333. which will generate
  334. .DS
  335. \fIAppendix A: List of Registered Trade Marks\fR
  336. (For the addresses of the proprietors see appendix B).
  337. .DE