Search code examples
octavetexsubscriptuicontrol

Is there a way to make octave interpret strings in static text of uicontrol using TeX (Greek letters, subscripts, superscripts etc.)?


I am writing a GUI in GNU octave (5.1.0). It is supposed to read some input values, make some calculations, plot some graphs and write the results. Everything works well besides the unwanted fact that uicontrol displays the given string uninterpreted (Greek letters, subscripts, superscripts etc.). Is there a way to change this?

I have tried to specify the interpreter inside the uicontrol:

uicontrol ("parent", p, "style",'text', "string", ["\beta Q_v [m^3/s]"],'interpreter','tex']);

But there is no such property listed in the documentation and hence no wonder I get this error:

error: set: unknown uicontrol property interpreter

Meanwhile, I have managed to insert the Greek letters into the displayed text using the UTF-8 ASCII code (in this case the letter beta):

uicontrol ("parent", p, "style",'text', "string", [char([206 178]) " Q_v [m^3/s]"],'interpreter','tex']);

That works fine. However the variable and its units are displayed the same way they are written in the code (no subscripts, no superscripts), which looks kind of silly and on top it is space consuming.

I have been searching all over the internet ever since I started with writing this GUI (2017 or so) but no luck. It seems as if no one has ever ran into this trouble, which seems strange to me. Am I missing something? Any help will be mostly appreciated!


Solution

  • There is no such option neither in Octave nor in Matlab. However, there is a workaround suggested by Pantxo, which can be found here. The trick is to "fake text-style uicontrol using proper text objects".

    In brief, one has to replace:

        uicontrol ("parent", p, "style",'text', "string", ...
        [char([206 178]) " Q_v[m^3/s]"], "position", [x0 y0 dx dy]);
    

    with

        hax = axes ("parent", p,"visible", "off", "position", [0 0 1 1]); 
        text ("parent", hax, "units", "pixels", "position", [x0 y0 0], ... 
        "interpreter", "tex", "string", "\\beta Q_v[m^3/s]", ... 
        "backgroundcolor", "none");
    

    One has to play a little with the font size etc., but the result is very satisfactory.