sympify() can only parse things that are valid Python, meaning it can
only work with symbol names that are valid Python variable names.
E_1m1 is a valid Python variable name but E_{1\,-1} is not. If you
need to get a parsable string form for an expression you can use
srepr(), which would create a string with Symbol in it directly, like
Symbol('E_{1\\,-1{'), which can be parsed by sympify(). If your
symbols name is already LaTeX the latex() printer will just include it
directly.Aaron Meurer On Mon, Feb 10, 2020 at 1:52 PM Thomas Ligon <[email protected]> wrote: > > Hello Aaron, > thanks for the reply. First, subst() is a typo, and should be subs(), but I'm > not using it here anyway. > The test program contains this definition: > E1m1 = symbols('E_{1\,-1}') > so you can see that I am using the _ in it. The problem is the conversion to > latex, which recognizes E11, converting it the way I need, and does not > recognize/convert E1m1. > In any case your response has helped me see a bit clearer. I use E1m1 in the > code for expressions, and want it to appear as 'E_{1\,-1}' in latex. That > raises the question of how I should do this when I call sympify. In the line > of code above, both forms appear E1m1 and 'E_{1\,-1}', but not in sympify. > The next thing I will try is the following: > In the routine tripLet, I will create both strings, the symbol (e.g. E1m1) > and the latex display version (e.g. 'E_{1\,-1}'), then issue the call to > symbols(), and then combine the symbols to create and return the expression. > >> > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/4a42d8e5-9ae9-4faa-a797-05db5aa0d4a2%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BaiT4sshh_SAfmAsR-LYAuyb-L%2BpJgDYXi8-STyH%3DCFg%40mail.gmail.com.
