Skip to content

Commit

Permalink
Merge remote-tracking branches '@jhpalmieri/mathmode_v2' and '@jhpalm…
Browse files Browse the repository at this point in the history
…ieri/latex-macros'; commit '4696154' from @robertwb

A batch of changes for bumping the sagenb version in Sage
  • Loading branch information
kini committed Jan 16, 2013
4 parents e11c433 + 5985758 + 9cf8ac7 + 4696154 commit ae02bff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
24 changes: 20 additions & 4 deletions sagenb/misc/sphinxify.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@
SAGE_DOC = '' # used to be None


def is_sphinx_markup(docstring):
"""
Returns whether a string that contains Sphinx-style ReST markup.
INPUT:
- ``docstring`` - string to test for markup
OUTPUT:
- boolean
"""
# this could be made much more clever
return ("`" in docstring or "::" in docstring)


def sphinxify(docstring, format='html'):
r"""
Runs Sphinx on a ``docstring``, and outputs the processed
Expand All @@ -55,7 +71,7 @@ def sphinxify(docstring, format='html'):
sage: sphinxify('**Testing**\n`monospace`')
'\n<div class="docstring"...<strong>Testing</strong>\n<span class="math"...</p>\n\n\n</div>'
sage: sphinxify('`x=y`')
'\n<div class="docstring">\n \n <p><span class="math">\\(x=y\\)</span></p>\n\n\n</div>'
'\n<div class="docstring">\n \n <p><span class="math">x=y</span></p>\n\n\n</div>'
sage: sphinxify('`x=y`', format='text')
'x=y\n'
sage: sphinxify(':math:`x=y`', format='text')
Expand Down Expand Up @@ -282,7 +298,7 @@ def generate_configuration(directory):
mathjax_path = 'MathJax.js?config=TeX-AMS_HTML-full,../mathjax_sage.js'
from sage.misc.latex_macros import sage_mathjax_macros
html_theme_options['mathjax_macros'] = sage_mathjax_macros
html_theme_options['mathjax_macros'] = sage_mathjax_macros()
from pkg_resources import Requirement, working_set
sagenb_path = working_set.find(Requirement.parse('sagenb')).location
Expand Down Expand Up @@ -386,14 +402,14 @@ def generate_configuration(directory):
try:
from sage.misc.latex_macros import sage_latex_macros
except ImportError:
sage_latex_macros = []
def sage_latex_macros(): return []
try:
pngmath_latex_preamble # check whether this is already defined
except NameError:
pngmath_latex_preamble = ""
for macro in sage_latex_macros:
for macro in sage_latex_macros():
# used when building latex and pdf versions
latex_elements['preamble'] += macro + '\n'
# used when building html version
Expand Down
16 changes: 12 additions & 4 deletions sagenb/misc/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def format_src(s, *args, **kwds):
return s

try:
from sagenb.misc.sphinxify import sphinxify
from sagenb.misc.sphinxify import sphinxify, is_sphinx_markup
except ImportError, msg:
print msg
print "Sphinx docstrings not available."
# Don't do any Sphinxifying if sphinx's dependencies aren't around
def sphinxify(s):
return s
def is_sphinx_markup(s):
return False

######################################################################
# Initialization
Expand Down Expand Up @@ -276,10 +278,16 @@ def docstring(obj_name, globs, system='sage'):

def html_markup(s):
try:
from sagenb.misc.sphinxify import sphinxify
return sphinxify(s)
from sagenb.misc.sphinxify import sphinxify, is_sphinx_markup
except ImportError, msg:
pass
# sphinx not available
def is_sphinx_markup(s): return False

if is_sphinx_markup(s):
try:
return sphinxify(s)
except:
pass
# Not in ReST format, so use docutils
# to process the preamble ("**File:**" etc.) and put
# everything else in a <pre> block.
Expand Down
2 changes: 2 additions & 0 deletions sagenb/notebook/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,8 @@ def interact(f, layout=None, width='800px'):
... html('There is no solution to $$%s x=%s$$'%(latex(A), latex(v)))
<html>...
"""
if not isinstance(f, types.FunctionType) and callable(f):
f = f.__call__
(args, varargs, varkw, defaults) = inspect.getargspec(f)

if defaults is None:
Expand Down

0 comments on commit ae02bff

Please sign in to comment.