Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a particular symbol in SymPy

Tags:

latex

sympy

I am trying to achieve a symbol for the Greek letter nu followed by a prime superscript. This can be achieved easily using LaTeX:

$\nu'$

I tried many variants in SymPy, none of which gave me the right symbol:

nuprime = symbols('{\nu}\'')
nuprime = symbols('{nu}{\'}')
nuprime = symbols('nu\'')
nuprime = symbols('$nu\'$')

To mention a few. How do I get the symbol I am looking for on SymPy?

EDIT I am using jupyter qtconsole with latex printing. I wish to create the nu prime symbol in this environment.

like image 598
user32882 Avatar asked Sep 15 '17 08:09

user32882


3 Answers

You can do this using the word prime in the symbol definition (in the string, not the variable name). Using Python 2 in Jupyter Notebook,

from sympy import init_printing,latex,symbols
import numpy as np
init_printing()
nuprime = symbols('nuprime')
display(nuprime)
print(latex(nuprime))

displays

     nuprime

If your want it bold, you can display this by also including the word bold in the symbol definition

nuprime = symbols("nuprimebold")

     nuprimebold

And if you need a subscript, you can use an underscore to indicate the beginning of the subscript

nuprime_subscript = symbols("nuprime_subscript")

     nuprimesubscript

These postfixes can be combined as needed.

Other accents can also be used. The ones I am aware of in addition to prime are hat, check, tilde, acute, grave, dot, ddot, breve, bar, and vec, but I can't find an official source for this, so this may not be comprehensive. Here is the definition, display, and latex print for Jupyter Notebook with these accents.

nuhat,nucheck,nutilde,nuacute,nugrave,nudot,nuddot,nubreve,nubar,nuvec = symbols("nuhat,nucheck,nutilde,nuacute,nugrave,nudot,nuddot,nubreve,nubar,nuvec")

     nuaccents

This technique can be used to modify the display and latex output for any uppercase or lowercase letter of the English or Greek alphabet.

like image 141
cameronroytaylor Avatar answered Sep 28 '22 00:09

cameronroytaylor


I am not exactly sure in what context you want the symbol to be represented as ν', but for SymPy’s standard display the following works fine:

nuprime = sympy.symbols("ν'")

This makes use of the following:

  • Python 3 has a straightforward Unicode support.
  • You can delimit strings by either single or double quotes. Whatever you choose, the respective other character does not need to be escaped.
like image 40
Wrzlprmft Avatar answered Sep 28 '22 00:09

Wrzlprmft


I have had some success with the following, though I am not completely sure that I am exactly replicating your circumstances: 1) I opened Jupyter QtConsole 2) I inputted the following code:

import sympy as sp
sp.init_printing(use_latex=True)
nuprime = sp.symbols("\\nu'")
nuprime

This produced the symbol I think you're looking for, at least on my QtConsole.

like image 42
user10230906 Avatar answered Sep 28 '22 02:09

user10230906