Insert several lines of latex code with a keyboard shortcut or using a custom menu

I have been using texmacs for a year.
I am a mathematics teacher in a French high school.
For me, Texmacs is the ideal tool.
I’ve used Lyx for my lessons for years but switched to Texmacs for good.
I want to be able to add directly in the “graph” plugin (in fact in “pdflatex”) several lines of code to be able to use them often.
I can’t find the solution.
This is what I tried:

(:mode in-text?)
(“p r e.” (insert

It does not work.
Thank you for your help and especially thank you for this nice software that you improve regularly.

There are various problems with your code. First: you have to define it in your “init-texmacs.scm” and surround it with delayed. See similar topics in the forum for this. Second: I guess the proper keybinding is “p r e .” with a space before the full stop. Third : insert insert some content so you might have (insert "blahblah") to insert some text. You need quotes to explain this to TeXmacs. Anyway this will not do you what you want, because you really want to insert a plugin environment with your text inside and then evaluate it. You are not telling this to TeXmacs. It cannot guess which plugin you want based on the text you want to evaluate, so the command has to be more complex. The correct command to create an executable fold connected with a Graph plugin is (make-script-input* "Graph" "default") (I think). This would be equivalent to select the menu “Insert->Fold->Executable->Graph”. But this only provide a new empty tag in the document. One would need to fill it with the correct material. It seems to me that something like

(begin (make-script-input* "Graph" "default") (insert "blahblah"))

do the job. But still one would have to activate the script. At that point you can do it manually by pressing enter (the coursor should be in the right position). I’m not sure how to achieve this. @jeroen suggestions?

The following inserts and activates the script for me:

(begin (make-script-input* "Graph" "default") (insert "blahblah") (kbd-enter (cursor-tree) #f))

I find the use of kbd-enter not very satisfactory, though. I expected that script-evaluate would have done the trick instead of kbd-enter (since this is what the menu item Focus -> Evaluate runs). For some reason that doesn’t work.

I tested your code in a session scheme in texmacs and I get an error message:
Unbound variable: make-script-input*
Is this normal?
Thanks for your help

Which version of TeXmacs are you using? These functions have recently been changed in version 2.1.1.

The function alternate-toggle also works and may be more robust than kdb-enter:

(begin (make-script-input* "Graph" "default") (insert "blahblah") (alternate-toggle (cursor-tree)))

I have version 1.99.13 and I understand why it doesn’t work.
Can I use this command in a menu?
My other problem is this :
Is it possible to have two line output with the command (insert “text on first line text on second line”)?

Yes, certainly. The best place to start looking is probably Help -> Manual -> Customizing TeXmacs under “Creating your own dynamic menus”. Let us know if you get stuck.

Yes, you can use

(insert '(document "text on first line" "text on second line"))
1 Like

Thank you very much.
I will install version 2.1.1 and I will test all these codes carefully.
I’m gonna do some good publicity at Texmacs.