Set Pasted Image to 0.8par and centered

Hi all,

I wish to make all pasted pictures automatically 0.8par in size and center justified. Is there a hint on how to achieve that? A possible similar post: Is it possible to set default size of linked images? , but it did not address the “paste” part.
Any help would be appreciated! :stuck_out_tongue_closed_eyes:

1 Like

If you really want it:

(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)))
(centered-paste-image "0.8par")

Create a interface for this function: kbd shortcut, texmacs macro, menu item, or even directly call it from bottom line minibuffer.

Thanks! I tried this. It is correctly centering the picture, but I don’t think 0.8par is set. May I know where is the problem?
image

Press M-x and type the function call to verify the function has proper definition. Meta should be the key with Windows’ logo on Windows and Linux. On my machine the image does present as width 0.8par though its height is left unchanged, resulting a stretched image. If this is what you mean, cancel the height before resetting width:

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

I get an “unbound variable” error on tree-search-outer-first. Is it a function you have defined yourself?

Sorry, yes. This can be replaced by a bundled function:

(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)))

2 Likes

Nice! Now it works as expected!
Also may I know if there is a way to set pasted image size “as is” i.e. in 100% scale. I find the default pasting function usually magnifies pasted image to some extent … e.g. below small screenshot has been magnified with default paste …

How the pasted images display is determined by your page type and page scale factor, TeXmacs just trade screen 1 pixel with 1pt for relatively small images. Large images are set to be 1par. It’s uneconomical, if not impossible, to implement some intelligent function to guess these numbers.

On the other hand, if you don’t constantly change page type and scale factor, you can conveniently set a “conversion scale” for pasted small images (large images stay well with 1par). Just (tree-ref img 1) to get the string, extract the number utilizing regular expression, and finally set the number. After several try you will find a comfortable conversion scale. If you switch between several machines, (get-screen-size) will give you some ideas.

Happy hacking :-}

2 Likes