9

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
user32882
  • 5,094
  • 5
  • 43
  • 82

4 Answers4

9

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.

cameronroytaylor
  • 1,578
  • 1
  • 17
  • 18
3

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.
Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54
  • i straight up copied what you wrote and it doesnt work for latex printing on my jupyter qtconsole. I can't accept this answer but I will vote up for the attempt – user32882 Sep 29 '17 at 19:50
  • @user32882: Please edit your question to specify that this is about LaTeX printing. – Wrzlprmft Sep 29 '17 at 19:55
2

I was googling some sympy stuff recently and came across this question which I asked almost 2 years ago. I am better with latex and sympy now, so I can say with great confidence that the most correct way of doing this is :

from sympy import symbols
nu = symbols('\\nu^\prime')
user32882
  • 5,094
  • 5
  • 43
  • 82
1

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.