Here is a short discussion of Scheme graphics with external files. It is also incomplete. I’ll explain at the end.
- Make a Scheme file with graphics functions. The file content may be this (as an example)
(texmacs-module (graphics-functions))
(tm-define pi (acos -1))
(tm-define (pt x y)
`(point ,(number->string x) ,(number->string y)))
- Put it in the
progs directory of your personal initialization directory, call it graphics-functions.scm
- In a Scheme executable switch, write
(begin
(use-modules (graphics-functions))
(define pA (pt -2 0))
(define pB (pt 2 0))
(define xC (- (* 2 (cos (/ pi 3))))); x-coordinate for point C
(define yC (* 2 (sin (/ pi 3)))); y-coordinate for point C
(define pC (pt xC yC))
(stree->tree
`(with "gr-geometry"
(tuple "geometry" "400px" "300px" "center")
(graphics
(with "color" "red" (cline ,pA ,pB ,pC))))))
and you will be using the pi and pt functions you defined in the module.
In the code:
-
(use-modules (graphics-functions)) tells Guile that it has to load the module, which is located in its search path
- The
tm-defines inside the module will make the corresponding definitions globally available
It is also possible to link to the module in the preamble, with
<use-module|(graphics-functions)>
and you will not need the (use-modules (graphics-functions)) form in the executable switch.
I hope this helps.
I did not finish the post on graphics with external code because (the explanations tell you also where the present post is incomplete in my opinion)
- I wanted to be exhaustive in explaining where files can be put, and I got into a tangle
- With external files, you might not know what functions you are executing. Scheme with full access to your computer’s resources can wipe them out ;-). I did not yet write about security in a way that satisfies me.
I think it is still possible for me to finish it but it might require a bit of sustained work. It would be also good to make it plain why one would like to use the function denestify-conditional: as I myself, that wrote it, do not see now the details of how it helps. I don’t like the name of the function anymore, too 