A (let that does not work

hello
this code in my-init-texmacs works perfectly
but i would like to use the (point q q) which is for the moment behind a ;
when i put off the ; the code does not work any longer
can any colleague explain me why ?
thanks
Vinz

; cercle trigo
          ;les variables
          (let ((q "0.866"))
(kbd-map (:mode in-text?) ("a z q" (insert '
(small-figure
(with "gr-mode"
    (tuple "edit" "math-at") "gr-frame"
    (tuple "scale" "1cm" (tuple "0.5gw" "0.5gh"))
    "gr-geometry" (tuple "geometry" "3.5cm" "3.2cm") "gr-line-width" "0.5ln"
(graphics ""
          ;le cercle
    (carc (point "0" "1") (point "0" "-1") (point "-1" "0"))
          ;les segments du repere
    (line (point "0" "1") (point "0" "-1"))
    (line (point "-1" "0") (point "1" "0"))
          ;les segments pointilles
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "0.5" "0.866") (point "0.5" "-0.866")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.5" "0.866") (point "-0.5" "-0.866")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.866" "0.5") (point "0.866" "0.5")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.866" "-0.5") (point "0.866" "-0.5")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.707" "-0.707") (point "0.707" "0.707")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.707" "0.707") (point "0.707" "-0.707")))
          ;les angles
    (math-at (small (math (frac "<pi>" "3"))) (point "0.5" "1.1"))
    (math-at (small (math (frac "<pi>" "6"))) (point "0.9" "0.5"))
          ;les petits points
          (point "0.866" "0.5")
         ; (point q q)
          (point "-0.866" "0.5")
          (point "-0.866" "-0.5")
          (point "0.866" "-0.5")
          (point "0.5" "0.866")
          (point "-0.5" "0.866")
          (point "-0.5" "-0.866")
          (point "0.5" "-0.866")
          (with "color" "blue" (point "-1" "0"))
          (with "color" "blue" (point "1" "0"))
          (with "color" "blue" (point "0" "1"))
          (with "color" "blue" (point "0" "-1")) 
    );graphics


);(with "gr-mode"
(concat(math (concat "cercle trigo" )))
);(small-figure

)))
            );let

That is a very nice image :slight_smile:
trig-circle
By the way @mgubi @vdhoeven @darcy @jeroen this work is in my opinion a very good contribution to TeXmacs because it shows TeXmacs in action; and I think it should be e.g. highlighted in the blog (if @vincent-douce agrees, and maybe when his whole document is ready).

Said this.

Your let does not work because the structure that you built is a quoted expression, which remains equal to itself after evaluation. So TeXmacs never sees the value of q, sees the symbol q and does not know what to do with it.

You have to let Scheme know that you want to evaluate q. You do it in the following way:

  • you substitute the quote with a quasiquote; in this way you let Scheme know that inside the quasiquoted expression there might be parts which Scheme has to evaluate. The quasiquote symbol is the backtick
quasiquote `
  • you prepend an unquote operator to the expressions that you want Scheme to evaluate; the unquote symbol is the comma
unquote ,

Below I am posting your code with these changes. I have a few observations on your Scheme code, but I’ll do them in separate postings.

; cercle trigo
          ;les variables
          (let ((q "0.866"))
(kbd-map (:mode in-text?) ("a z q" (insert `
(small-figure
(with "gr-mode"
    (tuple "edit" "math-at") "gr-frame"
    (tuple "scale" "1cm" (tuple "0.5gw" "0.5gh"))
    "gr-geometry" (tuple "geometry" "3.5cm" "3.2cm") "gr-line-width" "0.5ln"
(graphics ""
          ;le cercle
    (carc (point "0" "1") (point "0" "-1") (point "-1" "0"))
          ;les segments du repere
    (line (point "0" "1") (point "0" "-1"))
    (line (point "-1" "0") (point "1" "0"))
          ;les segments pointilles
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "0.5" "0.866") (point "0.5" "-0.866")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.5" "0.866") (point "-0.5" "-0.866")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.866" "0.5") (point "0.866" "0.5")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.866" "-0.5") (point "0.866" "-0.5")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.707" "-0.707") (point "0.707" "0.707")))
    (with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.707" "0.707") (point "0.707" "-0.707")))
          ;les angles
    (math-at (small (math (frac "<pi>" "3"))) (point "0.5" "1.1"))
    (math-at (small (math (frac "<pi>" "6"))) (point "0.9" "0.5"))
          ;les petits points
          (point "0.866" "0.5")
          (point ,q ,q)
          (point "-0.866" "0.5")
          (point "-0.866" "-0.5")
          (point "0.866" "-0.5")
          (point "0.5" "0.866")
          (point "-0.5" "0.866")
          (point "-0.5" "-0.866")
          (point "0.5" "-0.866")
          (with "color" "blue" (point "-1" "0"))
          (with "color" "blue" (point "1" "0"))
          (with "color" "blue" (point "0" "1"))
          (with "color" "blue" (point "0" "-1")) 
    );graphics


);(with "gr-mode"
(concat(math (concat "cercle trigo" )))
);(small-figure

)))
            );let
