#5653: [with patch, needs review] display docstrings in the notebook using html
and jsMath
-------------------------+--------------------------------------------------
 Reporter:  jhpalmieri   |       Owner:  boothby   
     Type:  enhancement  |      Status:  new       
 Priority:  major        |   Milestone:  sage-3.4.2
Component:  notebook     |    Keywords:            
-------------------------+--------------------------------------------------

Comment(by jhpalmieri):

 Here's a new patch incorporating Pat LeSmithe's latest ideas, plus a few
 new things.  This handles everything pretty well, although it might be a
 bit slow since Sphinx creates various files. I think it's slower than the
 standard docstring display in the notebook, but on the other hand, I also
 think it's fast enough to be usable. If we ever figure out how to run
 Sphinx without reading and writing files, we can do that instead.

 This latest version handles math well (via Sphinx), uses pygments to do
 syntax highlighting (via Sphinx), handles all of {{{identity_matrix(
 TAB}}}, {{{identity_matrix? TAB}}}, {{{identity_matrix? SHIFT-RETURN}}},
 and {{{identity_matrix??}}}.  There is now only one version of
 {{{set_introspect_html}}}: the Sphinx version.

 One of Pat's recent posts said:
 {{{
 * If anyone's interested, here's a way to render an input cell as
 syntax-highlighted HTML output:

 from pygments import highlight
 from pygments.lexers import PythonLexer
 from pygments.formatters import HtmlFormatter
 from pygments.styles import STYLE_MAP
 from pygments.styles import get_style_by_name
 from sphinx.highlighting import SphinxStyle

 class colorize:
     def __init__(self, style=SphinxStyle):
         self.lexer = PythonLexer(encoding='chardet')
         self.formatter = HtmlFormatter(noclasses=True, style=style)
     def eval(self, s, globals, locals):
         return html(highlight(s, self.lexer, self.formatter))

 Then put %colorize('colorful'), say, at the beginning of a cell and
 evaluate it, e.g.,

 %colorize('colorful')
 def f(x):
   return x * x
 f(3.0)

 STYLE_MAP.keys() gives a list of styles.  This is adapted from
 http://groups.google.com/group/sage-devel/msg/e53caae140cef7df .
 }}}
 There is already a file and a function called "colorize", but I added code
 like this, so that you can do
 {{{
 %pygments('colorful')
 def f(x):
   return x * x
 f(3.0)
 }}}
 (I was thinking of a name like "html" or "jsmath": pygments is what
 processes the rest of the cell, so that's the name of the decorator.) With
 the patch, this is automatically available in the notebook.

 I'm sure all of this could still use work, but I'll mark it as "needs
 review".

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5653#comment:2>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of 
Reinventing the Wheel

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to