Difficulty using external macros in TexMacs

Hello,
I created this scheme function called Tab-Val-Ligne-1 which works very well in the Scheme sessions and also with a keyboard shortcut using an executable foldable scheme …
I use Python to make a table of values ​​which is written in latex and which fits into TexMacs via the clipboard.

Here are the scheme functions used:

Here is a link to the python script: https://drive.google.com/file/d/16PIja9739t84MCCkSXGPt6t4zmpFu7cN/view?usp=sharing

(define (ext-perso a b)`(kbd-map (,a (begin (insert '(with “info-flag” “detailed” (flag ,b “red”)))(make-script-input* “scheme” “default”) (insert (string-append “(” ,b " )"))(go-to-previous)))))

(tm-define (tab-val-ligne-1 expression a b h arrondi_x arrondi_y)
(begin
(system (string-append "python3 /home/biz/Documents/autre-script/tab-val-ligne-1.py "
" \ " " expression " \ " "
(number->string a) " "
(number->string b) " "
(number->string h) " "
(number->string arrondi_x) " "
(number->string arrondi_y)))

;; Importer le tableau LaTeX depuis le presse-papier
(clipboard-paste-import "latex" "primary")

))

(eval(ext-perso “’ ’ ’ t v l 1” “tab-val-ligne-1”))

However, I tried to create an external macro in TexMacs from the Scheme Tab-Val-Ligne-1 function and all my attempts have failed: either TexMacs closes, or there are errors of arguments.

<assign|tab-val-ligne-1|<macro|expression|a|b|h|arrondi_x|arrondi_y|<extern|tab-val-ligne-1|<arg|expression>|<arg|a>|<arg|b>|<arg|h>|<arg|arrondi_x>|<arg|arrondi_y>>>>

I tried with instructions unquote and quasi as in other examples found on the forum or in packages, but nothing worked!

Before building the macro, maybe you have to improve the Tab-Val-Ligne-1 function? To be able to use it with the macro extern.
I think this macro extern is complicated to use and I am not a programmer.

Thank you very much for your possible help and especially for this sensational software that all mathematics teachers should know and use.

1 Like

When called through extern the Scheme function receives TeXmacs trees as input, not numbers as in the session. number->string does not expect trees, but numbers, so it complains. You could call tree->number on the input in your function before passing the result to number->string.

This is probably because of the expression argument, which is also a tree. You could apply tree->string

It’s strange.
On my first try, the value table appeared and then by doing the same manipulation Texmacs closes or there are errors or just a question mark.
The table is behind <inactive|<tab-val-line-1|“x”|0|0.5|0.1|1|1>> because it just comes from the clipboard.

My goal was to be able to reuse the macro to change the parameters of the array of values

I tried this by trying a single argument external macro but texmacs crashed…

<assign|test-tab-val|<macro|expression| <extern|tab-val-ligne-1|<arg|expression>|1|10|1|2|3>>>

Not much is missing for this to work.

I did not follow what the macro does. This said, I would debug it by printing out the input parameters inside the Scheme function and possibly printing out the output trees (both using the Scheme display function, which prints to the terminal if you run TeXmacs from the terminal.