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.IMPL / s2.3 < prev    next >
Text File  |  1994-01-25  |  13KB  |  315 lines

  1. @SubSection
  2.     @Tag { objects }
  3.     @Title { Basic structural operators }
  4. @Begin
  5. @PP
  6. A programming language may be considered complete when it attains the
  7. power of a Turing machine, but no such criterion seems relevant to
  8. document formatting.  Instead, as the language develops and new
  9. applications are attempted, deficiencies are exposed and the operator set is
  10. revised to overcome them.
  11. @PP
  12. Lout has a repertoire of 23 primitive operators
  13. (Figure {@NumberOf primitives}),
  14.  
  15. @Figure
  16.    @Caption { The 23 primitive operators of Lout, in order of
  17. increasing precedence. }
  18.    @Tag { primitives }
  19. @Tab
  20.    vmargin { 0.5vx }
  21.    @Fmta { @Col @I A ! @Col B }
  22. {
  23. @Rowa
  24.    A { object  {@Code "/"}gap  object }
  25.    B { Vertical concatenation with mark alignment }
  26. @Rowa
  27.    A { object  {@Code "//"}gap  object }
  28.    B { Vertical concatenation with left justification }
  29. @Rowa
  30.    A { object  {@Code "|"}gap  object }
  31.    B { Horizontal concatenation with mark alignment }
  32. @Rowa
  33.    A { object  {@Code "||"}gap  object }
  34.    B { Horizontal concatenation with top-justification }
  35. @Rowa
  36.    A { object  {@Code "&"}gap  object }
  37.    B { Horizontal concatenation within paragraphs }
  38. @Rowa
  39.    A { {@Code "@OneCol"}  object }
  40.    B { Hide all but one column mark of @I object }
  41. @Rowa
  42.    A { {@Code "@OneRow"}  object }
  43.    B { Hide all but one row mark of @I object }
  44. @Rowa
  45.    A { font  @Code "@Font"  object }
  46.    B { Render @I object in nominated font }
  47. @Rowa
  48.    A { breakstyle  @Code "@Break"  object}
  49.    B { Break paragraphs of @I object in nominated style }
  50. @Rowa
  51.    A { spacestyle  @Code "@Space"  object }
  52.    B { Render spaces between words in nominated style }
  53. @Rowa
  54.    A { length  {@Code "@Wide"}  object }
  55.    B { Render @I object to width @I length }
  56. @Rowa
  57.    A { length  {@Code "@High"}  object }
  58.    B { Render @I object to height @I length }
  59. @Rowa
  60.    A { {@Code "@HExpand"}  object}
  61.    B { Expand horizontal gaps to fill available space }
  62. @Rowa
  63.    A { {@Code "@VExpand"}  object}
  64.    B { Expand vertical gaps to fill available space }
  65. @Rowa
  66.    A { {@Code "@HScale"}  object }
  67.    B { Horizontal geometrical scaling to fill available space }
  68. @Rowa
  69.    A { {@Code "@VScale"}  object }
  70.    B { Vertical geometrical scaling to fill available space }
  71. @Rowa
  72.    A { angle  {@Code "@Rotate"}  object }
  73.    B { Rotate @I object by @I angle }
  74. @Rowa
  75.    A { PostScript  {@Code "@Graphic"}  object }
  76.    B { Escape to graphics language }
  77. @Rowa
  78.    A { @Code "@Next"  object }
  79.    B { Add 1 to an object denoting a number }
  80. @Rowa
  81.    A { object  @Code "@Case"  alternatives }
  82.    B { Select from a set of alternative objects }
  83. @Rowa
  84.    A { identifier  @Code "&&"  object }
  85.    B { Cross reference }
  86. @Rowa
  87.    A { cross-reference  @Code "@Open"  object }
  88.    B { Retrieve value from cross reference }
  89. @Rowa
  90.    A { cross-reference  @Code "@Tagged"  object}
  91.    B { Attach cross referencing tag to object }
  92. }
  93.  
  94. which has proven adequate for a wide variety of features, including equations,
  95. tables, and page layout, and so seems to be reasonably complete in this
  96. pragmatic sense.  In this section we introduce the eight concatenation and
  97. mark-hiding operators.  To them falls the basic task of assembling complex
  98. objects from simple ones, and they were the first
  99. to be designed and implemented.
  100. @PP
  101. Many of the operators of Eqn can be viewed as building small tables.  A
  102. built-up fraction, for example, has one column and three rows
  103. (numerator, line, and denominator).  Numerous investigations of this
  104. kind convinced the author that operators capable of assembling the rows
  105. and columns of tables would suffice for building all kinds of objects.
  106. @PP
  107. The simplest objects are empty objects and literal words like
  108. {@Code metempsychosis}, which have one column mark and one row mark:
  109. @ID {
  110. @ShowMarks metempsychosis
  111. }
  112. To place two arbitrary objects side by side, we use the infix
  113. operator {@Code "|"}, denoting horizontal concatenation.  For
  114. example,
  115. @ID {
  116. @Code "USA  |0.2i  Australia"
  117. }
  118. produces the object
  119. @ID {
  120. @ShowMarks USA |0.2i @ShowMarks Australia
  121. }
  122. The row marks are merged into one, fixing the vertical position of
  123. the objects relative to each other; their horizontal separation is
  124. determined by the @I gap attached to the operator, in this case 0.2
  125. inches.  We think of the gap as part of the operator, although
  126. strictly it is a third parameter.  It may be omitted, defaulting to
  127. {@Code "0i"}.
  128. @PP
  129. @I {Vertical concatenation} & , denoted by the infix operator {@Code "/"},
  130. is the same apart from the change of direction:
  131. @ID {
  132. @Code "Australia  /0.1i  USA"
  133. }
  134. produces the object
  135. @ID {
  136. @ShowMarks Australia /0.1i
  137. @ShowMarks USA
  138. }
  139. with column marks merged and a 0.1 inch gap.
  140. @PP
  141. Consider now what happens when horizontal and vertical are combined:
  142. @ID  @Code {
  143.              |1m  "{"  USA         |1m  "|0.2i" |1m   Australia  "}"
  144. /1vx "/0.1i" |    "{"  Washington  |    "|"     |     Canberra  "}"
  145. }
  146. The two parameters of @Code "/" now have two column marks each, and
  147. they will be merged with the corresponding marks in the other
  148. parameter, yielding the object
  149. @ID {
  150.       @ShowMarks USA &
  151.       { 0 ymark moveto xsize 10 pt add ymark lineto [ 3 pt ] 0 setdash stroke }
  152.       @Graphic {1c @Wide }
  153.       |0.2i @ShowMarks Australia
  154. /0.1i @ShowMarks Washington  |     @ShowMarks Canberra
  155. }
  156. The @Code "0.2i" gap separates columns, not individual items in
  157. columns, so a gap attached to the second @Code "|" would serve no
  158. purpose; any such gap is ignored.  If the number of marks to be merged
  159. differs, empty columns are added at the right to equalize the number.  The
  160. four marks protruding from the result are all available for merging
  161. with neighbouring marks by other concatenation operators.  The precedence
  162. of @Code "|" is higher than the precedence of {@Code "/"}, so the braces
  163. could be omitted.
  164. @PP
  165. When lines of text are concatenated, it is conventional to measure
  166. their separation from baseline to baseline (mark to mark in Lout),
  167. rather than from edge to edge as above.  This idea of different
  168. reference points for measurement evolved over the years into a
  169. system of six @I {gap modes} (Figure {@NumberOf gapmodes}), expressed
  170. by appending a letter to the length.  For example, @Code "|0.2i" is
  171. an abbreviation for {@Code "|0.2ie"}, meaning 0.2 inches measured
  172. from edge to edge; @Code "|0.3ix"
  173. produces a 0.3 inch gap measured from mark to mark and widened if
  174. necessary to prevent overstriking; and @Code "|2.5it" places its right
  175. parameter 2.5 inches from the current left margin, irrespective of
  176. the position of the left parameter.  There is also a choice of
  177. eleven units of measurement (inches, centimetres, multiples of the
  178. current font size, etc.), the most interesting being
  179. the @Code r unit:  one @Code r is the column width minus the width of
  180. the following object, so that @Code "|1rt" produces sufficient space
  181. to right justify the following object, and @Code "|0.5rt" to center
  182. it.  These features implement spacings needed in practice rather
  183. than suggested by theory.  They work with all five concatenation
  184. operators, horizontal and vertical.
  185.  
  186. @Figure
  187.    @Tag { gapmodes }
  188.    @Caption { The six gap modes (@I length is any length).  Hyphenation
  189. mode has an extra property not shown here. }
  190. @Fig {
  191. { /2.5vx Edge-to-edge |0.3i   {@Code "|"} &1p {@I length} &1p {@Code e}
  192.   /4.2vx Hyphenation    |0.3i   {@Code "|"} &1p {@I length} &1p {@Code h}
  193.   /4.2vx Overstrike     |0.3i   {@Code "|"} &1p {@I length} &1p {@Code o}
  194.   /4.2vx Mark-to-mark   |0.3i   {@Code "|"} &1p {@I length} &1p {@Code x}
  195.   /4.2vx Kerning        |0.3i   {@Code "|"} &1p {@I length} &1p {@Code k}
  196.   /4.2vx Tabulation     |0.3i   {@Code "|"} &1p {@I length} &1p {@Code t}
  197. }
  198. ||0.5i
  199. @Box margin { 0c } 6c @Wide 13.5c @High 9p @Font
  200. {
  201.   @OneRow {
  202.      @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  203.      @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  204.      @At { 2.2c @Wide 1.4c @High } @Put { @DoubleArrow 1.8c }
  205.      @At { 2.2c @Wide 1.6c @High } @Put { 1.8c @Wide { &0.5rt @I length } }
  206.   }
  207.   //4vx
  208.   @OneRow {
  209.      @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  210.      @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  211.      @At { 2.2c @Wide 1.4c @High } @Put { @DoubleArrow 1.8c }
  212.      @At { 2.2c @Wide 1.6c @High } @Put { 1.8c @Wide { &0.5rt @I length } }
  213.   }
  214.   //4vx
  215.   @OneRow {
  216.      @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  217.      @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  218.      @At { 1.2c @Wide 1.5c @High } @Put { @DoubleArrow 3.3c }
  219.      @At { 1.2c @Wide 1.7c @High } @Put { 3.3c @Wide { &0.5rt @I length } }
  220.   }
  221.   //4vx
  222.   @OneRow {
  223.      @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  224.      @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  225.      @At { 1.2c @Wide 1.5c @High } @Put { @DoubleArrow 3.3c }
  226.      @At { 1.2c @Wide 1.7c @High }
  227.     @Put 3.3c @Wide { |0.5rt @Eq { max(length, a+b) } }
  228.      @At { 1.2c @Wide 0.4c @High } @Put { @DoubleArrow 1.0c }
  229.      @At { 1.2c @Wide 0.2c @High } @Put { 1.0c @Wide { &0.5rt @I a } }
  230.      @At { 4c   @Wide 0.4c @High } @Put { @DoubleArrow 0.5c }
  231.      @At { 4c   @Wide 0.2c @High } @Put { 0.5c @Wide { &0.5rt @I b } }
  232.   }
  233.   //4.5vx
  234.   @OneRow {
  235.      @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  236.      @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  237.      @At { 1.2c @Wide 1.5c @High } @Put { @DoubleArrow 3.3c }
  238.      @At { 1.2c @Wide 1.7c @High }
  239.     @Put { 3.3c @Wide { |0.5rt @Eq { max(length, a, b) } } }
  240.      @At { 1.2c @Wide 0.4c @High } @Put { @DoubleArrow 1.0c }
  241.      @At { 1.2c @Wide 0.2c @High } @Put { 1.0c @Wide { &0.5rt @I a } }
  242.      @At { 4c   @Wide 0.4c @High } @Put { @DoubleArrow 0.5c }
  243.      @At { 4c   @Wide 0.2c @High } @Put { 0.5c @Wide { &0.5rt @I b } }
  244.   }
  245.   //4vx
  246.   @OneRow {
  247.      @At { 1c   @Wide 0.5c @High } @Put { @LBox 0.2co }
  248.      @At { 4c   @Wide 0.5c @High } @Put { @LBox 0.5co }
  249.      @At { 0.0c @Wide 1.6c @High } @Put { @DoubleArrow 4.0c }
  250.      @At { 2.8c @Wide 1.8c @High } @Put { @I length }
  251.   }
  252.   //5vx
  253.   @DoubleArrow 6c
  254.   //0.1c |0.5rt @I { current bound }
  255. }
  256. }
  257.  
  258. @PP
  259. When we construct a built-up fraction, the result has three row marks, but
  260. only the second should be visible outside the object:
  261. @ID @Eq { @ShowMarks { X over Y } }
  262. This is a common problem, and accordingly a @Code "@OneRow" operator was
  263. introduced for hiding all but one of the row marks of its
  264. parameter.  Normally, the first mark is the survivor, but a later mark can
  265. be chosen by prefixing @Code "^" to the preceding concatenation operator:
  266. @ID @Code "@OneRow { X  ^/2p  @HLine  /2p  Y }"
  267. has the desired result, where {@Code "2p"} is two points and @Code "@HLine"
  268. is an easy combination of Lout's graphics operators.  A similar operator,
  269. {@Code "@OneCol"}, hides column marks.
  270. @PP
  271. A variant of @Code "/" called @Code "//" is provided which performs
  272. vertical concatenation but ignores all column marks and simply
  273. left-justifies its two parameters:
  274. @ID @Code {
  275. "Heading  //0.1i"
  276. "A  |0.2i  B  /0.1i"
  277. "C  |  D"
  278. }
  279. has result
  280. @ID { Heading //0.1i  A  |0.2i  B  /0.1i  C  |  D }
  281. showing that spanning columns in tables motivate the inclusion of this
  282. operator.  There is an analogous @Code "||" operator.  The author
  283. would have preferred to leave out these operators, since they
  284. complicate the implementation, and it is interesting to examine the
  285. prospects of doing so.
  286. @PP
  287. The @Code "//" operator is formally redundant, because in general
  288. the expression @Code "x // y" can be replaced by
  289. @ID @Code {
  290. "@OneCol {  |  x  }   /"
  291. "@OneCol {  |  y  }"
  292. }
  293. for any objects {@Code x} and {@Code y}.  By concatenating an empty
  294. object at the left of @Code x and hiding all but that empty object's
  295. column mark, we effectively shift {@Code x}'s column mark to its left
  296. edge.  The same goes for {@Code y}, so the @Code "/" operator has just
  297. one column mark to merge, at the extreme left, and its effect is
  298. indistinguishable from {@Code "//"}.
  299. @PP
  300. Unfortunately, if @Code y consists of two rows separated by {@Code "/"},
  301. as in the example above, both rows must be placed inside the
  302. {@Code "@OneCol"}, and the table cannot be entered in the simple
  303. row-by-row manner that non-expert users naturally expect.  Another
  304. advantage of @Code "//" is that its left parameter can be printed
  305. before its right parameter is known; this is important when the left
  306. parameter is an entire page.
  307. @PP
  308. The fifth and final concatenation operator, {@Code "&"}, is an explicit
  309. version of the horizontal concatenation operator interpolated when
  310. objects are separated by white space.  It is formally identical to
  311. @Code "|" except for taking higher precedence and being subject to
  312. replacement by @Code "//1vx" during paragraph breaking
  313. (Section {@NumberOf style}).
  314. @End @SubSection
  315.