Skip to Content.
Sympa Menu

texmacs-users - Re: [TeXmacs] Sympy plugin

Subject: mailing-list for TeXmacs Users

List archive

Re: [TeXmacs] Sympy plugin


Chronological Thread 
  • From: "David E. Miller" <address@hidden>
  • To: Bill Eaton <address@hidden>, address@hidden
  • Subject: Re: [TeXmacs] Sympy plugin
  • Date: Wed, 15 May 2013 03:02:49 -0400
  • Authentication-results: smtp02.embarq.synacor.com smtp.user=address@hidden; auth=pass (LOGIN)
  • X_cmae_category: 0,0 Undefined,Undefined

Hi Bill:

First, what is the version of TeXmacs and what is the operating system?

I have a project that is a VirtualBox GNU/Linux virtual machine that features TeXmacs as a core program and it has a recent version. I also have a MS Windows (7 Pro) version that is also recent.  I can't find a sympy plugin in either version in the distribution file tree as installed.

Second, since this is a Python module, I would first try to use the existing Python plugin and fire up a Python session in a TeXmacs doc and load your sympy module and see how the Python plugin handles the some stress tests you can try. If the results are normal, then I would take a hard look at the TeXmacs help docs on plugins to get an idea of these work in general.

Then, I would recommend that you try to merely copy the existing Python plugin and rename the copy so you can play with it. The main Python plugin file (/usr/lib/texmacs/TeXmacs/bin/tm_python) merely waits for raw input, processes that input and executes the processed code and then the output is then tweaked within this same loop (# Main session loop. it is a while 1 loop as I recall near the bottom of the file) and then this tweaked output is displayed as it returned to TeXmacs. So there is a lot going on in this loop.

Each of these plugins are  different. In general there exists one or more files written in the language that is native or related to the program of the plugin. There are are also some Scheme files involved. In the case of Maxima it is a little complicated. There are Lisp files that take the Maxima output and process it to get the nice display you see in Maxima TeXmacs session output. TeXmacs provides a framework for developing a plugin, but each plugin author has to put code together within that framework that gets the job done in a way that is in general unique.

In your case it might simply be a matter of modifying the tm_python file main loop and/or by adding some functions to that file called from within the main while loop to get done what is needed. Look at the functions:

     def texmacs_out(out_str):
    """Feed data back to TeXmacs.
   
    Output results back to TeXmacs, with the DATA_BEGIN,
    DATA_END control characters."""
    data_begin()
    os.sys.stdout.write(out_str)
    data_end()
    os.sys.stdout.flush()

def compose_output(data):
    """Do some parsing on the output according to its type."""
    if isinstance(data, str):
        return 'verbatim:'+data.strip()
    if isinstance(data, int):
        return 'verbatim: %d' % data
    if isinstance(data, float):
        return 'verbatim: %f' % data
   
    if isinstance(data, unicode):
        data2=r''
        for c in data:
            if c not in string.printable:
                data2+='\\x%x' % ord(c)
            else:
                data2+=c
        data="data2
    return 'verbatim: %s' % str(data)

in the file tm_python.

For your information I have thrown everything but the kitchen sink at this Python plugin and is has so far worked without any issues including loading and using numpy, scipy, scitools, matplotlib, etc. I have also used the Oct2Py module which is an Python interface to GNU Octave and that works without any known issue.

I close by commenting that these plugins when they are supported well and maintained are really great. The Maxima plugin is really good. However, some are not supported and maintained as well as others, and you just have to try those that you are interested in and see how each works and then try to figure out in some cases on your own how to fix any bugs and make modifications.

I like Python myself, and I have not tried sympy, but I can say without much hesitation that Maxima really is hard to beat.

Lots of words. Hope this helps.

Best wishes,

David Miller




On 5/15/2013 12:34 AM, Bill Eaton wrote:
It has been pointed out to me by the SymPy community that the SymPy plugin for TexMacs is quite old and maybe hasn't kept up with the times. I can accept that. If it's simple, I'd like to see if I can fix it.

I browsed through the tm_sympy file. It looks like the SymPy plugin takes the all outputs and runs them through the sympy.printing.latex() function. So far so good.

Many outputs look good. For example
  (x**2+y**2)/a

Is formatted nicely (i.e. it looks great on screen). The LaTeX outputted from SymPy is
  '\\frac{x^{2} + y^{2}}{a}'

I run into trouble from integrals and square roots.
   TeXMacs Session   TexMacs Output     SymPy output
   sqrt(x)           <large-sqrt-0> x   '\\sqrt{x}'
   Integral(x**2,x)  <
big-int-2> x²dx   '\\int x^{2}\\,dx'

Is there something funky about SymPy's LaTeX output? Or does TexMacs have a slightly different LaTeX syntax?

Finally, I observe that the Maxima plugin works quite well. But I cannot make sense of what is happening in that plugin.

Any ideas?

--Bill Eaton





On 04/26/2013 09:45 PM, Bill Eaton wrote:
I have a partial answer to my question.

It turns out that the downloaded files from the Sympy Github repository work fine. Or mostly fine. I made a mistake and ended up saving an html file instead of a Scheme file.

tm_sympy  --> /usr/share/texmacs/TeXmacs/plugins/sympy/progs/

init-sympy.scm --> /usr/lib/texmacs/TeXmacs/bin

I had to change the permissions on tm_sympy to make it look like other files in that directory.

Now I get a Sympy menu entry under Sessions. And I can launch a session. The only problem is that result formatting is gibberish and I can't seem to figure out how to turn on LaTeX formatting.





Archive powered by MHonArc 2.6.19.

Top of Page