Adding TeX macros to the output from Maxima's tex() function.



I am having difficulty fine tuning the tex function to insert a
tex macro of my own into the middle of tex()'d maxima output.

To be specific, I would like to define a Maxima function like

texmacro(str,expr)

which can be applied to two entities, the first is any maxima
expression, expr and the second is a string.   This function is
perhaps returned by the simplifier as

texmacro(str,expr)

However, it does alter the tex() function so that

tex( texmacro(str,expr) )

returns

$$\themacro{str}{ tex(expr) }$$

As a specific example I'd like to do the following, from within Maxima.  
I can't do this by hand to the output since I'm generating expressions on
the fly for web pages and want to highlight incorrect entries in a matrix,
coefficients in a polynomial etc.

For example, a student gets a coefficient incorrect, and I
generate from within Maxima an expression such as

x^2+texmacro("red",1/8)*x+1

to highlight this.  I'd like the function tex()

ie tex( x^2+texmacro("red",1/8)*x+1) to return

$$x^2+\mycolor{red}{{1}\over{8}}\,x+1$$

I've looked for docs on texput, and at the mactex.lisp file, but
cannot seem to solve the problem.  Without the first argument
str, this looks to be very close to the lisp function

(defun tex-sqrt(x l r)
 (tex (cadr x) (append l  '("\\sqrt{")) (append '("}") r) 'mparen 'mparen))

I don't know how to "add a function" texmacro, so that tex()
becomes aware of it.

Can anyone help?

Many thanks indeed

Chris

(Currently my "fix" follows the example of texput and uses the
"<<" and ">>" matchfix operators to hightlight in red.

texput("<<",[" {\\color{red} ", " } ", " " ],matchfix);
matchfix("<<",">>");

So that

tex(x^2+<<1/8>>*x+1);

returns

$$x^2+ {\color{red} {{1}\over{8}} }  \,x+1$$

This isn't as flexible as I'd like though, and I'm soon going to
run out of sensible brackets!)