7.13.17 The root show operator

Prev Up Next Page 259 of 800 Search internet

The render-txt function of the previous section was custom made for the txt construct. Now consider the more complex problem of defining a new rendering operator which can be re-used in the right hand side of many different rendering definitions.

As a motivating example consider a 'newline pair' construct which renders as a newline and evaluates as a pair:

tex use define x ::: y as x,"
\newline ",y end define

value define x ::: y as x :: y end define

The above looks ok, but if we use indexed variables in the value definition, the rendering looks quite bad:

value define x _ { 1 } ::: x _ { 2 } as x _ { 1 } :: x _ { 2 } end define

An indexed variable has a subscript operator as principal operator. The subscript operator takes two parameters. When used, the second parameter is rendered as a subscript of the first parameter as can be seen in the right hand side of the definition above. When shown, it looks as in the left hand side above.

The problem is that the value definition construct value define x as y end define renders its first argument using show rendering. The rendering definition of the value definition construct reads:

   tex show define value define x as y end define as "
   [ "[ texshow x end texshow ]"
   \mathrel{\dot{=}} "[ y ]"
   ]" end define

The texshow...end texshow rendering operator causes all of x to be show rendered.

If you try to find where the texshow construct is defined, you will search in vain. The texshow construct has the behavior it has because it has arity one and no value definition. The default renderer treats all constructs with arity one and no value as a texshow construct. To find the line of code which implements this, go to the lgc page and locate the definition of lgc-render-eval in the section named 'rendering evaluator'. The penultimate line of the definition switches to show rendering for constructs with arity one.

To get indexed variables look right, we define a new value definition construct:

macro define root value define x as y end define as value define x as y end define end define

tex show define root value define x as y end define as "
[ "[ texrootshow x end show ]"
\mathrel{\dot{\equiv}} "[ y ]"
]" end define

The next section defines texrootshow such that it shows the principal operator of x but renders the rest of x normally. That makes indexed variables look right:

root value define x _ { 1 } ::: x _ { 2 } as x _ { 1 } :: x _ { 2 } end define

Prev Up Next Page 259 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05