How define-text-object works
[Next] [Up] [Previous]
Next: Rendering instances of
Up: Macros introduce new
Previous: Macros introduce new
Lisp macro define-text-object is quite involved.
In this overview, we use the call shown
in fig:define-kronecker to illustrate the various steps. A call
to macro define-text-object performs the following steps:
- Define class:
- Generate the class definition for
the new object type. In our example, it produces:
[LVerbatim695]
If the corresponding macro takes [tex2html_wrap5500] arguments, i.e.,
[tex2html_wrap5502] in fig:define-kronecker, then the
new object type is defined to have a slot arguments. This
slot will hold a list containing the result of processing the [tex2html_wrap5504]
arguments of the La)TeX macro call.
- Define processing function:
- Define a processing function that
is called to process instances of the La)TeX macro call. The
function applies the recursive-descent algorithm to the next
number-args tokens from the input stream. In the current
example, the function generated is:
[LVerbatim703]
where variable number-args is bound to the value of
the number-args keyword argument in the lexical scope in
which the function definition is evaluated.
Functions process-argument-as-math and
process-argument-as-text apply the recursive descent parser to their
argument; the former parses mathematical content, the latter
processes plain text.
- Define accessor methods:
- If
[tex2html_wrap5506], accessor method argument is
generated. Method argument takes two arguments, an instance
[tex2html_wrap5508] of the new object and an integer [tex2html_wrap5510], and retrieves the result of
processing argument [tex2html_wrap5512] of the corresponding call to the
La)TeX macro. It is used in the rendering rules to retrieve
different pieces of a La)TeX macro call.
See s:sample-macro-reading for an example of its use.
Assuming that [tex2html_wrap5514], this method looks like:
[LVerbatim716]
We take advantage of the generic dispatch provided by
CLOS and define an instance of the above method with its
arguments reversed -this avoids having to remember the order
of arguments to function argument when writing rendering rules.
- Define precedence:
- If the precedence keyword argument
is supplied, an appropriate call to define-precedence is
generated:
[LVerbatim722]
- Install macro definition:
- Finally, the La)TeX macro
is installed in a global table that records all known
La)TeX macros.
[LVerbatim726]
This specifies that the macro being defined takes [tex2html_wrap5516] arguments
and calls to it should be processed using function
kronecker-expand.
The call to the Lisp macro define-text-object
shown in this example produces [tex2html_wrap5518] lines of Lisp code.
[Next] [Up] [Previous]
Next: Rendering instances of
Up: Macros introduce new
Previous: Macros introduce new
TV Raman
Thu Mar 9 20:10:41 EST 1995