3

We try to change the way maxima translates multiplication when converting to tex.

By default maxima gives a space: \,

We changed this to our own latex macro that looks like a space, but in that way we conserve the sementical meaning which makes it easier to convert the latex back to maxima.

:lisp (setf (get 'mtimes 'texsym) '("\\invisibletimes "));

However, we have one problem, and that is when we put simplification on. We use this for generating steps in the explanation of a solution. For example:

tex1(block([simp: false], 2*3));

Of course when multiplying numbers we can want an explicit multiplication (\cdot).

So we would like it that if both arguments of the multiplication are numbers, that we then have a \cdot when translating to tex.

Is that possible?

Kasper
  • 12,594
  • 12
  • 41
  • 63

1 Answers1

2

Yes, if there is a function named by the TEX property, that function is called to process an expression. The function named by TEX takes 3 arguments, namely an expression with the same operator to which the TEX property is attached, stuff to the left, and stuff to the right, and the TEX function returns a list of strings which are the bits of TeX which should be output.

You can say :lisp (trace tex-mtimes) to see how that works. You can see the functions attached to MTIMES or other operators by saying :lisp (symbol-plist 'mtimes) or in general :lisp (symbol-plist 'mfoo) for another MFOO operator.

So if you replace TEX-MTIMES (by :lisp (setf (get 'mtimes 'tex) 'my-tex-mtimes)) by some other function, then you can control the output to a greater extent. Here is an outline of a suitable function for your purpose:

(defun my-tex-mtimes (e l r)
   (if $simp
     (tex-nary e l r) ;; punt to default handler
     (tex-mtimes-special-case e l r)))

You can make TEX-MTIMES-SPECIAL-CASE as complicated as you want. I assume that you can carry out the Lisp programming for that. The simplest thing to try, perhaps a point of departure for further efforts, is to just temporarily replace TEXSYM with \cdot. Something like:

(defun tex-mtimes-special-case (e l r)
  (let ((prev-texsym (get 'mtimes 'texsym)))
    (prog2 (setf (get 'mtimes 'texsym) (list "\\cdot "))
      (tex-nary e l r)
      (setf (get 'mtimes 'texsym) prev-texsym))))
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48