tri.tex 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. \relax
  2. % **********************************************************************
  3. % **** ****
  4. % **** DRAFT: The TeX-REDUCE-Interface ****
  5. % **** Werner Antweiler, University of Cologne, August 1, 1988 ****
  6. % **** ****
  7. % **********************************************************************
  8. \magnification=1200
  9. \hoffset=10truemm\hsize=16truecm\vsize=10truein
  10. \tolerance 1500 \hbadness=800
  11. \parindent=12pt \parskip=0pt \displayindent=30pt
  12. \baselineskip=12pt plus0.1pt minus0.2pt
  13. \newdimen\narrowskip \narrowskip=10pt
  14. % Make Use of 12pt-Fonts Default
  15. %
  16. \font\caps=cmcsc10
  17. \font\smallcaps=cmcsc10 at 10truept
  18. \font\small=cmr8
  19. \font\smallit=cmti8
  20. \font\smallbf=cmbx8
  21. \font\smalltt=cmtt8
  22. \font\big=cmbx10 at 15pt
  23. %
  24. \catcode`\"=\active \let"=\" \let\3=\ss
  25. \def\zB{z.B.\ }
  26. \def\D{\char'042}
  27. \def\B{\char'134}
  28. % -----------
  29. % Hilfsmacros
  30. % -----------
  31. \def\ttq{\par\vskip3.6135pt\begingroup\baselineskip=14.454pt
  32. \parindent=30pt\parskip=0pt\let\par=\endgraf\obeyspaces\obeylines\tt\ttf}
  33. {\obeylines\gdef\ttf^^M#1\endtt{\vbox{#1}\endgroup\par\noindent}}
  34. {\obeyspaces\gdef {\ }}
  35. \def\iq#1{{\it#1\/}}
  36. \def\quote{\par\begingroup\leftskip=\parindent
  37. \baselineskip=9.03pt\small\noindent}
  38. \def\endquote{\par\endgroup\par}
  39. \def\today{\ifcase\month\or January\or February\or March\or April\or May\or
  40. June\or July\or August\or September\or October\or November\or December\fi
  41. \space\number\day, \number\year}
  42. \def\endpage{\par\vfill\eject}
  43. \newcount\Defcount \Defcount=0
  44. \def\Def#1\par{\global\advance\Defcount by1\par
  45. \vskip3.6135pt{\baselineskip=14.454pt
  46. \noindent\bf Definition \the\Defcount:\sl\enspace#1\par}}
  47. \let\YY=\let % now you can send the control sequence \YY
  48. \newcount\Figcount \Figcount=0
  49. \def\VFig{\vFig\smalltt}
  50. \def\VVFig{\vFig\tt}
  51. \def\vFig#1{\midinsert\global\advance\Figcount by 1
  52. \message{[Fig. \the\Figcount]}
  53. \vbox\bgroup
  54. \hrule height.6pt
  55. \hbox to\hsize\bgroup
  56. \vrule width.6pt \hskip 9.4pt
  57. \vbox\bgroup
  58. \advance\hsize by-20pt \line{}
  59. \vskip 9.4pt \nointerlineskip
  60. \let\vtt=#1\verbatim}
  61. \def\endVFig#1:#2\par{\vskip 9.4pt
  62. \egroup \hss \vrule width.6pt
  63. \egroup \hrule height.6pt
  64. \vskip3pt\baselineskip=\narrowskip
  65. \noindent\smallbf Fig. \the\Figcount: #1.
  66. \small #2\par
  67. \egroup\endinsert}
  68. % ------------------
  69. % Fussnotensteuerung
  70. % ------------------
  71. \newcount\notenumber\notenumber=0
  72. \def\vfootnote#1{\insert\footins\bgroup
  73. \interlinepenalty=\interfootnotelinepenalty
  74. \splittopskip=\ht\strutbox \splitmaxdepth=\dp\strutbox
  75. \floatingpenalty=20000 \leftskip=0pt \rightskip=0pt
  76. \spaceskip=0pt \xspaceskip=0pt
  77. \item{#1}\footstrut\futurelet\next\fooot}
  78. \def\fooot{\ifcat\bgroup\noexpand\next\let\next\foooot
  79. \else\let\next\foot\fi\next}
  80. \def\foooot{\bgroup\aftergroup\oofoot\let\next}
  81. \def\foot#1{#1\oofoot}
  82. \def\oofoot{\strut\egroup}
  83. \def\note#1{\global\advance\notenumber by1
  84. \begingroup\small\baselineskip=\narrowskip
  85. \setbox\strutbox=\hbox{\vrule height7.0pt depth3.0pt width0pt}%
  86. \footnote{$^{\the\notenumber}$}{\bgroup\small\baselineskip=\narrowskip
  87. #1\egroup}\endgroup}
  88. % -----------------------------------
  89. % Seitenkopf und Fusszeilen-Steuerung
  90. % -----------------------------------
  91. \pageno=1
  92. \headline={\ifnum\pageno=1\hfill\else\hfill\rm---\ \folio\ ---\hfill\fi}
  93. \footline={\hfil}
  94. % ------------------
  95. % Inhaltsverzeichnis
  96. % ------------------
  97. \let\ZZ=\let % now you can send the control sequence \ZZ
  98. \newcount\seccount \seccount=0
  99. \newcount\subseccount \subseccount=0
  100. \newcount\subsubseccount \subsubseccount=0
  101. \def\secnum{\number\seccount%
  102. \ifnum\subseccount=0\else.\number\subseccount\fi%
  103. \ifnum\subsubseccount=0\else.\number\subsubseccount\fi}
  104. % --------
  105. % Textteil
  106. % --------
  107. \newbox\secbox
  108. \def\secindent#1#2#3{\par\bigskip\begingroup
  109. \message{\secnum #1}\setbox\secbox=\hbox{#3\secnum\hskip1.5em}
  110. \hangafter=1\hangindent=\wd\secbox\baselineskip=\ht\secbox
  111. \advance\baselineskip by5pt
  112. \noindent #3\box\secbox#1
  113. \par\endgroup\nobreak\smallskip
  114. \nobreak\smallskip\vskip-\parskip\noindent}
  115. \def\sec#1\par{\global\advance\seccount by1\global\subseccount=0
  116. \global\subsubseccount=0\secindent{#1}{0}\bf}
  117. \def\subsec#1\par{\global\advance\subseccount by1
  118. \global\subsubseccount=0\secindent{#1}{1}\bf}
  119. \def\subsubsec#1\par{\global\advance\subsubseccount by1
  120. \secindent{#1}{2}\bf}
  121. % --------------
  122. % Spezial Makros
  123. % --------------
  124. \def\center{\vskip\parskip\begingroup
  125. \parindent=0pt \parskip=0pt plus 1pt
  126. \rightskip=0pt plus 1fill \leftskip=0pt plus 1fill
  127. \obeylines}
  128. \def\endcenter{\endgroup}
  129. \def\flushleft{\vskip\parskip\begingroup
  130. \parindent=0pt \parskip=0pt plus 1pt
  131. \rightskip=0pt plus 1fill \leftskip=0pt
  132. \obeylines}
  133. \def\endflushleft{\endgroup}
  134. \def\flushright{\vskip\parskip\begingroup
  135. \parindent=0pt \parskip=0pt plus 1pt
  136. \rightskip=0pt \leftskip=0pt plus 1fill
  137. \obeylines}
  138. \def\endflushright{\endgroup}
  139. \def\itemize#1{\par\begingroup\parindent=#1}
  140. \def\litem#1{\par\hang\noindent\hbox to \parindent{#1\hfil}}
  141. \def\ritem#1{\par\hang\noindent\hbox to \parindent{\hfil#1\enspace}}
  142. \def\sitemize#1{\par\begingroup\parindent=#1\baselineskip=\narrowskip\small}
  143. \def\enditemize{\par\endgroup\par}
  144. \def\bitem{\ritem{$\bullet$}}
  145. % ------------
  146. % Mathe-Makros
  147. % ------------
  148. \newcount\eqcount \eqcount=0
  149. \newcount\eqoffcount
  150. \def\adveq{\global\advance\eqcount by1}
  151. \def\eqcon{\adveq(\number\eqcount)}
  152. \def\eqco{\eqno{\eqcon}}
  153. \def\ceqc#1{(\number\eqcount.#1)}
  154. \def\ceqalign{\adveq\eqalignno}
  155. \def\eqoff#1{\eqoffcount=\eqcount\advance\eqoffcount by-#1%
  156. (\the\eqoffcount)}
  157. \catcode`\*=\active \def*{\ifmmode\cdot\else\char'52\fi}
  158. % Spezialmakros
  159. \def\aut#1 \ttl#2 \pub#3 \ref#4 \dat#5 \inx#6 \^^M{\par
  160. {\baselineskip=\narrowskip
  161. \parindent=24pt\hang\noindent{\smallcaps#1}\small\ (#6) #2. #3, #5%
  162. \ifx\\#4\else, #4\fi.\par}\medskip\penalty0}
  163. \def\example{\par\vskip5pt\flushleft\tt\parindent=50pt}
  164. \def\endexample{\endflushleft\vskip5pt\noindent\ignorespaces}
  165. \def\i#1{{\it #1\/}}
  166. \def\t#1{{\tt #1}}
  167. \def\VAX{$\mu$VAX-I\kern-0.1em I}
  168. % ----------------------------------------------------------------------
  169. % Verbatim Mode Macros
  170. % ----------------------------------------------------------------------
  171. \def\uncatcodespecials{\def\do##1{\catcode`##1=12}\dospecials\do\"}
  172. \let\vtt=\tt
  173. \def\setupverbatim{\vtt\Obeylines\uncatcodespecials\obeyspaces}
  174. \def\newlinepar{~\par}
  175. {\catcode`\^^M=\active % these lines must end with `%'
  176. \gdef\Obeylines{\catcode`\^^M=\active\def^^M{\newlinepar}}}%
  177. {\obeyspaces\global\let =\ }
  178. \def\verbatim{\par\begingroup\parskip=0pt plus 1pt
  179. \ifx\vtt\smalltt\baselineskip=10pt\fi
  180. \setupverbatim\doverbatim}
  181. {\catcode`\|=0 \catcode`\\=12
  182. |Obeylines|gdef|doverbatim^^M#1\endverbatim{#1|endgroup}}
  183. \def\verb{\begingroup\setupverbatim\doverb}
  184. \def\doverb#1{\def\next##1#1{##1\endgroup}\next}
  185. % ----------------------------------------------------------------------
  186. % REDUCE-LISP Programming Language Documentation
  187. % ----------------------------------------------------------------------
  188. \newdimen\xindent \dimen\xindent=15pt
  189. \catcode`\@=\active
  190. \def\@{\char'100}
  191. \def@{\hskip\dimen\xindent\ignorespaces}
  192. \def\gets{$\leftarrow$}
  193. \def\\#1/{{\it#1\/\kern.05em}} % italic type for identifiers
  194. \def\&#1&{{\bf#1\/}} % boldface type for reserved words
  195. \def\.#1.{{\tt#1\/}} % typewriter type for strings
  196. \def\!#1!{{\rm$\langle$ #1 $\rangle$\/}} % roman for operations
  197. \def\[#1]{{\rm$\{$ #1 $\}$}} % comments in roman
  198. \def\DOC{\midinsert\global\advance\Figcount by 1
  199. \message{[Fig. \the\Figcount]}
  200. \vbox\bgroup
  201. \hrule height.6pt
  202. \hbox to\hsize\bgroup
  203. \vrule width.6pt \hskip 9.4pt
  204. \vbox\bgroup
  205. \advance\hsize by-20pt \line{}
  206. \vskip 9.4pt \nointerlineskip
  207. \parindent=0pt \parskip=0pt plus 1pt
  208. \rightskip=0pt plus 1fill \leftskip=0pt
  209. \begingroup\obeylines}
  210. \def\endDOC{\endgroup\endDoc}
  211. \def\endDoc#1:#2\par{\vskip 9.4pt
  212. \egroup \hss \vrule width.6pt
  213. \egroup \hrule height.6pt
  214. \vskip3pt\baselineskip=\narrowskip
  215. \noindent\smallbf Fig. \the\Figcount: #1.\ \small#2\par
  216. \egroup\endinsert}
  217. % ----------------------------------------------------------------------
  218. % Titel
  219. % ----------------------------------------------------------------------
  220. \line{}
  221. \vskip10mm
  222. \center\big\baselineskip=24pt
  223. Typesetting REDUCE output with \TeX
  224. --- A REDUCE-\TeX-Interface ---
  225. \endcenter
  226. \vskip13mm
  227. \center\baselineskip=12pt
  228. \smallcaps Werner Antweiler
  229. \smallcaps Andreas Strotmann
  230. \smallcaps Volker Winkelmann
  231. \small University of Cologne Computer Center, West Germany{\parindent=12pt%
  232. \note{The authors are with: %
  233. Rechenzentrum der Universit"at zu K"oln (University of Cologne %
  234. Computer Center), %
  235. Abt. Anwendungssoftware (Application Software Department), %
  236. Robert-Koch-Stra\3e 10, 5000 K"oln 41, West Germany.}}
  237. \small\today
  238. \endcenter
  239. \vskip15mm
  240. \begingroup\narrower\narrower\baselineskip=\narrowskip
  241. \noindent\smallbf Abstract: \small
  242. REDUCE is a well known computer algebra system invented by
  243. Anthony C. Hearn.
  244. Although a pretty-printer is already incorporated in REDUCE,
  245. the output is produced only in line-printer quality.
  246. The simple idea to produce high quality output from REDUCE
  247. is to link REDUCE with Donald E. Knuth's famous \TeX\ typesetting
  248. language. This draft reviews our efforts in this direction.
  249. We introduce a program written in REDUCE-Lisp which is able to typeset REDUCE
  250. formulas using \TeX. Our REDUCE-\TeX-Interface incorporates three
  251. levels of \TeX\ output: without line breaking, with line breaking,
  252. and with line breaking plus indentation. This paper deals with
  253. some of the ideas we have put into LISP-code and it summarizes some of our
  254. experiments we have made with it yet. Furthermore, we compile a small
  255. user's manual introducing to the use of our REDUCE-\TeX-Interface.
  256. \par\bigskip
  257. \noindent\smallbf Keywords: \small
  258. Line-Breaking Algorithm, LISP, Prefix-to-Infix Conversion,
  259. REDUCE, \TeX, Typesetting
  260. \par\endgroup\vskip10mm
  261. \rm
  262. %begin(text)
  263. % ----------------------------------------------------------------------
  264. \sec Introduction\par
  265. % ----------------------------------------------------------------------
  266. REDUCE is a well known computer algebra system invented by
  267. Anthony C. Hearn. While every effort was made to improve
  268. the system's algebraic capabilities, the readability of the
  269. output remained poor by modern typesetting standards.
  270. Although a pretty-printer is already incorporated in REDUCE,
  271. the output is produced only in line-printer quality.
  272. The simple idea to produce high quality output from REDUCE
  273. is to link REDUCE with Donald E. Knuth's famous \TeX\ typesetting
  274. language. This draft reviews our efforts in this direction.
  275. We introduce a program written in REDUCE-Lisp to typeset REDUCE
  276. formulas with \TeX. Our REDUCE-\TeX-Interface incorporates three
  277. levels of \TeX\ output: without line breaking, with line breaking,
  278. and with line breaking plus indentation. While speed
  279. without line breaking is comparable to that achieved with
  280. REDUCE's pretty-printer, line breaking consumes much more CPU time.
  281. Nevertheless, we reckon with a cost increase due to line breaking
  282. which is almost linear in the length of the expression to be broken.
  283. This paper deals with some of the ideas and algorithms we have
  284. programmed and it summarizes some of the experiments we have made
  285. with our program.
  286. Furthermore, at the end of this paper we provide a small user's manual
  287. which gives a short introduction to the use of our REDUCE-\TeX-Interface.
  288. For simplicity's sake the name ``REDUCE-\TeX-Interface'' will be
  289. abbreviated to ``TRI'' in this paper.\note{The reason why it was called
  290. TRI and not RTI is simply due to the fact that TRI corresponds better
  291. to the three-level (``tri-level'') mode.}
  292. At this point we should mention major goals we pursue with TRI:
  293. \bitem We want to produce REDUCE-output in typesetting quality.\par
  294. \bitem The intermediate files (\TeX-input files) should be easy to edit.
  295. The reason is that it is likely that the proposed
  296. line-breaks are sub-optimal from the user's point of view.\par
  297. \bitem We apply a \TeX-like algorithm which ``optimizes''
  298. the line-breaking over the whole expression. This differs
  299. fundamentally from the standard left-to-right, one-line look-ahead
  300. pretty-printers of REDUCE, LISP and the like.\par
  301. % ----------------------------------------------------------------------
  302. \sec From REDUCE to \TeX: concepts\par
  303. % ----------------------------------------------------------------------
  304. REDUCE uses the function \t{varpri} to decide how to output a REDUCE
  305. expression. The function gets three arguments: the expression to be
  306. printed, a list of variables to each of which the expression to be
  307. printed gets assigned, and a flag which determines if the expression to be
  308. printed is the first, last or only expression in the line. \t{varpri}
  309. may be called consecutively for preparing a line for output. So, our
  310. task is to assemble all expressions before finally printing them.
  311. We rewrote \t{varpri} in order to redirect output to our function
  312. \t{TeXvarpri}, which receives a REDUCE expression, translates it into
  313. \TeX\ and pushes it onto a variable called \t{TeXStack*} before
  314. eventually printing it once the line is completed.\par
  315. The \t{TeXvarpri} function first calls a function named \t{makeprefix}.
  316. Its job is to change a REDUCE algebraic expression to a standard prefix list
  317. while retaining the tree structure of the whole expression. Generally, this
  318. is done using a call \t{prepsq*(simp(expression))}, but lists and
  319. matrices need some special treatment. After this has been done the
  320. new intermediate expression is passed to the most important module
  321. of the TRI: the \t{mktag/makefunc}-family.\note{The whole family currently
  322. has five members. The ``parents'' are the mktag and makefunc
  323. functions which do the most burdensome job. The ``children'' are
  324. \t{makearg, makemat and makeDF} which handle special cases such as
  325. list construnction or differentiation operators. We do not review
  326. the minor functions since they are easily understandable.}
  327. These functions recursively expand the structured list (or operator tree)
  328. into a flat list, translating each REDUCE symbol or
  329. expression into so-called \TeX-items on passing by.
  330. For that reason, this list is called the \TeX-item list.
  331. If the simple \TeX-mode (without line breaking) was chosen this list
  332. is then printed immediately without further considerations.
  333. Translation and printing this way is almost as fast as with
  334. the standard REDUCE pretty printer.\par
  335. When line-breaking has been enabled things get a bit more complicated.
  336. The greatest effort with TRI was to implement the line-breaking
  337. algorithm. More than half of the entire TRI code deals with this
  338. task.
  339. The ultimate goal is to add some ``break items'', i.e. \verb|\nl|-%
  340. \TeX-commands\note{This is not a \TeX-primitive but a TRI-specific
  341. \TeX-macro command which expands into a lot of stuff.},
  342. marking --- in a certain way --- optimal line-breaks.
  343. Additionally, these break items can be followed immediately by
  344. ``indentation items'', i.e. \verb|\OFF{...}| \TeX-commands\note{see
  345. previous footnote}, specifying
  346. the amount of indentation applicable for the next new line.
  347. The problem is to choose the right points where to insert these
  348. special \TeX-items. Therefore, the \TeX-item list undergoes
  349. three further transformation steps.\par
  350. First, the \TeX-item list gets enlarged by so-called ``glue items''.
  351. Glue items are two-element lists, where the first element is a width
  352. info and the second element is a penalty info. The ``penalty'' is
  353. a value in the range $-10000\ldots+10000$ indicating a mark-up on a
  354. potential break-point, thus determining if this point is a
  355. fairly good (if negative) or bad (if positive) choice.
  356. The amount of penalty depends (a) on the kind of \TeX-items
  357. surrounding the glue item, (b) on the bracket nesting, and finally
  358. (c) on special characteristics.\note{For example, the plus- and
  359. the difference operator have special impact on the amount of
  360. penalty.} The function handling this job is named
  361. \t{insertglue} which implicitly calls the function
  362. \t{interglue}. The latter determines the glue item to insert
  363. between a left and a right \TeX-item.\par
  364. During the second level, the \TeX-item list becomes transformed
  365. into a so-called breaklist consisting of active and passive nodes.
  366. A passive node is simply a width info giving the total width of
  367. \TeX-items not interspersed by glue items. On the other hand,
  368. active nodes are glue items enlarged by a third element, the
  369. offset info, indicating an indentation level which is used later
  370. for computing the actual amount of indentation.
  371. Active nodes are used as potential breakpoints.
  372. Moreover, while creating the breaklist, the \TeX-item list will be
  373. modified if necessary according to the length of fractions and square
  374. roots which cannot be broken if retained in their ``classical''
  375. form. Hence fractions look like \t{(...)/(...)} if they don't fit
  376. into a single line, especially in the case of large polynomial fractions.
  377. The major function for this job is named \t{breaklist} which
  378. calls \t{resolve} if necessary.
  379. \par
  380. The third and most important level is the line-breaking algorithm
  381. itself. This algorithm embedded in the function \t{trybreak}
  382. will be described below. The idea how to break lines is based
  383. on the article by Knuth/Plass(1981). Line-breaking can occur at
  384. active nodes only. So, you can loop through the breaklist considering
  385. all potential break-points. But in order to find a suitable way
  386. in a reasonable amount of time you have to limit the number of
  387. potential breakpoints considered. This is performed by associating
  388. a ``badness'' with each potential breakpoint, describing how
  389. good looking or bad looking a line turns out. If the badness is less than
  390. a given amount of ``tolerance'' --- as set by the user ---
  391. then an active node is considered to be feasible and becomes
  392. a delta node. A delta node is simply an active node enlarged
  393. by four further infos: an identification number for this node,
  394. a pointer to the best feasible break-point (i.e. delta-node) to come from%
  395. \note{If one were to break the formula at this delta-node, the
  396. best place to start this line is given by this pointer.}
  397. the total amount of demerits (i.e. a compound value derived from
  398. badness and penalty) accumulated so far, and a value indicating
  399. the amount of indentation applied to a new line beginning at this
  400. node.
  401. When \t{trybreak} has stepped through the list, the breakpoints
  402. will have been determined. Afterwards all glue items (i.e. active nodes)
  403. are deleted from the \TeX-item list while break- and indentation-%
  404. items for those nodes marked as break-points are inserted.
  405. \par
  406. Finally the \TeX-item list is printed with regular ASCII-characters.
  407. We didn't put much emphasis on the question on how to format the
  408. intermediate output since it will be input directly into
  409. \TeX. The best way to characterize the routine \t{texout}
  410. is to call it quick and dirty. The readabiltiy of the output
  411. is low, but it may be quite good enough for users
  412. to do some final editing work.
  413. Nevertheless, \t{texout} keeps the nesting structure of the term
  414. visible when printed, so it will be easy to distinguish between
  415. parenthesis levels simply by considering the amount of indentation.
  416. % ----------------------------------------------------------------------
  417. \sec Creating a \TeX-item list\par
  418. % ----------------------------------------------------------------------
  419. The first \TeX-specific step in preparing a typesettable equivalent
  420. of a REDUCE expression is to expand the operator tree generated by
  421. REDUCE into a so-called \TeX-item list. The operator tree is
  422. preprocessed by \t{makeprefix} in order to receive an operator tree
  423. in standard prefix notation. A \TeX-item is either a character (letter or
  424. digit or special character) or a \TeX-primitive
  425. or -macro (i.e. a LISP symbol), with properties \t{'CLASS}, \t{'TEXTAG},
  426. \t{'TEXNAME} and (only if the item represents an operator)
  427. \t{'TEXPREC}, \t{'TEXPATT} and \t{'TEXUBY}
  428. bound to them, depending on what kind of \TeX-item it actually is.
  429. The latter three properties are used for operators only. \t{'TEXPREC}
  430. is the precedence of the operator, a number between 0 and 999.
  431. Here the value itself is less important than the position with
  432. respect to other operators' precedences. The remaining properties
  433. will be described later.
  434. \par
  435. First let's have a look at how a REDUCE expression arriving at TRI's main
  436. entry --- the function \t{TeXvarpri} --- is transformed through
  437. several levels of TRI-processing. For instance, let us consider
  438. the expression $(x-y)^{12}$, which expands into a polynomial
  439. $x^{12}-12*x^{11}*y+\cdots-12*x*y^{11}+y^{12}$ when evaluated.
  440. REDUCE uses a special form to store an expression. This form is
  441. called ``standard quotient'' because it in fact represents a quotient of two
  442. polynomials. The contents of the following figure 1 shows the
  443. ``standard quotient'' form of our example.\par
  444. % ----------------------------------------------------------------------
  445. \VFig
  446. (*SQ ((((X . 12) . 1)
  447. ((X . 11) ((Y . 1) . -12))
  448. ((X . 10) ((Y . 2) . 66))
  449. ((X . 9) ((Y . 3) . -220))
  450. ((X . 8) ((Y . 4) . 495))
  451. ((X . 7) ((Y . 5) . -792))
  452. ((X . 6) ((Y . 6) . 924))
  453. ((X . 5) ((Y . 7) . -792))
  454. ((X . 4) ((Y . 8) . 495))
  455. ((X . 3) ((Y . 9) . -220))
  456. ((X . 2) ((Y . 10) . 66))
  457. ((X . 1) ((Y . 11) . -12))
  458. ((Y . 12) . 1)
  459. ) . 1) T)
  460. \endverbatim
  461. \endVFig Standard Quotient Notation: This form is the way REDUCE represents
  462. terms.\par
  463. % ----------------------------------------------------------------------
  464. \noindent The term has been indented by hand to retain the structure
  465. of this expression. Actually the denominator is 1 as you easily find out
  466. from the last line.\note{The ``T'' in the last line is an ``already-%
  467. simplified''-flag indicating that the term doesn't need to undergo any more
  468. processing.} Obviously the standard-quotient form is a bit complicated
  469. for further manipulations. It can be changed to a real prefix
  470. notation as displayed in figure 2. Here, too, the term was edited
  471. by hand to make it a bit more readable and comparable to the other
  472. forms.\note{``Edit'' only means we have provided some additional
  473. indentation. We have changed neither the expression nor its structure.}
  474. Note that \t{PLUS} is not a binary but a $n$-ary operator,
  475. i.e. it takes an arbitrary number of arguments, while \t{MINUS} is
  476. always a unary operator.\note{The same problem arises with the
  477. RECIP-operator which is the unary form of the binary QUOTIENT-%
  478. operator.} This causes a bit of trouble because real
  479. binary operators are much easier to handle. To tackle this problem
  480. we have introduced the \t{'TEXUBY} property, which is used to change
  481. a unary into a binary form if possible.\par
  482. % ----------------------------------------------------------------------
  483. \VFig
  484. (PLUS (EXPT X 12)
  485. (MINUS (TIMES 12 (EXPT X 11) Y ))
  486. (TIMES 66 (EXPT X 10) (EXPT Y 2))
  487. (MINUS (TIMES 220 (EXPT X 9) (EXPT Y 3)))
  488. (TIMES 495 (EXPT X 8) (EXPT Y 4))
  489. (MINUS (TIMES 792 (EXPT X 7) (EXPT Y 5)))
  490. (TIMES 924 (EXPT X 6) (EXPT Y 6))
  491. (MINUS (TIMES 792 (EXPT X 5) (EXPT Y 7)))
  492. (TIMES 495 (EXPT X 4) (EXPT Y 8))
  493. (MINUS (TIMES 220 (EXPT X 3) (EXPT Y 9)))
  494. (TIMES 66 (EXPT X 2) (EXPT Y 10))
  495. (MINUS (TIMES 12 X (EXPT Y 11)))
  496. (EXPT Y 12))
  497. \endverbatim
  498. \endVFig Prefix Notation: This list represents the state after
  499. application of {\smalltt makeprefix}\par
  500. % ----------------------------------------------------------------------
  501. A REDUCE expression is expanded using the two functions \t{mktag}
  502. and \t{makefunc}. Function \t{mktag} identifies the operator and is
  503. able to put some brackets around the expression if necessary.
  504. \t{makefunc} is a pattern oriented ``unification''\note{in the
  505. terminology of the programming language Prolog} function, which matches
  506. arguments of a REDUCE expression in order of appearance with so-called
  507. ``unification tags'', as explained below. Thus, \t{mktag} and
  508. \t{makefunc} are mutually dependent and highly recursive functions.\par
  509. A ``unification tag list'' is a list (or a pattern, if you like)
  510. which consists of single ``unfication tags''.
  511. Each REDUCE operator is associated with a unification pattern.
  512. While expanding the expression, each tag is replaced by the appropiate
  513. \TeX-item or partial \TeX-item list created subsequently.
  514. A tag is defined as either an atom declared as a \TeX-item or one of
  515. the following:\par\itemize{27mm}\smallskip
  516. \litem{(F)}insert operator
  517. \litem{(X)}insert non-associative argument
  518. \litem{(Y)}insert a left- or right-associative argument
  519. \litem{(Z)}insert superscript/subscript argument
  520. \litem{(R)}use tail recursion to unify remaining arguments (necessary
  521. with operators having more than two arguments, e.g. the plus operator;
  522. associativity depends on previous (X) or (Y) tag)
  523. \litem{(L \i{hs})}insert a list of arguments (eat up all arguments on
  524. passing by); put \i{hs} as a horizontal separator between the arguments
  525. (e.g., a separator could be a comma for simple argument lists.)
  526. \litem{(M \i{vs} \i{hs})}insert a matrix (and eat up all arguments on
  527. passing by); put \i{vs} as a vertical separator and \i{hs} as a
  528. horizontal separator between the rows and columns
  529. \litem{(APPLY \i{fun})}apply function \i{fun} to remaining argument list
  530. \par\enditemize\smallskip
  531. \noindent
  532. These ``tags'' are assembled to a tag-list or pattern, respectively.
  533. For each functor (i.e. the head of a prefix list, e.g. \t{PLUS},
  534. \t{MINUS} or \t{SQRT}) such a list is bound to its property
  535. \t{'TEXPATT}. For instance, the functor \t{PLUS} has got the pattern
  536. \t{((X) (F) (R))} bound to it, and the functor \t{EXPT} possesses the
  537. pattern \verb|((X) ^{ (Z) })|.
  538. The following two boxes with pseudo-code (figures 3 and 4)
  539. survey the two major functions performing the expansion of a
  540. prefix REDUCE-expression into a TeX-item list.\par
  541. % ----------------------------------------------------------------------
  542. \DOC
  543. \&function& \\mktag/(\\tag/,\\outer-precedence/,\\associative/);
  544. \&begin&
  545. @ \&if& \!tag is empty! \&then return nil&
  546. @ \&else if& \!tag is an atom! \&then return& \!get the \TeX-item for%
  547. \\tag/!
  548. @ \&else begin& \[the tag is a list]
  549. @ @ \\precedence/\gets\!precedence of this tag or 999!
  550. @ @ \[now expand the expression, the first element is the]
  551. @ @ \[functor, the following elements are the arguments]
  552. @ @ \\term/\gets\\makefunc/(\&car& \\tag/,\&cdr& \\tag/,\\precedence/);
  553. @ @ \[check for parentheses: term is surrounded by parentheses in order]
  554. @ @ \[to prevent it from overruling by precedence]
  555. @ @ \&if& (\\associative/ \&and& (\\precedence/ = \\outer-precedence/))
  556. @ @ @ \&or& (\\precedence/ $<$ \\outer-precedence/)
  557. @ @ \&then& \\term/\gets\!put a pair of brackets around \\term/!;
  558. @ @ \&return& \\term/
  559. @ \&end&
  560. \&end&;
  561. \endDOC The function {\smalltt mktag}: This function deals with the
  562. transformation from prefix notation to \TeX\ notation. One important
  563. task of it is to decide whether or not brackets should be placed
  564. around the term.\par
  565. % ----------------------------------------------------------------------
  566. At this point, the way we use our LISP pseudo-code should be
  567. explained. Words typeset in boldface are reserved words, e.g.
  568. \&begin& and \&end&. We use a PASCAL-like syntax which is actually
  569. used by REDUCE-Lisp, too, but with a few differences: we use the
  570. word \&function& to indicate that a value is returned\note{REDUCE-Lisp
  571. uses the phrase ``symbolic procedure'' here.}, and
  572. we use \&return& to return the value of the function and therefore
  573. to exit the function. This is in contrast to the use of \t{return}
  574. in REDUCE-Lisp, where \t{return} is used only to return the value
  575. of a begin-end-block. Identifiers are printed in italics. Where
  576. identifiers are used as logical values, e.g. in conditions, they
  577. are either false if their value is \&nil& or true otherwise,
  578. regardless of their exact value. Pseudo-operations are printed
  579. in roman and are put in angle brackets. Comments, too, are printed
  580. in roman but they are put in curly brackets. Assignments are
  581. typeset by the assignment operator \gets, thus indicating the
  582. direction of assignment. Semicolons are used (as in PASCAL and REDUCE) as
  583. separators. In order to improve readability, mathematical expressions
  584. are given in mathematical form instead of real code. Finally,
  585. the operator {\tt ::=} is used to identify a pseudo-code-operation
  586. with its real code. We do not provide proper data type declarations
  587. for variables since this seems to be superfluous in LISP where you
  588. only deal with atoms and lists.
  589. % ----------------------------------------------------------------------
  590. \DOC
  591. \&function& \\makefunc/(\\functor/,\\argument-list/,\\precedence/);
  592. \&begin&
  593. @ \\term/\gets\&nil&;
  594. @ \\pattern/\gets\!pattern of this functor or default pattern!;
  595. @ \&while& \\pattern/ \&do& \[as long as pattern isn't empty]
  596. @ \&begin&
  597. @ @ \\tag/\gets\&car& \\pattern/;
  598. @ @ \\pattern/\gets\&cdr& \\pattern/;
  599. @ @ \&if& \!\\tag/ is an atom! \&then& \\aux/\gets\&nil&
  600. @ @ \&else if& \!tag is (F)! \&then& \\aux/\gets\!get the \TeX-item for%
  601. \\functor/!
  602. @ @ \&else if& \!\\argument-list/ is empty! \&then& \\aux/\gets\&nil&
  603. @ @ \&else if& \!tag is (X)! \&then&
  604. @ @ \&begin&
  605. @ @ @ \\aux/\gets\\mktag/(\&car& \\argument-list/,\\precedence/,\&nil&);
  606. @ @ @ \\argument-list/\gets\&cdr& \\argument-list/
  607. @ @ \&end&
  608. @ @ \&else if& \!tag is (Y)! \&then&
  609. @ @ \&begin&
  610. @ @ @ \\aux/\gets\\mktag/(\&car& \\argument-list/,\\precedence/,\&T&);
  611. @ @ @ \\argument-list/\gets\&cdr& \\argument-list/
  612. @ @ \&end&
  613. @ @ \&else if& \!tag is (R)! \&then& \[tail recursive pattern]
  614. @ @ @ \&if cdr& \\argument-list/ \[more than one argument remaining?]
  615. @ @ @ \&then begin&
  616. @ @ @ @ \\pattern/\gets\!pattern for \\functor/!;
  617. @ @ @ @ \\argument-list/\gets\&nil&
  618. @ @ @ \&end&
  619. @ @ @ \&else begin&
  620. @ @ @ @ \\aux/\gets\\mktag/(\&car& \\argument-list/,\\precedence/,%
  621. \&nil&);
  622. @ @ @ @ \\argument-list/\gets\&cdr& \\argument-list/
  623. @ @ @ \&end&
  624. @ @ \&else if& \!tag is (L \\hs/), (M \\vs hs/) or (APPLY xxx)! \&then&
  625. @ @ \&begin&
  626. @ @ @ \\aux/\gets\!result from call to a special routine!;
  627. @ @ @ \\argument-list/\gets\&nil&
  628. @ @ \&end&
  629. @ @ \&else& \\aux/\gets\&nil&;
  630. @ @ \&if& \\aux/ \&then& \!concatenate it to the end of term!
  631. @ \&end&;
  632. @ \&return& \\term/
  633. \&end&;
  634. \endDOC The function {\smalltt makefunc}: As well as the function
  635. {\smalltt mktag} this function performs the prefix-to-\TeX\
  636. notation. Its major task is to ``unify'' operators and their
  637. arguments with predefined patterns in order to build up lists of
  638. \TeX-items.\par
  639. % ----------------------------------------------------------------------
  640. You can bind a \TeX-item to any REDUCE atom (except the
  641. operators) you like. This is supported by binding the \TeX-item
  642. to the specific atom by its property \t{'TEXNAME}.
  643. You can choose to have some default \t{'TEXNAME}
  644. properties for your variables. Function \t{makeset} defines a set of
  645. such default names. At the moment, two sets are provided for greek
  646. and for lowercase letters. Refer to the User's Guide for how you can
  647. use them.\par
  648. But now turn back to the state of modifications our example term
  649. has undergone. With our set of functions we have expanded the prefix form
  650. into a \TeX-item list consisting of single \TeX-items such as
  651. numbers, letters, \TeX-macros, \TeX-primitives and other \TeX\
  652. symbols. The result is shown in figure 5. The \verb|\cdot|
  653. command is the multiplication sign, whereas \verb|^{| indicates
  654. the beginning of a superscript. (The term has been edited by hand
  655. to provide for proper indentation.)\par
  656. % ----------------------------------------------------------------------
  657. \VFig
  658. ( x ^{ 1 2 }
  659. - 1 2 \cdot x ^{ 1 1 } \cdot y
  660. + 6 6 \cdot x ^{ 1 0 } \cdot y ^{ 2 }
  661. - 2 2 0 \cdot x ^{ 9 } \cdot y ^{ 3 }
  662. + 4 9 5 \cdot x ^{ 8 } \cdot y ^{ 4 }
  663. - 7 9 2 \cdot x ^{ 7 } \cdot y ^{ 5 }
  664. + 9 2 4 \cdot x ^{ 6 } \cdot y ^{ 6 }
  665. - 7 9 2 \cdot x ^{ 5 } \cdot y ^{ 7 }
  666. + 4 9 5 \cdot x ^{ 4 } \cdot y ^{ 8 }
  667. - 2 2 0 \cdot x ^{ 3 } \cdot y ^{ 9 }
  668. + 6 6 \cdot x ^{ 2 } \cdot y ^{ 1 0 }
  669. - 1 2 \cdot x \cdot y ^{ 1 1 }
  670. + y ^{ 1 2 } )
  671. \endverbatim
  672. \endVFig A \TeX-item list: A \TeX-item is either a letter, a digit or
  673. another plain character, or it is a \TeX-command. Every \TeX-item
  674. belongs to one out of eight \TeX-item-classes.\par
  675. % ----------------------------------------------------------------------
  676. The last box in this chapter (i.e. figure 6) is a verbatim copy of the
  677. output from TRI for our example.
  678. Because our example will be used to demonstrate
  679. line-breaking, too, some additional commands appear which won't occur
  680. in normal \TeX-mode. These additional commands you find at the beginning
  681. and ending of the output and as \verb|\nl|-commands within the output.
  682. Nevertheless, the structure of the output would be much the same with
  683. our normal \TeX-mode.
  684. % ----------------------------------------------------------------------
  685. \VFig
  686. $$\displaylines{\qdd
  687. x^{12}
  688. -12\cdot x^{11}\cdot y
  689. +66\cdot x^{10}\cdot y^{2}
  690. -220\cdot x^{9}\cdot y^{3}
  691. +495\cdot x^{8}\cdot y^{4}
  692. -792\cdot x^{7}\cdot y^{5}\nl
  693. +924\cdot x^{6}\cdot y^{6}
  694. -792\cdot x^{5}\cdot y^{7}
  695. +495\cdot x^{4}\cdot y^{8}
  696. -220\cdot x^{3}\cdot y^{9}
  697. +66\cdot x^{2}\cdot y^{10}
  698. -12\cdot x\cdot y^{11}
  699. +y^{12}
  700. \Nl}$$
  701. \endverbatim
  702. \endVFig Output produced by the TRI: This \TeX-code has to be postprocessed
  703. by \TeX. This example includes commands for line-breaking as produced
  704. with the second level of TRI.\par
  705. % ----------------------------------------------------------------------
  706. The actual printing of TRI output in this example is easily readable
  707. since the expression is not deeply nested. Complications arise if
  708. expressions to be printed are deeply nested, use many subscripts
  709. and superscripts, have fractions and large operators and the like.
  710. Then output structure is worsened, especially if the whole expression
  711. extends over several lines. We provide a ``cheap'' way of indentation
  712. to retain some of the structure, but our solution is far from perfect.
  713. As the need for post-TRI-editing rises the output from TRI should be
  714. made better. However, our quick-and-dirty solution should suffice.
  715. % ----------------------------------------------------------------------
  716. \sec Breaking REDUCE expressions into lines\par
  717. % ----------------------------------------------------------------------
  718. As mentioned earlier, there are a few properties bound to each
  719. \TeX-item, two of them dealing with line-breaking.
  720. The following list gives you a survey of these two properties and
  721. the values they can take:\par
  722. \smallskip\itemize{17mm}
  723. \litem{\t{'CLASS}}one of the following class specifiers
  724. \itemitem{\t{'ORD\ }}ordinary symbols
  725. \itemitem{\t{'LOP\ }}large operators, such as integrals
  726. \itemitem{\t{'BIN\ }}binary operators
  727. \itemitem{\t{'REL\ }}relational operators
  728. \itemitem{\t{'OPN\ }}opening symbols (left parentheses)
  729. \itemitem{\t{'CLO\ }}closing symbols (right parentheses)
  730. \itemitem{\t{'PCT\ }}punctuation symbols
  731. \itemitem{\t{'INN\ }}inner \TeX\ group delimiters
  732. \litem{\t{'TEXTAG}}this is either an atom describing an \t{'INN} class
  733. or a list of widths defining the width of a \TeX-item, where
  734. succeeding elements of the list will be used depending on the
  735. \TeX\ inner group level (i.e. the nesting of subscripts or superscripts)
  736. \par\enditemize\smallskip\noindent
  737. Glue items are to be inserted between consecutive \TeX-items (similar to
  738. what \TeX\ does with its items). The following table specifies for
  739. each left and right class of a \TeX-item the corresponding glue measure.
  740. The glue item values have following meanings: 0 = no space,
  741. 1 = thin space, 2 = medium space, and 3 = thick space.
  742. An asterisk means that this case never arises, and
  743. values put in brackets indicate no space in the case of sub- or
  744. superscripts.\par
  745. %
  746. \midinsert
  747. \def\tablerule{\noalign{\hrule}}
  748. $$\vbox{\offinterlineskip
  749. \halign{&\vrule#&\quad\hfil\tt#\hfil\quad\cr
  750. \tablerule
  751. &\strut\rm Left&&\multispan{15}\hfil\rm Right Class\hfil&\cr
  752. &&&\multispan{15}\hrulefill&\cr
  753. &\strut\rm Class&&ORD&&LOP&&BIN&&REL&&OPN&&CLO&&PCT&&INN&\cr
  754. \tablerule
  755. &\strut ORD&&0&&1&&(2)&&(3)&&0&&0&&0&&0&\cr
  756. &\strut LOP&&1&&1&&*&&(3)&&0&&0&&0&&(1)&\cr
  757. &\strut BIN&&(2)&&(2)&&*&&*&&(2)&&*&&*&&(2)&\cr
  758. &\strut REL&&(3)&&(3)&&*&&0&&(3)&&0&&0&&(3)&\cr
  759. &\strut OPN&&0&&0&&*&&0&&0&&0&&0&&0&\cr
  760. &\strut CLO&&0&&1&&(2)&&(3)&&0&&0&&0&&0&\cr
  761. &\strut PCT&&(1)&&(1)&&*&&(1)&&(1)&&(1)&&(1)&&(1)&\cr
  762. &\strut INN&&0&&1&&(2)&&(3)&&(1)&&0&&(1)&&0&\cr
  763. \tablerule}}$$
  764. \endinsert
  765. Actually, a glue item is a list consisting of two elements --- a width
  766. info characterizing the width of this item (in scaled points)
  767. and a ``penalty'' to be used if a line should be broken at
  768. this point.
  769. The algorithm for inserting glue items is easily described:
  770. for every consecutive pair of \TeX-items, get their classes and create
  771. a glue item according to the value found in the glue item table.
  772. For some special \TeX-items use special penalties instead of the default
  773. values. That's all.\par
  774. Let us return to our example from the last chapter. When the functions
  775. \t{insertglue} and \t{interglue} have finished, the \TeX-item list
  776. will be left (temporarily) extended with glue items. You can find
  777. them as the two-element lists in the example. All glue items there
  778. have (by chance) the same width 163840. But they have different
  779. penalties 0, 50 and -390. The latter therefore indicates a very good breaking
  780. point because it is a negative penalty, i.e. a bonus.
  781. See the following figure 7 for the changes made to the \TeX-item list.
  782. % ----------------------------------------------------------------------
  783. \VFig
  784. ( x ^{ 1 2 } (163840 0)
  785. - 1 2 \cdot (163840 50) x ^{ 1 1 } \cdot (163840 50) y %
  786. (163840 -390)
  787. + 6 6 \cdot (163840 50) x ^{ 1 0 } \cdot (163840 50) y ^{ 2 } %
  788. (163840 0)
  789. - 2 2 0 \cdot (163840 50) x ^{ 9 } \cdot (163840 50) y ^{ 3 } %
  790. (163840 -390)
  791. + 4 9 5 \cdot (163840 50) x ^{ 8 } \cdot (163840 50) y ^{ 4 } %
  792. (163840 0)
  793. - 7 9 2 \cdot (163840 50) x ^{ 7 } \cdot (163840 50) y ^{ 5 } %
  794. (163840 -390)
  795. + 9 2 4 \cdot (163840 50) x ^{ 6 } \cdot (163840 50) y ^{ 6 } %
  796. (163840 0)
  797. - 7 9 2 \cdot (163840 50) x ^{ 5 } \cdot (163840 50) y ^{ 7 } %
  798. (163840 -390)
  799. + 4 9 5 \cdot (163840 50) x ^{ 4 } \cdot (163840 50) y ^{ 8 } %
  800. (163840 0)
  801. - 2 2 0 \cdot (163840 50) x ^{ 3 } \cdot (163840 50) y ^{ 9 } %
  802. (163840 -390)
  803. + 6 6 \cdot (163840 50) x ^{ 2 } \cdot (163840 50) y ^{ 1 0 } %
  804. (163840 0)
  805. - 1 2 \cdot (163840 50) x \cdot (163840 50) y ^{ 1 1 } %
  806. (163840 -390)
  807. + y ^{ 1 2 } )
  808. \endverbatim
  809. \endVFig A \TeX-item list extended with glue items: \par
  810. %
  811. %
  812. Setting break points requires the creation of a ``breaklist''.
  813. A breaklist is a sequence of passive and active nodes, where each
  814. active node is followed by a passive node and vice versa.
  815. Active nodes represent glue items.
  816. Passive nodes are integer atoms which represent the width of a sequence
  817. of ordinary \TeX-items which must not be interspersed with glue
  818. items. Each breaklist consists of (at least one) passive nodes surrounded
  819. by delta nodes representing the beginning and ending of the list.
  820. \medskip
  821. \settabs\+\indent&passive-node\quad&\cr
  822. \+&\i{breaklist} &::= ( \i{delta-node} \i{inner-list} \i{delta-node} )\cr
  823. \+&\i{inner-list} &::= \i{passive-node} \i{active-node} \dots
  824. \i{passive-node}\cr
  825. \+&\i{active-node} &::= ( \i{width} \i{penalty} \i{offset} )\cr
  826. \+&\i{passive-node} &::= \i{width}\cr
  827. \+&\i{delta-node} &::= \i{active-node} $+$ \i{appendix}\cr
  828. \+&\i{appendix} &::= ( \i{id-number} \i{ptr} \i{demerits}
  829. \i{indentation} )\cr
  830. \medskip
  831. The breaklist will be created using the function \t{breaklist}.
  832. line breaking is performed with this list only; the \TeX-item list
  833. becomes modified only indirectly since the active nodes are shared.
  834. That means that the active nodes aren't copied while creating the breaklist.
  835. Instead, their memory addresses are put into the breaklist as a reference.
  836. This is both memory saving and necessary, since later we deal
  837. with the \TeX-item list itself again in order to insert \verb|\nl|-commands.
  838. So remember there exist two lists sharing all the active nodes
  839. (and hence all the delta nodes). Figure 8 contains
  840. the breaklist from our $(x-y)^{12}$ example. Bear in mind that
  841. passive nodes are sums of widths. The first line and the last line contain
  842. the beginning and ending delta nodes, respectively.
  843. By default, their \i{id-numbers} are 0 and -1, respectively.
  844. %
  845. % ----------------------------------------------------------------------
  846. \VFig
  847. ((0 0 0 0 0 0 0)
  848. 915227 (163840 0 0) 1347128 (163840 50 0) 1097271 (163840 50 0)
  849. 321308 (163840 -390 0) 1347128 (163840 50 0) 1097271 (163840 50 0)
  850. 598015 (163840 0 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  851. 598015 (163840 -390 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  852. 598015 (163840 0 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  853. 598015 (163840 -390 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  854. 598015 (163840 0 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  855. 598015 (163840 -390 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  856. 598015 (163840 0 0) 1674808 (163840 50 0) 820564 (163840 50 0)
  857. 598015 (163840 -390 0) 1347128 (163840 50 0) 820564 (163840 50 0)
  858. 874722 (163840 0 0) 1347128 (163840 50 0) 543857 (163840 50 0)
  859. 874722 (163840 -390 0) 1384446
  860. (0 0 41140184 -1 0 2147483647 0))
  861. \endverbatim
  862. \endVFig A breaklist: Three types of objects are included in a breaklist.
  863. Active nodes are the lists with three elements. Delta nodes contain
  864. exactly seven elements. Passive nodes are integer atoms representing
  865. a width.\par
  866. % ----------------------------------------------------------------------
  867. %
  868. The task of setting the break points (i.e. break items) in the breaklist
  869. is up to the function \t{trybreak}. During this phase, some active nodes
  870. are selected as ``feasible'' break points. Thus, they will be extended and
  871. called ``delta nodes'' furtheron. By default, the first and last node in a
  872. breaklist are delta nodes. When trybreak has finished, the \i{ptr}'s of
  873. the delta nodes point back to the best preceding delta node
  874. in terms of minimal total demerits. So, by stepping through this pointer
  875. list, it is easy to find the best path for breaking the whole breaklist
  876. apart. We use some terminology we'd like to explain:
  877. \itemize{27mm}\medskip
  878. \litem{\i{width}}width of this item (both active and passive nodes)
  879. \litem{\i{penalty}}a numeric value which prohibits line breaking (if
  880. negative, line breaking will be merited)
  881. \litem{\i{offset}}distance to the most recent opening bracket
  882. \litem{\i{id-number}}the identification number of this delta node (1,2,3,...)
  883. \litem{\i{ptr}}pointer to the best delta node to come from with
  884. respect to the minimal demerits path. (Note: a zero
  885. pointer indicates the very beginning of the breaklist)
  886. \litem{\i{demerits}}total demerits accumulated so far
  887. \litem{\i{indentation}}amount of indentation when breaking at this point
  888. \par\enditemize\medskip
  889. The algorithm itself will be described now.
  890. To determine the ``quality'' of a line we introduce a value called
  891. ``badness''. It simply is a heuristic describing how good-looking a
  892. line comes out. This concept is due to Knuth/Plass(1981) and is a major
  893. concept
  894. of \TeX. We use a slightly different heuristic here. We do not measure
  895. badness in terms of ``stretchability'' and ``shrinkability''.
  896. Instead we measure how ``full'' a line is, where ``full''
  897. means that three quarters of the page width are optimal.
  898. Furthermore we add a surplus badness for the indentation: the less
  899. indentation the better.
  900. The badness is a value between 0 and 10000 and is calculated with
  901. the following code (displayed in figure 9).
  902. Surprisingly, we got a higher speed with floating point arithmetic
  903. here than with integer arithmetic.
  904. % ----------------------------------------------------------------------
  905. \DOC
  906. \&function& \\badnessof/(\\length/,\\indentation/);
  907. \&begin&
  908. @ \\temp/\gets\&abs&(\\length/$-{3\over4}*$\\pagewidth/)/(${1\over6}*$%
  909. \\pagewidth/);
  910. @ \&return min&($10000,100*temp^3+2500*$\\indentation/$/$\\pagewidth/)
  911. \&end&;
  912. \endDOC The badness function: ``Badness'' is just a heuristic to compute
  913. a numerical value describing how ``good-looking'' a line comes out.
  914. A correction term is applied to provide for indentation.\par
  915. % ----------------------------------------------------------------------
  916. Figure 10 summarizes the line breaking algorithm. The code
  917. is part of the function \t{trybreak} and describes the ``heart'' of
  918. our algorithm.
  919. Basically, it consists of two loops: the outer loop steps through
  920. the breaklist considering each delta node as a potential start of a
  921. new line while the inner loop looks ahead exactly one line (bounded
  922. by the \i{page-width} or by the rightmost delta-node) checking each
  923. active node if it is a feasible breakpoint, and if so, saving it as the best
  924. path of breaking. Or to put it in another way, simply imagine a
  925. window as wide as a page which moves over the unbroken expression
  926. from the very left to the very right. The left end of the window
  927. is put on every feasible breakpoint determined earlier. The right
  928. end of the window just defines the border of the search for feasible
  929. breakpoints within the window.
  930. % ----------------------------------------------------------------------
  931. \DOC
  932. \\bottom/\gets\\breaklist/;\quad\\pagewidth/\gets\ %
  933. \!user defined page width!;
  934. \!set all variables not mentioned explicitly to zero or nil!;
  935. \&while& \\bottom/ \&do&
  936. \&begin& \[try a new line starting at this delta node]
  937. @ \\base/\gets\&car& \\bottom/; \\top/\gets\&cdr& \\bottom/;
  938. @ \\baseid/\gets\\idof/ \\base/; \\baseptr/\gets\\ptrof/ \\base/;
  939. @ \\basedemerits/\gets\\demeritsof/ \\base/;
  940. @ \\baseoffset/\gets\\offsetof/ \\base/;
  941. @ \\baseindent/\gets\\length/\gets\\indentof/ \\base/;
  942. @ \\total/\gets\\total/+\\widthof/ \\base/;
  943. @ \&while& \\top/ \&and& \\length$<$pagewidth/ \&do&
  944. @ \&begin& \[consider this node for end of the line]
  945. @ @ \\node/\gets\&car& \\top/;
  946. @ @ \\penalty/\gets\\penaltyof/ \\node/;
  947. @ @ \&if& \!node is a passive node!
  948. @ @ \&then& \\len/\gets\\len/+\\node/
  949. @ @ \&else begin& \[node is an active node]
  950. @ @ @ \\badness/\gets\ \!compute current badness from \\length/ and%
  951. \\baseindent/!
  952. @ @ @ \\penalty/\gets\\penaltyof/ \\node/; \\offset/\gets\\offsetof/%
  953. \\node/;
  954. @ @ @ \&if& \\badness $<$ tolerance/
  955. @ @ @ \&or& \\badness $< 1-$penalty/
  956. @ @ @ \&or& \!this is the rightmost delta node!
  957. @ @ @ \&then begin& \[we have a feasible breakpoint]
  958. @ @ @ @ \\demerits/\gets\\basedemerits/+\\badness/$^2+$\\penalty/$*$%
  959. \&abs&(\\penalty/);
  960. @ @ @ @ \&if& \!node is a delta node!
  961. @ @ @ @ \&then begin&
  962. @ @ @ @ @ \&if& \\demerits$<$demeritsof node/ \[better path found?]
  963. @ @ @ @ @ \&then begin&
  964. @ @ @ @ @ @ \!save current \\demerits/ and \\baseid/ to \\node/!;
  965. @ @ @ @ @ @ \!compute amount of indentation!
  966. @ @ @ @ @ \&end&
  967. @ @ @ @ \&end&
  968. @ @ @ @ \&else begin&
  969. @ @ @ @ @ \\feasible/\gets\\feasible/+1;
  970. @ @ @ @ @ \!create new delta node with \\feasible, baseid, demerits/!;
  971. @ @ @ @ @ \!compute amount of indentation!
  972. @ @ @ @ \&end&;
  973. @ @ @ @ \&if& \\penalty/$=-10000$ \&then& \\top/\gets\&nil&%
  974. \[must break here]
  975. @ @ @ \&end;&
  976. @ @ @ \\length/\gets\\length/+\\wdithof node/
  977. @ @ \&end&;
  978. @ @ \&if& \\top/ \&then& \\top/\gets\&cdr& \\top/
  979. @ \&end&;
  980. @ \!save the total length so far to the delta node!;
  981. @ \!step ahead to next delta node and count total length!
  982. \&end&;
  983. \endDOC The code segment from {\smalltt trybreak} dealing with line-breaking:
  984. \par
  985. % ----------------------------------------------------------------------
  986. Earlier we introduced the concept of ``badness'' derived from \TeX.
  987. But actually this is not the only measure answering the question whether
  988. a certain point in the breaklist is feasible or not. There are three
  989. conditions which decide whether a breakpoint is feasible or not.
  990. The first condition requires the badness to be smaller than the value
  991. of \i{tolerance} as specified by the user. This condition can be overridden
  992. if the active node under consideration has a negative penalty whose
  993. (absolute, i.e. positive) amount is greater than the badness.
  994. That means you can buy a breakpoint if you've got enough money
  995. (i.e. a bonus = negative penalty) to pay the price (i.e. the badness).
  996. The third condition just forces the rightmost delta node to be
  997. considered feasible anyway.\note{This is necessary since the end
  998. of the expression is naturally a breakpoint even if it is a bad one,
  999. and the last delta node is needed for accounting purposes as well as
  1000. for storing the pointer to the preceding breakpoints.}
  1001. At this point we introduce a second measure called ``demerits'' which
  1002. is defined as the sum of the demerits so far (i.e. up to the
  1003. beginning of the line currently under consideration), the squared
  1004. badness and the sign-propagated square of the penalty.\note{The
  1005. latter is evaluated as the product of the value (which can
  1006. be positive or negative) and the absolute value (which can be
  1007. positive only).} Now we have a measure which not only refers to
  1008. the current line but to the previous lines, too. Therefore, our
  1009. modified {\caps Knuth}-algorithm ``optimizes'' not only over
  1010. \i{one} line but over \i{all} lines.\par
  1011. Figure 11 should make clear what is happening to the breaklist
  1012. and the \TeX-item list. For readability purposes we display the latter,
  1013. but really it is the breaklist under consideration within \t{trybreak}.
  1014. As in the previous display of our example, you can identify the
  1015. active-nodes. These are the three element number lists. The third
  1016. element which is zero here is used as an offset width to the last
  1017. opening bracket. This information is used for indentation.
  1018. The delta-nodes are remarkable. These are the number lists with seven
  1019. elements. Count them by their fourth element. They run 0, 1, 2
  1020. through 8, 9, -1. The fifth element gives you the way back through the
  1021. list. Start at the last delta-node. There the best way to come from
  1022. is 1. So go to delta-node 1 where you find 0 as the best way to come
  1023. from. Delta-node 0 is the beginning, so you're finished. The sixth element
  1024. stands for the total demerits so far. The seventh element stands for
  1025. the amount of indentation. Here it is a zero because the term isn't
  1026. nested in our example.
  1027. % ----------------------------------------------------------------------
  1028. \VFig
  1029. ( ( 0 0 0 0 0 0 0)
  1030. x ^{ 1 2 } (163840 0 0)
  1031. - 1 2 \cdot (163840 50 0) x ^{ 1 1 }
  1032. \cdot (163840 50 0) y (163840 -390 0)
  1033. + 6 6 \cdot (163840 50 0) x ^{ 1 0 }
  1034. \cdot (163840 50 0) y ^{ 2 } (163840 0 0)
  1035. - 2 2 0 \cdot (163840 50 0) x ^{ 9 }
  1036. \cdot (163840 50 0) y ^{ 3 } (163840 -390 0)
  1037. + 4 9 5 \cdot (163840 50 0) x ^{ 8 }
  1038. \cdot (163840 50 0) y ^{ 4 } (163840 0 0)
  1039. - 7 9 2 \cdot (163840 50 0) x ^{ 7 }
  1040. \cdot (163840 50 0) y ^{ 5 } (163840 18624949 0 1 0 -151875 0)
  1041. + 9 2 4 \cdot (163840 20463597 0 2 0 2500 0)
  1042. x ^{ 6 }
  1043. \cdot (163840 21448001 0 3 0 2500 0)
  1044. y ^{ 6 } (163840 22209856 0 4 0 1 0)
  1045. - 7 9 2 \cdot (163840 50 0) x ^{ 5 }
  1046. \cdot (163840 50 0) y ^{ 7 } (163840 25794763 0 5 0 -142299 0)
  1047. + 4 9 5 \cdot (163840 50 0) x ^{ 4 }
  1048. \cdot (163840 50 0) y ^{ 8 } (163840 0 0)
  1049. - 2 2 0 \cdot (163840 50 0) x ^{ 3 }
  1050. \cdot (163840 50 0) y ^{ 9 } (163840 32964577 0 6 1 -207875 0)
  1051. + 6 6 \cdot (163840 50 0) x ^{ 2 }
  1052. \cdot (163840 50 0) y ^{ 1 0 } (163840 0 0)
  1053. - 1 2 \cdot (163840 38009479 0 7 1 -149350 0)
  1054. x
  1055. \cdot (163840 38717176 0 8 1 -149374 0)
  1056. y ^{ 1 1 } (163840 39755738 0 9 1 -303975 0)
  1057. + y ^{ 1 2 } ( 0 41140184 ?-1 1 -151866 ?)
  1058. \endverbatim
  1059. \endVFig A \TeX-item list extended with delta-nodes: From this list
  1060. the line-breaking way can be derived. Start with node --1, go to node
  1061. 1 and from there to node 0. That makes one break point at node 1.\par
  1062. We haven't mentioned how we generate indentation yet. Generally speaking,
  1063. indentation is entirely directed by brackets, either round, curly, or
  1064. dummy brackets. But how do we compute the amount of indentation?
  1065. First let's turn to the code segment which deals with this problem
  1066. within the big line-braking algorithm shown before. The contents of
  1067. figure 12 explains what happens to the amount of indentation.
  1068. % ----------------------------------------------------------------------
  1069. \DOC
  1070. \!compute amount of indentation! ::=
  1071. \&begin&
  1072. @ \&if& \\offset/$>$\\total/
  1073. @ \&then& \\indent/\gets\\offset$-$total$+$baseindent/ \ \ %
  1074. \[opening bracket case]
  1075. @ \&else if& \\offset$<$baseoffset/
  1076. @ @ \&then& \\indent/\gets\\findindent/() \ \ \ \ \ \ \ \ %
  1077. \ \ \ \[closing bracket case]
  1078. @ @ \&else& \\indent/\gets\\baseindent/; \ \ \ \ \ \ \ \ \ %
  1079. \ \ \ \ \[no change case]
  1080. @ \!save \\indent/ to delta-node!
  1081. \&end&;
  1082. \endDOC The code segment from {\smalltt trybreak} dealing with indentation:
  1083. \par
  1084. % ----------------------------------------------------------------------
  1085. The logic of this code segment is easily summarized. The \i{offset}
  1086. is a measure of how distant the last opening bracket is from the beginning
  1087. of the whole expression. So in the case where \i{offset} is greater than
  1088. the total width accumulated until the very beginning of the line, the
  1089. indentation is just the difference between \i{total}
  1090. and the sum of \i{offset}
  1091. and the amount of indentation \i{baseindent} for the currently line.
  1092. That'll work if the line currently under consideration contains at least
  1093. one opening bracket which hasn't become closed in the same line.
  1094. This case may be labelled the ``opening bracket case''.
  1095. But what shall we do in the other cases? We have to decide if we've got
  1096. a ``closing bracket case'', i.e. if we have at least one more closing
  1097. bracket than we have opening brackets, or if we've got a ``no change
  1098. case'', i.e. the number of opening brackets in the current line matches
  1099. the number of closing brackets in this line. This decision is made by
  1100. comparing \i{offset}$<$\i{baseoffset}. If the \i{baseoffset}, i.e.
  1101. the offset at the beginning of the line, is greater than \i{offset},
  1102. i.e. the offset at the current point, then we've got the ``closing
  1103. bracket case'', otherwise we've got the ``no change case''.
  1104. In the latter, the amount of indentation for the next line is just
  1105. the amount of indentation for the current line. But the ``closing
  1106. bracket case'' causes us much trouble. So we need an extra function dealing
  1107. with this case, as displayed in figure 13.
  1108. % ----------------------------------------------------------------------
  1109. \DOC
  1110. \&macro function& \\findindent/;
  1111. \[macro functions share all variables of outer code blocks]
  1112. \&begin& \[first check if we can save search time for equal destination]
  1113. @ \&if& \\offset/$=$\\lastoffset/ \&and& \\baseptr/$=$\\lastbaseptr/
  1114. @ \&then return& \\lastindent/
  1115. @ \&else begin& \[search the delta-node-stack for previous indentation]
  1116. @ @ \\stack/\gets\\deltastack/; \\lastoffset/\gets\\offset/;
  1117. @ @ \\p/\gets\\lastbaseptr/\gets\\baseptr/;
  1118. @ @ \&while& \\stack/ \&do& \[as long as we have a delta-node ahead]
  1119. @ @ \&begin&
  1120. @ @ @ \\node/\gets\&car& \\stack/; \[current delta-node]
  1121. @ @ @ \&if& \\p$=$idof node/ \&then begin&
  1122. @ @ @ @ \\p/\gets\\ptrof node/; \\local/\gets\\totalof node/;
  1123. @ @ @ @ \&if& \\local$<$offset/ \&then& \\stack/\gets\&nil&
  1124. @ @ @ \&end&;
  1125. @ @ @ \&if& \\stack/ \&then& \\stack/\gets\&cdr& \\stack/
  1126. @ @ \&end&;
  1127. @ @ \\lastindent/\gets\\offset$-$local$+$indentof node/;
  1128. @ @ \&return& \\lastindent/
  1129. @ \&end&
  1130. \&end&;
  1131. \endDOC The macro function findindent: This macro is used to compute the
  1132. amount of indentation in the ``closing bracket case''. It causes some
  1133. trouble since we have to travel back to previous delta nodes.\par
  1134. % ----------------------------------------------------------------------
  1135. This macro\note{Macros become expanded where they are called and thus
  1136. share all variable names defined in the code block where they are called.
  1137. So, there is no need for argument passing if certain variable names in
  1138. the code block don't differ from call to call.} searches the list
  1139. of delta-nodes previously created until it reaches a delta-node (at
  1140. least the very first delta-node in the breaklist) where the total
  1141. width accumulated so far, i.e. the variable \i{local}, is less than
  1142. \i{offset}, i.e. the offset at the end of the line under consideration,
  1143. and computes the amount of indentation from the difference of
  1144. \i{offset} and \i{local} plus the amount of indentation so far.
  1145. Plainly speaking, we go back the lines until we find a line where
  1146. we find the opening parenthesis matching the closing parenthesis
  1147. in the current line. When we've found it, we compute the amount of
  1148. indentation as described in the ``opening bracket case'', but with
  1149. \i{local} instead of \i{total}.
  1150. % ----------------------------------------------------------------------
  1151. \sec Postprocessing with the \TeX\ module ``tridefs.tex''\par
  1152. % ----------------------------------------------------------------------
  1153. When a \TeX-output-file has been created with the TRI it has to be
  1154. processed by \TeX\ itself. But before you run \TeX\ you should make sure
  1155. the file looks the way you want it. Sometimes you will
  1156. find it necessary to add some \TeX-code of your own or delete some
  1157. other \TeX-code. This job is up to you before you finally run \TeX.\par
  1158. During the \TeX-run the sizes of brackets are determined. This task is
  1159. not done by the TRI. In order to produce proper sized brackets
  1160. we put some \verb|\left(| and \verb|\right)| \TeX-commands
  1161. where brackets are opened or closed. A new problem arises when
  1162. an expression has been broken up into several lines. Since, for every
  1163. line, the number of \verb|\left(| and \verb|\right)| \TeX-commands must
  1164. match but bracketed expressions may start in one line and end in another,
  1165. we have to insert the required number of ``dummy'' parentheses
  1166. (i.e. \verb|\right.| and \verb|\left.| \TeX-commands)
  1167. at the end of the current line and the beginning of the following line.
  1168. Therefore, we have to keep track of the depth of bracketing.
  1169. See the following figure 14 for the \TeX-code actually applied.\par
  1170. There is a caveat against this method. Since opening and closing brackets
  1171. needn't lie in the same line, it is possible that the height of the
  1172. brackets can differ although they should correspond in height. That will
  1173. happen if the height of the text in the opening line has a height
  1174. different from the text in the closing line. We haven't found a
  1175. way of tackling this problem yet, but we think it is possible to program
  1176. a little \TeX-macro for this task.
  1177. Furthermore, some macros deal with tricks we had to use in order to
  1178. provide for indentation, fraction handling and the like.
  1179. \VVFig
  1180. \def\qdd{\quad\quad} % simply a double quad
  1181. \def\frac#1#2{{#1\over#2}} % fractions from prefix notation
  1182. \newcount\parenthesis % nesting of brackets
  1183. \parenthesis=0 % intialize
  1184. \newcount\n % a temporary variable
  1185. % ---- round and curly brackets ----
  1186. \def\({\global\advance\parenthesis by1\left(}
  1187. \def\){\global\advance\parenthesis by-1\right)}
  1188. \def\{{\global\advance\parenthesis by1\left\lbrace}
  1189. \def\}{\global\advance\parenthesis by-1\right\rbrace}
  1190. \def\[{\relax} % dummy parenthesis
  1191. \def\]{\relax} % dummy parenthesis
  1192. % ---- provide for looping using tail recursion ----
  1193. % \loop ...what... \repeat
  1194. \def\loop#1\repeat{\global\n=0\global\let\body=#1\iterate}
  1195. \def\iterate{\body\let\next=\iterate\else\let\next=\relax\fi\next}
  1196. % ---- conditions and statements for loop interior
  1197. \def\ldd{\ifnum\n<\parenthesis\global\advance\n by1
  1198. \left.\nulldelimiterspace=0pt\mathsurround=0pt}
  1199. \def\rdd{\ifnum\n<\parenthesis\global\advance\n by1
  1200. \right.\nulldelimiterspace=0pt\mathsurround=0pt}
  1201. % ---- newline statement as issued by TRI ----
  1202. \def\nl{\loop\rdd\repeat\hfill\cr\quad\quad\loop\ldd\repeat{}}
  1203. % ---- indentation statement as issued by TRI ----
  1204. \def\OFF#1{\hskip#1sp\relax}
  1205. % ---- last newline statement before end of math group ----
  1206. \def\Nl{\hfill\cr}
  1207. \endverbatim
  1208. \endVFig The file ``tridefs.tex'': This is the code you have
  1209. to use on the \TeX\ side in order to typeset output produced by our
  1210. TRI.\par
  1211. \noindent There is at least one more line of \TeX-code you have to
  1212. insert by hand into the \TeX-input-file produced by TRI. This line runs
  1213. \verbatim
  1214. \input tridefs
  1215. \endverbatim\noindent
  1216. and inputs the module \t{tridefs.tex} into the file. This is necessary
  1217. because otherwise \TeX\ won't know how to deal with our macro calls.
  1218. If you use the \TeX-input-file as a ``stand-alone'' file, don't
  1219. forget a final \verb|\bye| at the end of the text. If you use
  1220. code produced by TRI as part of a larger text then simply put
  1221. the input-line just once at the beginning of your text.
  1222. % ----------------------------------------------------------------------
  1223. \sec Experiments\par
  1224. % ----------------------------------------------------------------------
  1225. We measured performance using the TIME-facility of REDUCE, which can be
  1226. switched on and off with the two commands
  1227. \example
  1228. ON TIME;
  1229. OFF TIME;
  1230. \endexample
  1231. We have tested our TRI on a \VAX\ operating under VAX/VMS,
  1232. with no other users operating during this phase in order to minimize
  1233. interference with other processes, e.g. caused by paging.
  1234. The TRI code has been compiled with the PSL~3.2a-Compiler.
  1235. The following table presents results obtained with a small number of
  1236. different terms. All data were measured in CPU-seconds
  1237. as displayed by LISP's TIME-facility.
  1238. For expressions where special packages such as \t{solve} and \t{int}
  1239. were involved we have taken only effective output-time, i.e. the time
  1240. consumption caused by producing the output and not by evaluating
  1241. the algebraic result.\note{That means we assigned the result of an
  1242. evaluation to an itermediate variable, and then we printed this
  1243. intermediate variable. Thus we could eliminate the time overhead
  1244. produced by ``pure'' evaluation. Nevertheless, in terms of effective
  1245. interactive answering time, the sum of evaluation and printing time
  1246. might be much more interesting than the ``pure'' printing time.
  1247. In such a context the percentage overhead caused by printing is
  1248. the critical point. But since we talk about printing we decided
  1249. to document the ``pure'' printing time.}\par
  1250. \def\strut{\vrule height8pt depth4pt width0pt}
  1251. \def\tablerule{\noalign{\hrule}}
  1252. \def\hdbox#1{\hbox to 12truemm{\small\hfil#1\hfil}}
  1253. \def\[#1]{$\scriptstyle#1$\hfil}
  1254. $$\vbox{
  1255. \offinterlineskip
  1256. \halign{&\strut\vrule#&\quad\hfil\smalltt#\quad\cr
  1257. \tablerule
  1258. &{\smallbf REDUCE-}\hfil&&\hdbox{\small nor-}&&
  1259. \hdbox{TeX}&&\hdbox{\small TeX-}&&\hdbox{\small TeX-}&\cr
  1260. &{\smallbf Expression}\hfil&&\hdbox{\small mal}&&
  1261. &&\hdbox{\small Break}&&\hdbox{\small Indent}&\cr
  1262. \tablerule
  1263. &\[(x+y)^{12}]&& 0.82&& 0.75&& 3.42&& 3.47&\cr
  1264. &\[(x+y)^{24}]&& 2.00&& 2.22&&12.52&&12.41&\cr
  1265. &\[(x+y)^{36}]&& 4.40&& 4.83&&21.48&&21.44&\cr
  1266. &\[(x+y)^{16}/(v-w)^{16}]&& 2.27&& 2.38&&12.18&&12.19&\cr
  1267. &\[solve((1+\xi)x^2-2\xi x+\xi,x)]&& 0.41&& 0.62&& 0.89&& 0.87&\cr
  1268. &\[solve(x^3+x^2\mu+\nu,x)]&& 4.21&&20.84&&31.82&&40.43&\cr
  1269. \tablerule
  1270. }}$$\vskip5pt
  1271. \noindent This short table should give you an impression of the
  1272. performance of TRI. It goes without saying that on other machines
  1273. results may turn out which are quite different from our results. But our
  1274. intention is to show the relative and not the absolute performance.
  1275. Note that printing times are a function of expression complexity,
  1276. as shown by rows three and six.
  1277. % ----------------------------------------------------------------------
  1278. \sec User's Guide to the REDUCE-\TeX-Interface\par
  1279. % ----------------------------------------------------------------------
  1280. If you intend to use the TRI you are required to load the compiled code.
  1281. This can be performed with the command
  1282. \example
  1283. load!-package 'tri;
  1284. \endexample
  1285. During the load, some default initializations are performed. The
  1286. default page width is set to 15 centimeters, the tolerance for
  1287. page breaking is set to 20 by default. Moreover, TRI is enabled
  1288. to translate greek names, e.g. TAU or PSI, into equivalent \TeX\
  1289. symbols, e.g. $\tau$ or $\psi$, respectively. Letters are printed
  1290. lowercase as defined through assertion of the set LOWERCASE. The whole
  1291. operation produces the following lines of output
  1292. \example
  1293. *** Function TEXVARPRI redefined
  1294. \% set GREEK asserted
  1295. \% set LOWERCASE asserted
  1296. \% \B hsize=150mm
  1297. \% \B tolerance 20
  1298. \endexample
  1299. Now you can switch on and off the three TRI modes as you like.
  1300. You can use the switches alternatively and incrementally.
  1301. That means you have to switch on TeX for receiving standard
  1302. \TeX-output, or TeXBreak to receive broken \TeX-output, or
  1303. TeXIndent to receive broken \TeX-output plus indentation.
  1304. Thus, the three levels of TRI are enabled or disabled according to:
  1305. \example
  1306. On TeX; \% switch TeX is on
  1307. On TeXBreak; \% switches TeX and TeXBreak are on
  1308. On TeXIndent; \% switches TeX, TeXBreak and TeXIndent are on
  1309. Off TeXIndent; \% switch TeXIndent is off
  1310. Off TeXBreak; \% switches TeXBreak and TeXIndent are off
  1311. Off TeX; \% all three switches are off
  1312. \endexample
  1313. More specifically, if you switch off {\tt TeXBreak} you implicitly quit
  1314. {\tt TeXIndent}, too, or, if you switch off {\tt TeX} you implicitly quit
  1315. {\tt TeXBreak} and, consequently, {\tt TeXIndent}.\par
  1316. The most crucial point in defining how TRI breaks multiple lines
  1317. of \TeX-code is your choice of the page width and the tolerance.
  1318. As mentioned earlier, ``tolerance'' is related to \TeX's famous
  1319. line-breaking algorithm. The value of ``tolerance'' determines which
  1320. potential breakpoints are considered feasible and which not. The
  1321. higher the tolerance, the more breakpoints become feasible as determined
  1322. by the value of ``badness'' associated with each breakpoint. Breakpoints
  1323. are considered feasible if the badness is less than the tolerance.
  1324. You can easily set values for page width and tolerance using
  1325. \example
  1326. TeXsetbreak(\i{page-width},\i{tolerance});
  1327. \endexample
  1328. where \i{page-width} is measured in millimeters\note{You can
  1329. also specify page width in scaled points (sp).
  1330. Note: 1~pt = 65536~sp = 1/72.27~inch. The function automatically chooses
  1331. the appropiate dimension according to the size: all values greater than
  1332. 400 are considered to be scaled points.} and the \i{tolerance} is
  1333. a positive integer in the closed interval $[0\ldots10000]$.
  1334. You should choose a page width according to your purposes,
  1335. but allow a few centimeters for errors in TRI's metric.
  1336. For example, specify 140 millimeters for an effective 150 or 160
  1337. millimeter wide page. That way you have a certain safety-margin to
  1338. the borders of the page. Now let's turn to the tolerance.
  1339. A tolerance of 0 means that actually no breakpoint will be considered
  1340. feasible (except those carrying a negative penalty), while a value
  1341. of 10000 allows any breakpoint to be considered feasible.
  1342. Obviously, the choice of a tolerance has a great impact on the time
  1343. consumption of our line-breaking algorithm since time consumption
  1344. increases in proportion to the number of feasible breakpoints.
  1345. So, the question is what values to choose. For line-breaking without
  1346. indentation, suitable values for the tolerance lie between 10 and 100.
  1347. As a rule of thumb, you should use higher values the deeper the term
  1348. is nested --- if you can estimate. If you use indentation, you have to
  1349. use much higher tolerance values. This is necessary because badness
  1350. is worsened by indentation. So, TRI has to try harder to find
  1351. suitable places where to break. Reasonable values for tolerance
  1352. here lie between 700 and 1500. A value of 1000 should be your first
  1353. guess. That'll work for most expressions in a reasonable amount of
  1354. time.\par
  1355. Sometimes you want to add your own REDUCE-symbol-to-\TeX-item
  1356. translations. For such a task, TRI provides a function named
  1357. \t{TeXlet} which binds any REDUCE-symbol to one of the predefined
  1358. \TeX-items. A call to this function has the following syntax:
  1359. \example
  1360. TeXlet(\i{REDUCE-symbol},\i{\TeX-item})
  1361. \endexample
  1362. Three examples show how to do it right:
  1363. \example
  1364. TeXlet('velocity,'!v);
  1365. TeXlet('gamma,\verb|'!\!G!a!m!m!a! |);
  1366. TeXlet('acceleration,\verb|'!\!v!a!r!t!h!e!t!a! |);
  1367. \endexample
  1368. Besides this method of single assertions you can choose to assert
  1369. one of (currently) two standard sets providing substitutions
  1370. for lowercase and greek letters. These sets are loaded by default.
  1371. You can switch these sets on or off using the functions
  1372. \example
  1373. TeXassertset \i{setname};
  1374. TeXretractset \i{setname};
  1375. \endexample
  1376. where the setnames currently defined are \t{'GREEK} and \t{'LOWERCASE}.
  1377. So far you have learned only how to connect REDUCE-atoms with predefined
  1378. \TeX-items but not how to create new \TeX-items itself. We provide a
  1379. way for adding standard \TeX-items of any class \t{'ORD, 'BIN, 'REL,
  1380. 'OPN, 'CLO, 'PCT} and \t{LOP} except for class \t{'INN} which is
  1381. reserved for internal use by TRI only. You can call the function
  1382. \example
  1383. TeXitem(\i{item},\i{class},\i{list-of-widths})
  1384. \endexample
  1385. e.g. together with a binding
  1386. \example
  1387. TeXitem(\verb|'!\!n!a!b!l!a! |,'ORD,'(655360 327680 163840))
  1388. TeXlet('NABLA,\verb|'!\!n!a!b!l!a! |);
  1389. \endexample
  1390. where \i{item} is a legal \TeX-code name\note{Please note that
  1391. any \TeX-name ending with a letter must be followed by a blank
  1392. to prevent from interference with letters of following \TeX-items.
  1393. Note also that you can legalize a name by defining it as a \TeX-macro.},
  1394. \i{class} is one of seven classes (see above) and \i{list-of-width}
  1395. is a non-empty list of elements each one representing the width of
  1396. the item in successive super-/subscript depth levels. That means that the
  1397. first entry is the breadth in display mode, the second stands for
  1398. scriptstyle and the third stands for scriptscriptstyle in \TeX-%
  1399. terminology. But how can you retrieve the width information required?
  1400. For this purpose we provide the following small interactive \TeX\ facility
  1401. called \t{redwidth.tex} documented in figure 15. Simply call
  1402. \example
  1403. tex redwidth
  1404. \endexample
  1405. on your local machine. Then you are prompted for the \TeX-item
  1406. you want the width information for. Type ``end'' when you
  1407. want to finish the session.
  1408. \VVFig
  1409. \newbox\testbox\newcount\xxx\newif\ifOK\def\endloop{end }
  1410. \def\widthof#1{\message{width is: }\wwidthof{$\displaystyle#1$}
  1411. \wwidthof{$\scriptstyle#1$}\wwidthof{$\scriptscriptstyle#1$}}
  1412. \def\wwidthof#1{\setbox\testbox=\hbox{#1}\xxx=\wd\testbox
  1413. \message{[\the\wd\testbox=\the\xxx sp]}}
  1414. \loop\message{Type in TeX item or say 'end': }\read-1 to\answer
  1415. \ifx\answer\endloop\OKfalse\else\OKtrue\fi
  1416. \ifOK\widthof{\answer}
  1417. \repeat
  1418. \end
  1419. \endverbatim
  1420. \endVFig The file ``redwidth.tex'': This \TeX\ code you can use to
  1421. determine the width of specific \TeX-items.\par
  1422. Finally let us discuss how you can compile the TRI into a binary.
  1423. (We refer to PSL, but other LISP versions work quite similar.)
  1424. First of all start REDUCE. Than type in\par
  1425. \verbatim
  1426. on comp;
  1427. symbolic;
  1428. faslout "tri";
  1429. in "tri.red";
  1430. faslend;
  1431. bye;
  1432. \endverbatim\noindent
  1433. We stress the fact that this procedure is definitely LISP dependent.
  1434. Ask your local REDUCE or LISP wizards how to adapt to it.
  1435. % ----------------------------------------------------------------------
  1436. \sec Examples\par
  1437. % ----------------------------------------------------------------------
  1438. Some examples --- which we think might be representative ---
  1439. shall demonstrate the capabilities of our TRI.
  1440. For each example we state (a) the REDUCE command (i.e.
  1441. the input), (b) the tolerance if it differs from the default, and
  1442. (c) the output as produced in a \TeX\ run.\par
  1443. \newcount\exacount\exacount=0
  1444. \def\strut{\vrule height11pt depth4pt width0pt}
  1445. \def\exa#1 \mod#2 \tol#3 \cod#4 \^^M{\global\advance\exacount by1\par
  1446. {\offinterlineskip
  1447. \vbox{
  1448. \hrule
  1449. \line{\strut\vrule
  1450. \hbox to 8mm{\hfil\caps\the\exacount\hfil}\vrule
  1451. \quad\rm#1\hfill\vrule
  1452. \hbox to 32mm{\hfill{\smallcaps Mode: }{\tt #2}\hfill}\vrule
  1453. \hbox to 32mm{\hfill{\smallcaps Tolerance: }{\tt #3}\hfill}\vrule}
  1454. \hrule
  1455. \line{\strut\vrule\hfill\tt#4\hfill\vrule}
  1456. \hrule}
  1457. }\nobreak}
  1458. \bigskip\input tridefs
  1459. % ------------------------------ Examples ------------------------------
  1460. \exa Standard
  1461. \mod TeXindent
  1462. \tol 250
  1463. \cod (x+y){*}{*}16{/}(v-w){*}{*}16;
  1464. \
  1465. $$\displaylines{\qdd
  1466. \(x^{16}
  1467. +16\cdot x^{15}\cdot y
  1468. +120\cdot x^{14}\cdot y^{2}
  1469. +560\cdot x^{13}\cdot y^{3}\nl
  1470. \OFF{327680}
  1471. +1820\cdot x^{12}\cdot y^{4}
  1472. +4368\cdot x^{11}\cdot y^{5}
  1473. +8008\cdot x^{10}\cdot y^{6}\nl
  1474. \OFF{327680}
  1475. +11440\cdot x^{9}\cdot y^{7}
  1476. +12870\cdot x^{8}\cdot y^{8}
  1477. +11440\cdot x^{7}\cdot y^{9}\nl
  1478. \OFF{327680}
  1479. +8008\cdot x^{6}\cdot y^{10}
  1480. +4368\cdot x^{5}\cdot y^{11}
  1481. +1820\cdot x^{4}\cdot y^{12}\nl
  1482. \OFF{327680}
  1483. +560\cdot x^{3}\cdot y^{13}
  1484. +120\cdot x^{2}\cdot y^{14}
  1485. +16\cdot x\cdot y^{15}
  1486. +y^{16}
  1487. \)
  1488. /\nl
  1489. \(v^{16}
  1490. -16\cdot v^{15}\cdot w
  1491. +120\cdot v^{14}\cdot w^{2}
  1492. -560\cdot v^{13}\cdot w^{3}\nl
  1493. \OFF{327680}
  1494. +1820\cdot v^{12}\cdot w^{4}
  1495. -4368\cdot v^{11}\cdot w^{5}
  1496. +8008\cdot v^{10}\cdot w^{6}
  1497. -11440\cdot v^{9}\cdot w^{7}\nl
  1498. \OFF{327680}
  1499. +12870\cdot v^{8}\cdot w^{8}
  1500. -11440\cdot v^{7}\cdot w^{9}
  1501. +8008\cdot v^{6}\cdot w^{10}
  1502. -4368\cdot v^{5}\cdot w^{11}\nl
  1503. \OFF{327680}
  1504. +1820\cdot v^{4}\cdot w^{12}
  1505. -560\cdot v^{3}\cdot w^{13}
  1506. +120\cdot v^{2}\cdot w^{14}
  1507. -16\cdot v\cdot w^{15}
  1508. +w^{16}
  1509. \)
  1510. \Nl}$$
  1511. \exa Integration
  1512. \mod TeX
  1513. \tol -;
  1514. \cod int(1/(x{*}{*}3+2),x)
  1515. \
  1516. $$
  1517. -
  1518. \(\frac{2^{\frac{1}{
  1519. 3}}\cdot
  1520. \(2\cdot
  1521. \sqrt{3}\cdot
  1522. \arctan
  1523. \(\frac{2^{\frac{1}{
  1524. 3}}
  1525. -2\cdot x}{
  1526. 2^{\frac{1}{
  1527. 3}}\cdot
  1528. \sqrt{3}}
  1529. \)
  1530. +
  1531. \ln
  1532. \(2^{\frac{2}{
  1533. 3}}
  1534. -2^{\frac{1}{
  1535. 3}}\cdot x
  1536. +x^{2}
  1537. \)
  1538. -2\cdot
  1539. \ln
  1540. \(2^{\frac{1}{
  1541. 3}}
  1542. +x
  1543. \)
  1544. \)
  1545. }{
  1546. 12}
  1547. \)
  1548. $$
  1549. \exa Integration
  1550. \mod TeXindent
  1551. \tol 1000
  1552. \cod int(1/(x{*}{*}4+3*x{*}{*}2-1,x);
  1553. \
  1554. $$\displaylines{\qdd
  1555. \(\sqrt{2}\cdot
  1556. \(3\cdot
  1557. \sqrt{
  1558. \sqrt{13}
  1559. -3}\cdot
  1560. \sqrt{13}\cdot
  1561. \ln
  1562. \(-
  1563. \(\sqrt{
  1564. \sqrt{13}
  1565. -3}\cdot
  1566. \sqrt{2}
  1567. \)
  1568. +2\cdot x
  1569. \)
  1570. \nl
  1571. \OFF{2260991}
  1572. -3\cdot
  1573. \sqrt{
  1574. \sqrt{13}
  1575. -3}\cdot
  1576. \sqrt{13}\cdot
  1577. \ln
  1578. \(\sqrt{
  1579. \sqrt{13}
  1580. -3}\cdot
  1581. \sqrt{2}
  1582. +2\cdot x
  1583. \)
  1584. \nl
  1585. \OFF{2260991}
  1586. +13\cdot
  1587. \sqrt{
  1588. \sqrt{13}
  1589. -3}\cdot
  1590. \ln
  1591. \(-
  1592. \(\sqrt{
  1593. \sqrt{13}
  1594. -3}\cdot
  1595. \sqrt{2}
  1596. \)
  1597. +2\cdot x
  1598. \)
  1599. \nl
  1600. \OFF{2260991}
  1601. -13\cdot
  1602. \sqrt{
  1603. \sqrt{13}
  1604. -3}\cdot
  1605. \ln
  1606. \(\sqrt{
  1607. \sqrt{13}
  1608. -3}\cdot
  1609. \sqrt{2}
  1610. +2\cdot x
  1611. \)
  1612. \nl
  1613. \OFF{2260991}
  1614. +6\cdot
  1615. \sqrt{
  1616. \sqrt{13}
  1617. +3}\cdot
  1618. \sqrt{13}\cdot
  1619. \arctan
  1620. \(\frac{2\cdot x}{
  1621. \sqrt{
  1622. \sqrt{13}
  1623. +3}\cdot
  1624. \sqrt{2}}
  1625. \)
  1626. \nl
  1627. \OFF{2260991}
  1628. -26\cdot
  1629. \sqrt{
  1630. \sqrt{13}
  1631. +3}\cdot
  1632. \arctan
  1633. \(\frac{2\cdot x}{
  1634. \sqrt{
  1635. \sqrt{13}
  1636. +3}\cdot
  1637. \sqrt{2}}
  1638. \)
  1639. \)
  1640. \)
  1641. /104
  1642. \Nl}$$
  1643. \exa Solving Equations
  1644. \mod TeXindent
  1645. \tol 1000
  1646. \cod solve(x{*}{*}3+x{*}{*}2*mu+nu=0,x);
  1647. \
  1648. $$\displaylines{\qdd
  1649. \{x=
  1650. \[-
  1651. \(\(\(9\cdot
  1652. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1653. +27\cdot \nu ^{2}}
  1654. -2\cdot
  1655. \sqrt{3}\cdot \mu ^{3}
  1656. -27\cdot
  1657. \sqrt{3}\cdot \nu
  1658. \)
  1659. ^{\frac{2}{
  1660. 3}}\cdot
  1661. \sqrt{3}\cdot i\nl
  1662. \OFF{3675021}
  1663. +
  1664. \(9\cdot
  1665. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1666. +27\cdot \nu ^{2}}
  1667. -2\cdot
  1668. \sqrt{3}\cdot \mu ^{3}
  1669. -27\cdot
  1670. \sqrt{3}\cdot \nu
  1671. \)
  1672. ^{\frac{2}{
  1673. 3}}\nl
  1674. \OFF{3675021}
  1675. +2\cdot
  1676. \(9\cdot
  1677. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1678. +27\cdot \nu ^{2}}
  1679. -2\cdot
  1680. \sqrt{3}\cdot \mu ^{3}
  1681. -27\cdot
  1682. \sqrt{3}\cdot \nu
  1683. \)
  1684. ^{\frac{1}{
  1685. 3}}\cdot \nl
  1686. \OFF{3675021}
  1687. 2^{\frac{1}{
  1688. 3}}\cdot 3^{\frac{1}{
  1689. 6}}\cdot
  1690. \mu
  1691. -2^{\frac{2}{
  1692. 3}}\cdot
  1693. \sqrt{3}\cdot 3^{\frac{1}{
  1694. 3}}\cdot
  1695. i\cdot \mu ^{2}
  1696. +2^{\frac{2}{
  1697. 3}}\cdot 3^{\frac{1}{
  1698. 3}}\cdot
  1699. \mu ^{2}
  1700. \)
  1701. /\nl
  1702. \OFF{3347341}
  1703. \(6\cdot
  1704. \(9\cdot
  1705. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1706. +27\cdot \nu ^{2}}
  1707. -2\cdot
  1708. \sqrt{3}\cdot \mu ^{3}
  1709. -27\cdot
  1710. \sqrt{3}\cdot \nu
  1711. \)
  1712. ^{\frac{1}{
  1713. 3}}\cdot 2^{\frac{1}{
  1714. 3}}\cdot
  1715. 3^{\frac{1}{
  1716. 6}}
  1717. \)
  1718. \)
  1719. \]
  1720. \,\nl
  1721. \OFF{327680}
  1722. x=
  1723. \[\(\(9\cdot
  1724. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1725. +27\cdot \nu ^{2}}
  1726. -2\cdot
  1727. \sqrt{3}\cdot \mu ^{3}
  1728. -27\cdot
  1729. \sqrt{3}\cdot \nu
  1730. \)
  1731. ^{\frac{2}{
  1732. 3}}\cdot
  1733. \sqrt{3}\cdot i\nl
  1734. \OFF{2837617}
  1735. -
  1736. \(9\cdot
  1737. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1738. +27\cdot \nu ^{2}}
  1739. -2\cdot
  1740. \sqrt{3}\cdot \mu ^{3}
  1741. -27\cdot
  1742. \sqrt{3}\cdot \nu
  1743. \)
  1744. ^{\frac{2}{
  1745. 3}}\nl
  1746. \OFF{2837617}
  1747. -2\cdot
  1748. \(9\cdot
  1749. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1750. +27\cdot \nu ^{2}}
  1751. -2\cdot
  1752. \sqrt{3}\cdot \mu ^{3}
  1753. -27\cdot
  1754. \sqrt{3}\cdot \nu
  1755. \)
  1756. ^{\frac{1}{
  1757. 3}}\cdot \nl
  1758. \OFF{2837617}
  1759. 2^{\frac{1}{
  1760. 3}}\cdot 3^{\frac{1}{
  1761. 6}}\cdot \mu
  1762. -2^{\frac{2}{
  1763. 3}}\cdot
  1764. \sqrt{3}\cdot 3^{\frac{1}{
  1765. 3}}\cdot i\cdot
  1766. \mu ^{2}
  1767. -2^{\frac{2}{
  1768. 3}}\cdot 3^{\frac{1}{
  1769. 3}}\cdot
  1770. \mu ^{2}
  1771. \)
  1772. /\nl
  1773. \OFF{2509937}
  1774. \(6\cdot
  1775. \(9\cdot
  1776. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1777. +27\cdot \nu ^{2}}
  1778. -2\cdot
  1779. \sqrt{3}\cdot \mu ^{3}
  1780. -27\cdot
  1781. \sqrt{3}\cdot \nu
  1782. \)
  1783. ^{\frac{1}{
  1784. 3}}\cdot 2^{\frac{1}{
  1785. 3}}\cdot 3^{
  1786. \frac{1}{
  1787. 6}}
  1788. \)
  1789. \]
  1790. \,\nl
  1791. \OFF{327680}
  1792. x=
  1793. \[\(\(9\cdot
  1794. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1795. +27\cdot \nu ^{2}}
  1796. -2\cdot
  1797. \sqrt{3}\cdot \mu ^{3}
  1798. -27\cdot
  1799. \sqrt{3}\cdot \nu
  1800. \)
  1801. ^{\frac{2}{
  1802. 3}}\nl
  1803. \OFF{2837617}
  1804. -
  1805. \(9\cdot
  1806. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1807. +27\cdot \nu ^{2}}
  1808. -2\cdot
  1809. \sqrt{3}\cdot \mu ^{3}
  1810. -27\cdot \nl
  1811. \OFF{3675021}
  1812. \sqrt{3}\cdot \nu
  1813. \)
  1814. ^{\frac{1}{
  1815. 3}}\cdot 2^{\frac{1}{
  1816. 3}}\cdot 3^{
  1817. \frac{1}{
  1818. 6}}\cdot \mu
  1819. +2^{\frac{2}{
  1820. 3}}\cdot 3^{\frac{1}{
  1821. 3}}\cdot
  1822. \mu ^{2}
  1823. \)
  1824. /\nl
  1825. \OFF{2509937}
  1826. \(3\cdot
  1827. \(9\cdot
  1828. \sqrt{4\cdot \mu ^{3}\cdot \nu
  1829. +27\cdot \nu ^{2}}
  1830. -2\cdot
  1831. \sqrt{3}\cdot \mu ^{3}
  1832. -27\cdot
  1833. \sqrt{3}\cdot \nu
  1834. \)
  1835. ^{\frac{1}{
  1836. 3}}\cdot 2^{\frac{1}{
  1837. 3}}\cdot 3^{
  1838. \frac{1}{
  1839. 6}}
  1840. \)
  1841. \]
  1842. \}
  1843. \Nl}$$
  1844. \exa Matrix Printing
  1845. \mod TeX
  1846. \tol --
  1847. \cod mat((1,a-b,1/(c-d)),(a*{*}2-b*{*}2,1,sqrt(c)),((a+b)/(c-d),sqrt(d),1));
  1848. \
  1849. $$
  1850. \pmatrix{1&a
  1851. -b&
  1852. \frac{1}{
  1853. c
  1854. -d}\cr
  1855. a^{2}
  1856. -b^{2}&1&
  1857. \sqrt{c}\cr
  1858. \frac{a
  1859. +b}{
  1860. c
  1861. -d}&
  1862. \sqrt{d}&1\cr
  1863. }
  1864. $$
  1865. % ----------------------------------------------------------------------
  1866. \sec Caveats\par
  1867. % ----------------------------------------------------------------------
  1868. Techniques for printing mathematical expressions are available
  1869. everywhere. This TRI adds only a highly specialized version for
  1870. most REDUCE output. The emphasis is on the word \i{most}.
  1871. One major caveat is that we cannot print SYMBOLIC-mode output
  1872. from REDUCE. This could be done best in a WEB-like programming-plus-%
  1873. documentation style. Nevertheless, as Knuth's WEB is already available
  1874. for PASCAL and C, hopefully someone will write a LISP-WEB or a
  1875. REDUCE-WEB as well.\par
  1876. Whenever you discover a bug in our program please let us
  1877. know. Send us a short report accompanied by an output listing.\note{You
  1878. can reach us with e-mail at the following addresses:
  1879. Werner Antweiler: antweil\@epas.utoronto.ca, Andreas Strotmann:
  1880. strotmann@rrz.uni-koeln.de and Volker Winkelmann:
  1881. winkelmann@rrz.uni-koeln.de.} We'll try to fix the error.
  1882. The whole TRI package consists of following files:\par
  1883. \itemize{3cm}
  1884. \litem{\tt tri.tex}This text as a \TeX-input file.\par
  1885. \litem{\tt tri.red}The REDUCE-LISP source code for the TRI.\par
  1886. \litem{\tt tridefs.tex}The \TeX-input file to be used together with
  1887. output from the TRI.\par
  1888. \litem{\tt redwidth.tex}The \TeX-input file for interactive determination
  1889. of \TeX-item widths.\par
  1890. \litem{\tt tritest.red}Run this REDUCE file to check if
  1891. TRI works correctly.\par
  1892. \litem{\tt tritest.tex}When you have run {\tt tritest.red} just make a
  1893. \TeX\ run with this file to see all the nice things TRI is able
  1894. to produce.\par
  1895. \enditemize
  1896. % ----------------------------------------------------------------------
  1897. \sec References\par
  1898. % ----------------------------------------------------------------------
  1899. \aut Antweiler, W.; Strotmann, A.; Pfenning, Th.; Winkelmann, V.
  1900. \ttl Zwischenbericht "uber den Status der Arbeiten am
  1901. REDUCE-\TeX-Anschlu\3
  1902. \pub Internal Paper, Rechenzentrum der Universit"at zu K"oln
  1903. \ref \\
  1904. \dat November 1986
  1905. \inx 1986
  1906. \
  1907. \aut Fateman, Richard J.
  1908. \ttl \TeX\ Output from MACSYMA-like Systems
  1909. \pub ACM SIGSAM Bulletin, Vol. 21, No. 4, Issue \#82
  1910. \ref pp. 1--5
  1911. \dat November 1987
  1912. \inx 1987
  1913. \
  1914. \aut Knuth, Donald E.; Plass, Michael F.
  1915. \ttl Breaking Paragraphs into Lines
  1916. \pub Software---Practice and Experience, Vol. 11
  1917. \ref pp. 1119--1184
  1918. \dat 1981
  1919. \inx 1981
  1920. \
  1921. \aut Knuth, Donald E.
  1922. \ttl The \TeX book
  1923. \pub Addison-Wesley, Readings/Ma.
  1924. \ref \\
  1925. \dat sixth printing, 1986
  1926. \inx 1986
  1927. \
  1928. \aut Hearn, Anthony C.
  1929. \ttl REDUCE User's Manual, Version 3.3
  1930. \pub The RAND Corporation, Santa Monica, Ca.
  1931. \ref \\
  1932. \dat July 1987
  1933. \inx 1987
  1934. \
  1935. \bye