texput and extension of the tex function



Zach,

The function to process an expression with a specified operator
(e.g. integrate, diff, exponent, etc) takes 3 arguments, the expression
to be processed and the stuff to the left and right, and it returns a list
of strings (which are smashed together when the output is printed).

I've written a few lines of code to make it possible to call a Maxima
function to accept those arguments and return the list of strings.
The code is just kind of a sketch at this point.

Here's an example. Let's say for foo(a, b) we want the output
\frac{1 + a}{1 + b}. See the PS of this message for tex_function and tex1.

footex (x, l, r) := append (l, ["\\frac{1 + "], tex1 (first (x)), ["}{1 + "],
  tex1 (second (x)), ["}"], r);
tex_function (foo, footex);

tex (foo (g, h));
 => $$\frac{1 + g}{1 + h}$$

tex (1 + u + foo (g, h));
 => $$u+\frac{1 + g}{1 + h}+1$$

tex (foo (%pi^2, %gamma/2));
 => $$\frac{1 + \pi^2}{1 + {{\gamma}\over{2}}}$$

Does that seem useful?

best

Robert Dodier

PS.
;; copyright 2008 by Robert Dodier
;; I release this work under terms of the GNU General Public License

(defun $tex1 (x) (cons '(mlist) (tex x nil nil 'mparen 'mparen)))

(defun $tex_function (op f)
  (let
    ((glue-f (gensym))
     (f-body `(rest (mfuncall ',f x (cons '(mlist) l) (cons '(mlist) r)))))
    (setf (symbol-function glue-f) (coerce `(lambda (x l r) ,f-body) 'function))
    (setf (get op 'tex) glue-f)))