[racket] Modifying how "interaction" renders results

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat May 26 16:27:48 EDT 2012

While documenting a matrix library, I have used the nice feature
that picts returned by the evaluation are inserted into the resulting

@interaction[#:eval matrix-eval
                     (let ([print (current-print)])
                       (λ (v) (print (if (matrix? v) (matrix->pict v) v)))))
                    (matrix 2 2  1 2 3 4)]

The 2x2 matrix is converted to a pict by matrix->pict and thus
I get a nice matrix image in the documentation.

Now I am experimenting with MathJax.
Using Prabhakar Ragde code from RacketCon I can write

    @$[(tex-matrix (matrix 2 3 1 2 3 4 5 6))]

and get a nice inline matrix displayed.

Then I thought, I could use the trick as before to get nice matrices
in the output:

@interaction[#:eval matrix-eval
                     (let ([print (current-print)])
                       (λ (v) (print (if (matrix? v) (tex-matrix (matrix v))))))
                    (matrix 2 2  1 2 3 4)]

But tex-matrix returns an element (in the Scribble sense) and
instead of embedding the returned element into the page it
simple writes #<element>.

Is there a way to bypass/modify how  interaction  renders the results?

Jens Axel Søgaard

Posted on the users mailing list.