[main]Notes on TeXmacs
In a previous note, we have shown an example of TeXmacs
native graphics generated with
Now let us see how to embed it seamlessly in a document. Our work is
based on
Since in each
For more complex drawings users may feel the need of more efficient facilities to compose, test and deploy into TeXmacs their code. We are going to discuss some available tools in a future post.
A synthetic discussion of TeXmacs graphics primitives and how to code
them in
In the code we ue in this note, we introduce a function pt that generates point primitives, (which are parametrized by two numbers, expressed as strings), and with it we generate points that we will use to build other primitives (arc, line, cline and text-at).
In turn, TeXmacs will use the primitives to represent the triangle, the half-circle and the decorations, that is the drawing that we will embed in the document.
We open the environment with
Press Shift+Return and type or paste the graphics command; in this note let us copy the same commands that generate the drawing in the previous note, wrapping everything in a begin form as we already said:
(begin
(define pi (acos -1))
;; a function for generating TeXmacs points
(define (pt x y)
‘(point ,(number->string x) ,(number->string y)))
;; points for the triangle
(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))
;; points for the letters
(define tA (pt -2.3 -0.5))
(define tB (pt 2.1 -0.5))
(define tC (pt (- xC 0.2) (+ yC 0.2)))
(stree->tree
‘(with "gr-geometry" (tuple "geometry" "400px" "300px" "center")
(graphics
;; the arc and the line together make the semicircle
(with "color" "black" (arc ,pA ,pC ,pB))
(with "color" "black" (line ,pA ,pB))
;; a closed polyline for the triangle
(with "color" "red" (cline ,pA ,pB ,pC))
;; add letters using text-at
(with "color" "black" (text-at "A" ,tA))
(with "color" "black" (text-at "B" ,tB))
(with "color" "black" (text-at "C" ,tC))
;; finally decorate with the TeXmacs symbol
;; and close all of the parentheses!!!
(with "color" "blue" (text-at (TeXmacs) ,(pt -0.55 -0.75)))))))
The last step is pressing Shift+Return to execute
the code and generate the drawing. We do it in a big-figure
environment (
|
The drawing we generated is editable in two different ways.
Placing the cursor at the drawing (just after or just before, the drawing is then surrounded by a thin cyan frame) and pressing Return brings back the yellow edit window, where the code can be changed and re-executed into a new drawing.
(begin
(define pi (acos -1))
;; a function for generating TeXmacs points
(define (pt x y)
‘(point ,(number->string x) ,(number->string y)))
;; points for the triangle
(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))
;; points for the letters
(define tA (pt -2.3 -0.5))
(define tB (pt 2.1 -0.5))
(define tC (pt (- xC 0.2) (+ yC 0.2)))
(stree->tree
‘(with "gr-geometry" (tuple "geometry" "400px" "300px" "center")
(graphics
;; the arc and the line together make the semicircle
(with "color" "black" (arc ,pA ,pC ,pB))
(with "color" "black" (line ,pA ,pB))
;; a closed polyline for the triangle
(with "color" "red" (cline ,pA ,pB ,pC))
;; add letters using text-at
(with "color" "black" (text-at "A" ,tA))
(with "color" "black" (text-at "B" ,tB))
(with "color" "black" (text-at "C" ,tC))
;; finally decorate with the TeXmacs symbol
;; and close all of the parentheses!!!
(with "color" "blue" (text-at (TeXmacs) ,(pt -0.55 -0.75)))))))
It is also possible to edit the drawing with the interactive (point and
click) facilities. In this case too it is always possible to return to
the text-editing mode of the