##// END OF EJS Templates
Merge pull request #1399 from asmeurer/sympyprinting...
Merge pull request #1399 from asmeurer/sympyprinting Use LaTeX to display, on output, various built-in types with the SymPy printing extension. SymPy's latex() function supports printing lists, tuples, and dicts using latex notation (it uses bmatrix, pmatrix, and Bmatrix, respectively). This provides a more unified experience with SymPy functions that return these types (such as solve()). Also display ints, longs, and floats using LaTeX, to get a more unified printing experience (so that, e.g., x/x will print the same as just 1). The string form can always be obtained by manually calling the actual print function, or 2d unicode printing using pprint(). SymPy's latex() function doesn't treat set() or frosenset() correctly presently (see http://code.google.com/p/sympy/issues /detail?id=3062), so for the present, we leave those alone.

File last commit:

r4872:34c10438
r6482:ba882bf7 merge
Show More
ipy_render.py
65 lines | 1.5 KiB | text/x-python | PythonLexer
vivainio
crlf cleanup
r680 """ IPython extension: Render templates from variables and paste to clipbard """
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
vivainio
crlf cleanup
r680
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
crlf cleanup
r680
from string import Template
import sys,os
Brian Granger
Moved Itpl.py to deathrow as we already have a copy in external.
r2031 from IPython.external.Itpl import itplns
vivainio
crlf cleanup
r680
def toclip_w32(s):
""" Places contents of s to clipboard
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 Needs pyvin32 to work:
http://sourceforge.net/projects/pywin32/
"""
import win32clipboard as cl
import win32con
cl.OpenClipboard()
cl.EmptyClipboard()
cl.SetClipboardText( s.replace('\n','\r\n' ))
cl.CloseClipboard()
try:
Bernardo B. Marques
remove all trailling spaces
r4872 import win32clipboard
vivainio
crlf cleanup
r680 toclip = toclip_w32
except ImportError:
def toclip(s): pass
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680
def render(tmpl):
""" Render a template (Itpl format) from ipython variables
Example:
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 $ import ipy_render
$ my_name = 'Bob' # %store this for convenience
$ t_submission_form = "Submission report, author: $my_name" # %store also
$ render t_submission_form
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 => returns "Submission report, author: Bob" and copies to clipboard on win32
# if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
Bernardo B. Marques
remove all trailling spaces
r4872 $ ;render c:/templates/greeting.txt
vivainio
crlf cleanup
r680 Template examples (Ka-Ping Yee's Itpl library):
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 Here is a $string.
Here is a $module.member.
Here is an $object.member.
Here is a $functioncall(with, arguments).
Here is an ${arbitrary + expression}.
Here is an $array[3] member.
Here is a $dictionary['member'].
"""
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 if os.path.isfile(tmpl):
tmpl = open(tmpl).read()
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 res = itplns(tmpl, ip.user_ns)
toclip(res)
return res
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.push('render')