home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / DOC / TR.LOUT / ch1.02 < prev    next >
Text File  |  1994-01-25  |  9KB  |  253 lines

  1. @Section
  2.    @Title { Definitions }
  3.    @Tag { definitions }
  4. @Begin
  5. @PP
  6. The features of Lout are very general.  They do not assume that documents
  7. are composed of pages, nor that there are such things as margins and
  8. footnotes, for example.  @I Definitions
  9. definitions. @Index { Definitions }
  10. bridge the gap between Lout's general features and the
  11. special features -- footnotes, equations, pages -- that particular
  12. documents require.  They hold the instr&-uct&-ions for producing these
  13. special features, conveniently packaged ready for use.
  14. @PP
  15. For example, consider the challenge posed by `@TeX', which is the name of
  16. one of Lout's most illustrious rivals [{@Ref knuth84}].  Lout solves it
  17. easily enough, like this:
  18. @ID @Code {
  19. "T{ /0.2fo E }X"
  20. }
  21. but to type this every time @TeX is mentioned would be tedious and
  22. error-prone.  So we place a definition at the beginning of the document:
  23. @ID @Code {
  24. "def  @TeX  {  T{ /0.2fo E }X  }"
  25. }
  26. Now @Code "@TeX" stands for the object following it between
  27. braces, and we may write
  28. @ID @Code {
  29. consider the challenge posed by "`@TeX'", ...
  30. }
  31. as the author did earlier in this paragraph.
  32. @PP
  33. A @I symbol
  34. symbol. @Index Symbol
  35. is a name, like {@Code "@TeX"}, which stands for
  36. something other than itself.  The initial @Code "@" is not compulsory,
  37. but it does make the name stand out clearly.  A @I definition of a symbol
  38. declares a name to be a symbol, and says what the symbol stands for.  The
  39. @I body of a definition
  40. body.of @Index { Body of a definition }
  41. is the part following the name, between the braces.  To @I invoke
  42. invocation @Index { Invocation of a symbol }
  43. a symbol is to make use of it.
  44. @PP
  45. Another expression ripe for packaging in a definition is
  46. @ID @Code {
  47. "@OneRow {  |  -2p @Font n  ^/0.5fk  2  }"
  48. }
  49. which produces @OneRow { | -2p @Font n ^/0.5sk 2 } as the reader
  50. familiar with Chapter {@NumberOf details}
  51. can verify.  But this time we would like to be able to write
  52. @ID {
  53. @I object  @Code "@Super"  @I object
  54. }
  55. so that @Code { a "@Super" 2 } would come out as {a @Super 2}, and so
  56. on, for in this way the usefulness of the definition is greatly
  57. increased.  Here is how it is done:
  58. @ID @Code {
  59. "def @Super"
  60. "   left x"
  61. "   right y"
  62. "{ @OneRow {  |  -2p @Font y  ^/0.5fk  x  }"
  63. "}"
  64. }
  65. This definition says that @Code "@Super" has two {@I parameters},
  66. parameter @Index Parameter
  67. @Code x and {@Code y}.  When @Code "@Super" is invoked, all occurrences
  68. of @Code x in the body will be replaced by the object just to the left
  69. of {@Code "@Super"}, and all occurrences of @Code y will be replaced by
  70. the object just to the right.  So, for example, the expression
  71. @ID @Code {
  72. "2  @Super  { Slope @Font n }"
  73. }
  74. is equal to
  75. @ID @Code {
  76. "@OneRow {  |  -2p @Font { Slope @Font n }  ^/0.5fk  2  }"
  77. }
  78. and so comes out as {2 @Super {Slope @Font n}}.
  79. @PP
  80. Lout permits definitions to invoke themselves, a peculiarly circular
  81. thing to do which goes by the name of
  82. recursion @Index Recursion
  83. @I recursion.  Here is an example
  84. of a recursive definition:
  85. @ID @Code {
  86. "def  @Leaders  {  ..   @Leaders  }"
  87. }
  88. The usual rule is that the value of an invocation of a symbol is a copy of
  89. the body of the symbol's definition, so the value of @Code "@Leaders" must be
  90. @ID @Code {
  91. "..   @Leaders"
  92. }
  93. But now this rule applies to this new invocation of {@Code "@Leaders"};
  94. substituting its body gives
  95. @ID @Code {
  96. "..   ..   @Leaders"
  97. }
  98. and so on forever.  In order to make this useful,
  99. an invocation of a recursive symbol is replaced by its body only if
  100. sufficient space is available.  So, for example,
  101. @ID @Code {
  102. "4i @Wide { Chapter 7  @Leaders   62 }"
  103. }
  104. has for its result the object
  105. @ID {
  106. 4i @Wide { Chapter 7  @Leaders   62 }
  107. }
  108. with Lout checking before each replacement of @Code "@Leaders" by
  109. @OneCol @Code { ".."   "@Leaders" } that the total length afterwards,
  110. including the other words, would not exceed four inches.
  111. @PP
  112. The remaining issue is what happens when Lout decides that it is time to
  113. stop.  The obvious thing to do is to replace the last invocation by an
  114. empty object:
  115. @ID @Code {
  116. "..    ..    ..    ..    ..    ..    ..    ..    {}"
  117. }
  118. As the example shows, this would leave a small trailing space, which in
  119. practice turns out to be a major headache.  Lout solves this problem
  120. by replacing the last invocation with a different kind of empty object,
  121. called @@Null, whose effect is to make an adjacent concatenation symbol
  122. disappear, preferably one preceding the @@Null.  Thus, when Lout
  123. replaces @Code "@Leaders" by @@Null in the expression
  124. @ID @Code {
  125. "..    ..    ..    ..    ..    ..    ..    ..    @Leaders"
  126. }
  127. the trailing space, which is really a horizontal concatenation symbol,
  128. disappears as well.  This is carefully taken into account when deciding
  129. whether there is room to replace @Code "@Leaders" by its body at each
  130. stage.
  131. @PP
  132. The remainder of this section is devoted to showing how definitions may
  133. be used to specify the @I {page layout}
  134. page.layout @RawIndex { Page layout }
  135. page.layout.basic @SubIndex { principles of }
  136. of a document.  To begin with,
  137. we can define a page like this:
  138. @ID @Code {
  139. "def @Page"
  140. "{"
  141. "    //1i  ||1i"
  142. "    6i @Wide 9.5i @High"
  143. "    { @TextPlace  //1rt  @FootSect }"
  144. "    ||1i  //1i"
  145. "}"
  146. }
  147. Now @Code "@Page" is an eight by
  148. eleven and a half inch object, with one inch margins, a place at the top for
  149. text, and a section at the bottom for footnotes (since @Code "//1rt" leaves
  150. sufficient space to bottom-justify the following object).  It will be
  151. convenient for us to show the effect of invoking @Code "@Page" like this:
  152. @ID @Code
  153. { { //0.5ix 8p @Font "@Page" &2m => } &2m
  154. @LittlePage { "@TextPlace" //1rt "@FootSect" }
  155. }
  156. with the invoked symbol appearing to the left of the arrow, and its body to
  157. the right.
  158. @PP
  159. The definition of a vertical list of pages should come as no surprise:
  160. @ID @Code {
  161. "def @PageList"
  162. "{"
  163. "    @Page"
  164. "    //"
  165. "    @PageList"
  166. "}"
  167. }
  168. This allows invocations like the following:
  169. @ID @Code @HExpand @HScale {
  170. { //0.5ix 8p @Font "@PageList" }
  171. ||1m { //0.5ix => } ||1m
  172. {        @LittlePage { "@TextPlace" //1rt "@FootSect" }
  173.   //0.2c 8p @Font "@PageList"
  174. }
  175. ||1m { //0.5ix => } ||1m
  176. {        @LittlePage { "@TextPlace" //1rt "@FootSect" }
  177.   //     @LittlePage { "@TextPlace" //1rt "@FootSect" }
  178.   //0.2c 8p @Font "@PageList"
  179. }
  180. ||1m { //0.5ix => } ||1m
  181. {        @LittlePage { "@TextPlace" //1rt "@FootSect" }
  182.   //     @LittlePage { "@TextPlace" //1rt "@FootSect" }
  183. }
  184. }
  185. setting  @Code "@PageList" to @Code @@Null on the last step.  An
  186. arbitrary number of pages can be generated in this way.
  187. @PP
  188. A definition for @Code "@TextPlace" is beyond us at present, since
  189. @Code "@TextPlace" must be replaced by different parts of the text
  190. of the document on different pages.  We can,
  191. however, define @Code "@FootSect" to be a small space followed by a
  192. horizontal line followed by a list of places where footnotes are to go:
  193. @ID @Code {
  194. "def @FootList         "
  195. "{                     "
  196. "   @FootPlace         "
  197. "   //0.3v             "
  198. "   @FootList          "
  199. "}                     "
  200. "                      "
  201. "def @FootSect"
  202. "{                        "
  203. "   //0.3v 1i @Wide @HLine"
  204. "   //0.3v @FootList      "
  205. "}                        "
  206. }
  207. assuming that @Code "@HLine" will produce a horizontal line of the
  208. indicated width.  With this definition we can generate pages like this:
  209. @ID @Code {
  210. @LittlePage { "@TextPlace"
  211.                //1rt
  212.                "@FootSect"
  213.              }
  214. ||2m { //0.5ix => } ||2m
  215. @LittlePage { "@TextPlace"
  216.                //1rt
  217.                @OneRow { 1c @Wide @HLine
  218.                          //0.1c
  219.                          "@FootList"
  220.                        }
  221.              }
  222. ||2m { //0.5ix => } ||2m
  223. @LittlePage { "@TextPlace"
  224.                //1rt
  225.                @OneRow { 1c @Wide @HLine
  226.                          //0.1c
  227.                          "@FootPlace"
  228.                          //0.1c
  229.                          "@FootList"
  230.                        }
  231.              }
  232. }
  233. and so on for arbitrarily many footnotes.
  234. @PP
  235. We will see in the next section how invocations of @Code "@PageList",
  236. @Code "@FootSect" and @Code "@FootList" are replaced by their bodies only
  237. when the need to insert text and footnotes obliges Lout to do so;
  238. otherwise the invocations are replaced by @@Null.  In this way, the
  239. right number of pages is made, the small line appears only on pages that
  240. have at least one footnote, and unnecessary concatenation symbols
  241. disappear.
  242. @PP
  243. This approach to page layout is the most original contribution Lout has
  244. made to document formatting.  It is extraordinarily flexible.  Two-column
  245. pages?  Use
  246. @ID @Code {
  247. "{2.8i @Wide @TextPlace}  ||0.4i  {2.8i @Wide @TextPlace}"
  248. }
  249. instead of {@Code "@TextPlace"}.  Footnotes in smaller type?  Use
  250. @Code { -2p "@Font" "@FootPlace" } instead of {@Code "@FootPlace"}.  And
  251. on and on.
  252. @End @Section
  253.