<\body> UPDATED: 19 May 2013 \; From: David E. Miller Subject: Modifying plugin for feasibility of plugin. \; In the plugin file t: Add to plugin file t import statement to import method: <\framed> <\verbatim-code> \; import os import traceback import keyword import re import string from sympy import latex # added to import sympy latex method DATA_BEGIN = chr(2) DATA_END = chr(5) DATA_ESCAPE = chr(27) DATA_COMMAND = chr(16) \; <\warning*> If module is not accessible, then an error is likely to be returned here. Probably need to add a condition that checks for the module and returns a ``nice'' message that module is not installed or not accessible. Edit/replace the method as follows <\framed> <\verbatim-code> \; def compose_output(data): \ \ \ \ \ """Do some parsing on the output according to its type.""" \ \ \ \ \ if isinstance(data, str) and data == "": \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return 'verbatim: %s' % str(data) \ \ \ \ \ if isinstance(data, str) and data.find('Traceback') != -1: \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return 'verbatim: %s' % str(data) \ \ \ \ \ if isinstance(data, str) and data.find('Error:') != -1: \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return 'verbatim: %s' % str(data) \ \ \ \ \ 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) \ \ \ \ \ \ data = latex(data,mode='inline') \ \ \ \ \ \ return 'latex: %s' % str(data) \; <\note*> The method uses the mode when used in this way. Then a session will return formatted output as shown below: <\session|python|default> <\output> Python plugin for TeXmacs. Please see the documentation in Help -\ plugins -\ Python <\input|Python] > from __future__ import division <\input|Python] > from sympy import * <\input|Python] > x, y, z, t = symbols('x y z t') <\input|Python] > k, m, n = symbols('k m n', integer=True) <\input|Python] > f, g, h = symbols('f g h', cls=Function) <\input|Python] > from sympy import Integral, latex <\input|Python] > from sympy.abc import x <\unfolded-io|Python] > 189856 <|unfolded-io> \ 189856 <\unfolded-io|Python] > 3.14159 <|unfolded-io> \ 3.141590 <\unfolded-io|Python] > "a string" <|unfolded-io> <\textput> This looks like a problem. Strings are being formatted as variables. \; <\unfolded-io|Python] > \\text{a string} <|unfolded-io> \ Traceback (most recent call last): \ \ File "tm_python", line 1 \ \ \ \ \\text{a string} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ^ SyntaxError: unexpected character after line continuation character <\textput> This does not work either. system error messages are also affected. So I added some code to catch exceptions in method to return exception and error messages verbatim. Otherwise these would be returned as and these messages do not display well if not verbatim. The question that remains if you want to output strings is how to detect what is and what is not. What is not (non- strings), needs to be returned formatted as a string. It looks like everything else is okay. Or you should merely not use strings with . <\textput> \; <\unfolded-io|Python] > while True print 'Hello world' <|unfolded-io> \ Traceback (most recent call last): \ \ File "tm_python", line 1 \ \ \ \ while True print 'Hello world' \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ^ SyntaxError: invalid syntax <\textput> Same issue here, but the error type is different. Again some code was added to catch this error and format it as instead of to avoid the display issue. \; <\unfolded-io|Python] > x**2 <|unfolded-io> > <\unfolded-io|Python] > 1/x <|unfolded-io> > <\unfolded-io|Python] > Integral(x**2, x) <|unfolded-io> x*d*x> \; <\unfolded-io|Python] > (1/cos(x)).series(x, 0, 10) <|unfolded-io> *x+*x+*x+*x+|)>> <\input|Python] > from sympy import Rational <\input|Python] > a = Rational(1,2) <\unfolded-io|Python] > a <|unfolded-io> > <\unfolded-io|Python] > a**2 <|unfolded-io> > <\unfolded-io|Python] > Rational(2)**50/Rational(10)**50 <|unfolded-io> > <\unfolded-io|Python] > 1/2 <|unfolded-io> \ 0 <\unfolded-io|Python] > \ x+y+x-y <|unfolded-io> <\unfolded-io|Python] > (x+y)**2 <|unfolded-io> > <\unfolded-io|Python] > ((x+y)**2).expand() <|unfolded-io> +2*x*y+y> <\input|Python] > from sympy import apart <\unfolded-io|Python] > 1/( (x+2)*(x+1) ) <|unfolded-io> *>> <\unfolded-io|Python] > apart(1/( (x+2)*(x+1) ), x) <|unfolded-io> +> <\input|Python] > from sympy import limit, Symbol, sin, oo <\input|Python] > x = Symbol("x") <\unfolded-io|Python] > limit(sin(x)/x, x, 0) <|unfolded-io> <\input|Python] > from sympy import diff, Symbol, sin, tan <\unfolded-io|Python] > diff(sin(x), x) <|unfolded-io> > <\unfolded-io|Python] > diff(sin(2*x), x) <|unfolded-io> > <\unfolded-io|Python] > diff(tan(x), x) <|unfolded-io> +1> <\input|Python] > from sympy import Matrix <\unfolded-io|Python] > Matrix([[1,0], [0,1]]) <|unfolded-io> |>||>>>>|)>> <\unfolded-io|Python] > Matrix([[1,0,3], [5,4,3],[0,1,8]]) <|unfolded-io> ||>|||>|||>>>>|)>> \; <\input|Python] > \; This is as much code as I have tried using this latest version. <\initial> <\collection>