Is there a way to set compound Greek letters as a character in SymPy?

As silly as this sounds, I would like to use compound Greek letters as one character in SymPy. For example, if the following is entered in Jupyter Notepad:

import sympy as sp ab = sp.Symbol("alpha beta") sp.pprint(ab) 

ab behaves as desired when used in symbolic manipulations, but the conclusion is:

 alpha beta 

I would like the result to be:

 α⋅β 

I can use the subs command after manipulations, for example:

 ab.subs({ab : sp.Symbol("alpha") * sp.Symbol("beta")}) 

but it is tiring and undesirable.

+5
source share
1 answer

Character names can be any string, but automatic conversion of letters to Greek letters for printing does not work for all input. I think it is not trying to break a line in spaces.

If you are using a Jupyter laptop, you can simply set the character name as LaTeX of what you want

 ab = Symbol(r'\alpha\cdot\beta') 

(don't forget the line prefix with r , so Python will not use backslash)

If you use text output, you can set it to a Unicode string. This should also work on a Jupyter laptop, although it will look slightly different since it will display the actual Unicode characters instead of LaTeX.

 ab = Symbol(u'α⋅β') 
+4
source

All Articles