Form input for plugins

Hi!

so I wrote some simple plugins with python for texmacs and I would like to know if its possible to add toggle-buttons, input-fields and dropdown-menus when you pick your plugin.

If its possible, how can I create them and how can I get the picked inputs in my python code.

Thanks a lot!

Hi @codeLover and welcome to the forum.

Please take a look at Chapter 6 of the TeXmacs Scheme Developer Guide (http://www.texmacs.org/tmweb/documents/manuals/texmacs-scheme.en.pdf), “Extending the graphical user interface”.

I do not know how to apply the forms described in there to plugins written with Python, but maybe you will figure it out.

I have been able to use the widget forms for a plugin that I wrote with Scheme together with @jeroen:

Finally, if you would like to share your plugins that would be very nice. Either here or there is a repository of user-contributed code at https://github.com/texmacs/tm-forge

Hi pireddag and thanks for response!

At the moment I try to implement a code-highlighter that supports every language and every theme you like.
For that I am using pygments which creates HTML that we can render in our documents via flush_any.

The problem that I have is that I want to have a box where I can add my code, pick the theme and the language once and edit it how I want.

We can get a “box” where you can add your code to get processed with your python script with:
“Insert --> Fold --> Executable”,
but the problem that I try to fix is to create a “box” and store/pick the language and the style that I want, but when I edit my code again, I do not want to enter these configs (lanuge, style) again.

Hope thats almost clear :slight_smile:

I did not yet enter into the details of what you are doing—and I do not know if this suggestion will work—but I would try still with a tm-widget. I think that you can associate a Scheme program to each entry of the widget. In the program (to make things easy for a start) I would set a global variable (defined with tm-define in the TeXmacs initialization file, and set as uninitialized at the beginning) according to your choice, then I would use that to set the theme and language.
After this works, I would think on how to do the same thing without a global variable—of course associating the preferences to the box so that you can have different box with different languages (I do not yet know how to do that). Another desirable thing is to let the user know that a language has been se—the title of the box could be a good place, but I do not know how to do that yet either.

thanks for your response!
I know its hard but I am happy to know that I am not the only one that do not know how to do that :slight_smile:

The perfect solution would be “code box” that changes in style and interface when you want to edit stuff, so you can have a dropdown and some form elements in it, and when you are finished you get the rendered result (html). I am pretty sure that texmacs do not supports sutff like that, but the great thing about that is that we can store all this (the settings) in pure xml or some other serialized format.

Maybe someone else have some ideas :slight_smile:

I think the simplest way of doing this is the strategy used in @darcy’s Graph plugin, where the first line of input is used to configure the plugin.

I was guiding @codeLover through the concept of writing TeXmacs plugins on Gitter before this post appeared. I have writen a simple plugin as a demonstration for that discussion, which might be useful to others:

2 Likes

Good also for https://github.com/texmacs/tm-forge?

Yes, I agree. I’m going to some more testing, bug fixing and improvement, then move it to the forge.

A really cool approach. We should make syntax highlight extensible via plugins.

1 Like

Dear jeroen,

I installed the latest tm-pygments according to your instructions given in README.md under OSX 10.13.6. Upon trying to launch a tm-pygments session from within TeXmacs 2.1, I get the following error message:

Traceback (most recent call last):
     File "/Users/tilda/.TeXmacs/plugins/pygments/src/tm-pygments.py", line 23, in <module>
from pygments import highlight
    ImportError: No module named pygments

Yet pygments is on the system and active as py37-pygments v_2.10.0_0 via MacPorts. Moreover TeXmacs recognizes its port as the default Python, as can be seen from a python-plugin prompt.

Python 3.7.12 [/opt/local/bin/python3] 
Python plugin for TeXmacs.
Please see the documentation in Help -> Plugins -> Python

I tried to modify the above mentioned line 23 and change pgyments into py37-pygments but this resulted in a syntax-error message.

So, I wonder if you have any idea how I can get tm-pygments running.

Cheers, Tilda

Thanks for your report @Tilda. This is only a rough alpha version, so there will certainly be some bumps along the road!

What does

from pygments import highlight

or

from py37-pygments import highlight

say when you run it in a Python session in TeXmacs? If you get an error, can you try in a Python session on the terminal as well?

Thanks for your fast reply @jeroen.

Running

from py37-pygments import highlight

in a Python session both from within a terminal and TeXmacs produces a syntax error message. Whereas running

from pygments import highlight

in both environments seems to work fine as there are no error messages. However tm-pygments still doesn’t find pgyments module.

I’ve made a few changes to the plugin so that it should use the same version of Python as the Python plugin. Please see if that helps. If not, please file an issue on Github.

It helped! Thanks again.

1 Like