Inserting picture

hello
i have juste now 20 students, their job is to present in TeXmacs the numerics results and the plots obtained in R

but : there is a unconfortable behaviour of TeXmacs
by default the pictures are pasted with lenght 1par

it creates probleme of new lines or it is difficult to put the cursor at the right of the picture to change it size after

it would be very, very, very convenient to at least set the length by default to something like 7cm instead of 1par
is there a means to do this ? is it programmed in the evolution of texmacs ?

I looked in the code and I did not find where the size of dragged-and-dropped images is defined (and I realize now that pasted might not mean dragged and dropped.

These threads, though, can help with setting the size of images inserted from files, maybe that is helpful:

Pls. let me know. In case, I could look again, this time for pasted images

hello thanks
i have tried this in my-init-texmacs but is does not work :
(define (centered-paste-image size)
(insert-go-to '(center “”) '(0 0))
(kbd-paste)
(tree-set! (tree-search-outer-first (cursor-tree) 'image)
1
(string->tree size)))
(kbd-map (“A-P” (centered-paste-image “0.8par”)))

i can’t manage to understand what’s wrong

I did not try to debug the function you posted—I think tree-search-outer-first needs to be defined; I found a different one in Set Pasted Image to 0.8par and centered (posters in that thread reported that the function you tried wasn’t working):

(define (centered-paste-image size)
  (insert-go-to '(center "") '(0 0))
  (kbd-paste)
  (let ((img (tree-search-upwards (cursor-tree) 'image)))
    (tree-set! img 2 "")
    (tree-set! img 1 size)))

which you may bind to a key combination like you did in your message. Pls. let me know if this works.

ok thank
juste one question
where in the code is the size 0.8 par written ?

i have tried this :

;images plus petites
(define (centered-paste-image size)
(insert-go-to '(center "") '(0 0))
(kbd-paste)
 (let ((img (tree-search-upwards (cursor-tree) 'image)))
(tree-set! img 2 "")
(tree-set! img 1 size)))
(kbd-map (:mode in-text?) ("a z m" (centered-paste-image size)
                           ))                                  
;-------------

but it has not effect, when i press :
a z m
nothing happens

centered-paste-image is a function that takes one argument, the horizontal size of the image. So when you assign the application of the function to a keyboard shortcut, you have to apply it to an argument, e.g.

(kbd-map (:mode in-text?) ("a z m" (centered-paste-image "0.8par")))

like you did in the first code you posted.

ok this is very, very fine
sorry i should have understood that the function needs an argument
it seems with your help have soon solved a problem i had since a long time

current working code:

(define (paste-image size)
(insert-go-to '(center "") '(0 0))
(kbd-paste)
(let ((img (tree-search-upwards (cursor-tree) 'image)))
(tree-set! img 2 "")
(tree-set! img 1 size)))
(kbd-map (:mode in-text?) ("a z m" (paste-image "5cm")
                               ))

now i still have 3 questions

the fisrt one is : i dont want the pictures to be centered, juste pasted where the cursor is ; i have tried to erase the '(center “”) instruction but it does not work any longer
how could i do ?

the second one is : i would like the pasted picture to be insertd in a :

(small-figure

how could i do ?

I did not try this; I think it does not work because if you remove '(center “”) you get the function application (insert-go-to '(0 0)), but insert-go-to expects two arguments.

Try the following. I did it by “copying as Scheme” an empty small figure and realizing that the structure of '(small-figure "" "") is equal to the structure of '(center "") up to its first element (small-figure and center are the tags), so the “go-to” argument of insert-go-to needs to be the same.

(define (paste-image-into-small-figure size)
  (insert-go-to '(small-figure "" "") '(0 0))
(kbd-paste)
(let ((img (tree-search-upwards (cursor-tree) 'image)))
(tree-set! img 2 "")
(tree-set! img 1 size)))

ok fantastique
maitnenant c’est nickel et ça va me faire gagner un temps fou
bon, pour les étudiant,s il faudrait que je fasse installer mon propre my-init-texmacs au collègue en charge du parc informatique ; mais d’un autre côté, l’apprentissage de TeXmacs prend un peu de temps et on arrive sur une autre problématique
mais pour mon usage propre c’est fantastique

maintenant ma troisième question c’était de cmprendre le script
en associant ce que tu as écrit et l’aide de chat-gpt j’en viens à la conclusion suivante :slight_smile:

(define (paste-image size)

crée la fonction paste-image qui prend l’argument size

(insert-go-to '(small-figure "" "") '(0 0))

c’est la première instruction dans la définition de la fonction et ça crée une petite figure tout en y mettant le curseur dedans ; je maîtrise pas le (0 0) maisje comprend l’idée

(kbd-paste)

doit être une instruction propre à TeXmacs, donc programmée par Joris à la base j’imagine, qui permet de coller ici le contenu du presse-papier. Au début de TeXmacs on ne pouvait pas copier coller d’images dans TeXmacs si je me souviens bien, donc cette instruction, dans la façon dont elle est programmée inside, a dû, j’imagine, évoluer avec le temps : où puis-je lire le code (par simple curiosité) qui définit cette fonction ?

(let ((img (tree-search-upwards (cursor-tree) 'image)))

c’est ça que chat-gpt m’a aidé à comprendre
donc ça définit une variable nommée “img”, si j’ai bien compris, qui est en fait la structure autour du curseur ou bine qui est l’image collée elle-même (mais si c’est l’image pourquoi, si j’applique mon raccourci clavier à du texte, ça marche aussi ?)
donc cette variable img part du curseur, “regarde” ce qu’il y a autour c’est-à-dire l’environnement dans lequel l’image est ? si l’on vient de coller l’image, en théorie le curseur est juste à droite de l’image… je ne comprend pas l’instruction :slight_smile:

'image

ensuite :

(tree-set! img 2 "")
(tree-set! img 1 size)))

ça je comprend, ça va dans l’arbre de l’image, que je visualise un peu, ça met du vide en position 2 (la hauteur) et la taille voulue en position 1 (la largeur)

ensuite on associe la fonction au raccourci clavier voulu avec l’argument voulu

si jamais j’ai dit faux ou imprécis, je suis intéressé par toute explication

Vincent

1 Like

Mostly you are on it. Pls. give me a bit of time (early next week) to enter into the let part of the code.

yes thanks very much to you
oups i have written in french sorry

let is a construct which defines a scope, that is a portion of the program where some variables take values that are valid in that portion only.

In (let ((img (tree-search-upwards (cursor-tree) 'image))) one defines img as the value of (tree-search-upwards (cursor-tree) 'image), which I think (I did not check) is the closest tree, searching upwards from the cursor, whose tag is image—since you just copied an image, TeXmacs will have created one (this is again guessing, but the function works, so it may be good guessing) and you will find the one TeXmacs just created. Now that you hold the tree, you have to change its leaves, and you do that with the tree-set! instructions.

The exclamation mark in the name of the function is a hint that the function will change already-existing variables—naming functions in this way is a custom of Scheme; the ones without exclamation mark according to the custom do not change any already-defined variable. One can violate the custom and if they do so may confuse someone else.