Hi Aaron,

On 02/20/2012 09:25 PM, Aaron Meurer wrote:
The easiest way to do this is to use the symbol_names flag that was
recently added to latex().  I think this may have been added since
0.7.1, so you'll need to use a development version to get it (see
https://github.com/sympy/sympy/wiki/getting-the-bleeding-edge).  With
that, you can get:

In [462]: latex(phidd**2, symbol_names={phidd:r'\ddot{\varphi}'})
Out[462]: \ddot{\varphi}^{2}

that is the solution I was looking for. Thank you.

However, as far as I see, there is no possibility to pass the symbol_names argument to preview.

https://github.com/ness01/sympy/blob/master/sympy/printing/preview.py#L114


I think it should not be hard to modify the preview signature from

def preview(expr, output='png', viewer=None, euler=True):

to

def preview(expr, output='png', viewer=None, euler=True, **latex_settings):


pass these settix to the latex function.

Would that make sense?

Carsten.



If you don't want to type that each time, you can define the dict
before hand and do latex(expr, symbol_names=translation_dict), or if
you just want to make things fast for an interactive demo, you can
redefine latex at the beginning as

def latex(*args, **kwargs): # or def my_latex if you don't want to override it
     kwargs['symbol_names'] = {phidd:r'\ddot{\varphi}'}
     return sympy.latex(*args, **kwargs)

which will make things a little more confusing, but will allow for
faster typing (so it depends on what your goal is).

If you're using automatic latex in the IPython notebook or qtconsole,
you'll have to modify the sympy profile.

Aaron Meurer

On Mon, Feb 20, 2012 at 7:30 AM, Carsten Knoll<[email protected]>  wrote:
Hi,

I am writing a script in which I generate the an expression. This expression
I want to use 1) with preview and 2) with lambdify.


Lets say

expr = phidd**2

And I want preview to use the latex code '\ddot{\varphi}' for rendering of
phidd. Therfore I defined:

phidd = sp.Symbol(r'\ddot{\varphi}').


However, this causes problems when I call

sp.lambdify(phidd, expr)


File "<string>", line 1
     lambda \ddot{\varphi}: (\ddot{\varphi}**2)
                                              ^
SyntaxError: unexpected character after line continuation character

A manual workarround would be to substitute the critical symbol with some
uncritical one.

However Im wondering if there is another (cleaner) way.

I would like to use the code in a tutorial session, therefore I would like
minimize the ballast.


Best regards,
Carsten

--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.



--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to