1 Like

hello
thanks for your answer
here a little draft of a possible video for presenting shortcuts that can done with TeXmacs
[https://youtu.be/4K2mR5Ko-WY?si=Q6zYKK5QooCa_OSm)
thanks for your explanation, but

(point ,q ,q)

does not work !

and you said you had remarks on my code i am interested

You need the backquote too in place of the quote: the backquote has to substitute the quote before (small-figure—I replaced it in this way in the code that I posted. Pls. let me know if with this change it works.

For the remarks, pls give me some time.

ok it works
maybe the problems came from the

`

vs the

character
in fact, if i type ` in my-init-texmacs, this character is automatically replaced by
somethinf i can not copypaste here, a symetric of ’ (see picture)

ajscheme

hence i had confused the ’ and the symetric of ’

i have now other questions… when you have time…

(with "dash-style" "10" "line-width" "0.4ln"
          (line (point "0.5" ,q) (point "0.5" ,qm)))
(with "dash-style" "10" "line-width" "0.4ln"
          (line (point "-0.5" ,q) (point "-0.5" ,qm)))
(with "dash-style" "10" "line-width" "0.4ln"
          (line (point ,qm "0.5") (point ,q "0.5")))

i had tried to automatize these “with” trying not to repeat them all the time but did not manage to do it

also : how can i evaluate my code directly ? for the momemnt, i type/modify in my-init-texmacs and save and quit and relauch texmacs but it takes time…

This is part of my comments on code :slight_smile: Synthesis: wrap all of the lines in a gr-group construct and place the with around the group.

Example:

(define two-blue-lines '(with "color" "blue" (gr-group 
                       (line (point "1" "1") (point "2" "2"))
                       (line (point "1" "2") (point "2" "3")))))

gr-group is a TeXmacs tag. There is a “Scheme” way that is also helpful, that is unquote-splicing, let me write about that in a separate post.

In a Scheme session.

Here is my solution : you can draw this circle with the keyboard shortcut 'circle.
This opens you up to a foldable scheme 'senvironment.
We obtain: (circle)…
The cursor returns to before the second parenthesis, it remains to write the desired q value: “0.8”. Don’t forget the quotation marks.
Then press ENTER and the circle appears. In addition, by pressing CTRL ENTER you can modify the value of q and therefore your drawing.
This is my solution which is certainly not the best but it works on my Ubuntu.

(define (cercle q)
(insert `
(small-figure
(with “gr-mode”
(tuple “edit” “math-at”) “gr-frame”
(tuple “scale” “1cm” (tuple “0.5gw” “0.5gh”))
“gr-geometry” (tuple “geometry” “3.5cm” “3.2cm”) “gr-line-width” “0.5ln”
(graphics “”
;le cercle
(carc (point “0” “1”) (point “0” “-1”) (point “-1” “0”))
;les segments du repere
(line (point “0” “1”) (point “0” “-1”))
(line (point “-1” “0”) (point “1” “0”))
;les segments pointilles
(with “dash-style” “10” “line-width” “0.4ln”
(line (point “0.5” “0.866”) (point “0.5” “-0.866”)))
(with “dash-style” “10” “line-width” “0.4ln”
(line (point “-0.5” “0.866”) (point “-0.5” “-0.866”)))
(with “dash-style” “10” “line-width” “0.4ln”
(line (point “-0.866” “0.5”) (point “0.866” “0.5”)))
(with “dash-style” “10” “line-width” “0.4ln”
(line (point “-0.866” “-0.5”) (point “0.866” “-0.5”)))
(with “dash-style” “10” “line-width” “0.4ln”
(line (point “-0.707” “-0.707”) (point “0.707” “0.707”)))
(with “dash-style” “10” “line-width” “0.4ln”
(line (point “-0.707” “0.707”) (point “0.707” “-0.707”)))
;les angles
(math-at (small (math (frac “” “3”))) (point “0.5” “1.1”))
(math-at (small (math (frac “” “6”))) (point “0.9” “0.5”))
;les petits points
(point “0.866” “0.5”)
(point ,q ,q)
(point “-0.866” “0.5”)
(point “-0.866” “-0.5”)
(point “0.866” “-0.5”)
(point “0.5” “0.866”)
(point “-0.5” “0.866”)
(point “-0.5” “-0.866”)
(point “0.5” “-0.866”)
(with “color” “blue” (point “-1” “0”))
(with “color” “blue” (point “1” “0”))
(with “color” “blue” (point “0” “1”))
(with “color” “blue” (point “0” “-1”))
);
;graphics
);(with “gr-mode”
(concat(math (concat “cercle trigo” )))
);(small-figure
))

(delayed (lazy-keyboard-force)(kbd-map ("’ c e r c l e" (begin (insert '(with “info-flag” “detailed” (flag “cercle” “red”)))(make-script-input* “scheme” “default”) (insert " (cercle )")(go-to-previous)))))

image image

2 Likes