How to do a fancy print in ipython

94 views
Skip to first unread message

Macias

unread,
Apr 3, 2014, 10:37:01 AM4/3/14
to sy...@googlegroups.com
Hi, I'm trying to pprint() a variable that I call barphi. What I want to get is
$\bar{\phi}$
when printed as pprint(barphi).

I try 

barphy = Symbol('\bar{phi}')

 but it does not work. Any help? Thanks in advance.


Aaron Meurer

unread,
Apr 3, 2014, 11:42:19 AM4/3/14
to sy...@googlegroups.com
Python converts \ + character in strings as escaping. The \b in your string becomes a backspace (see https://en.wikipedia.org/wiki/ASCII#ASCII_control_code_chart).

You need to either escape the \, i.e., use '\\bar{\\phi}$', or, much easier, if you don't care about escaping, use a raw string, which just means to put an r in front of the quotes, like r'\bar{\phi}'.

If you want to get LaTeX, pprint() will not do it. You should use init_printing() to enable latex printing.

Aaron Meurer


--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d1da7393-dee0-4a17-a0b8-f9dc07379454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julien Rioux

unread,
Apr 3, 2014, 11:49:34 AM4/3/14
to sy...@googlegroups.com
On Thursday, 3 April 2014 11:42:19 UTC-4, Aaron Meurer wrote:
Python converts \ + character in strings as escaping. The \b in your string becomes a backspace (see https://en.wikipedia.org/wiki/ASCII#ASCII_control_code_chart).

You need to either escape the \, i.e., use '\\bar{\\phi}$', or, much easier, if you don't care about escaping, use a raw string, which just means to put an r in front of the quotes, like r'\bar{\phi}'.

If you want to get LaTeX, pprint() will not do it. You should use init_printing() to enable latex printing.



You can also name your Symbol "phibar" and it will correspond to r"\bar{\phi}" in the LaTeX representation.
Cheers,
Julien
Reply all
Reply to author
Forward
0 new messages