Ticket #9774: mathjax-try2.patch

File mathjax-try2.patch, 59.0 KB (added by jason, 8 years ago)

Apply only this patch

  • doc/common/builder.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1308085809 25200
    # Node ID 085d5e7aa31309ce73002ae2afa1c77f7ceee16f
    # Parent  8fbe88616398352f5926a3f548ad6845a3306615
    #9774: switch Sage library from jsMath to MathJax.
    TO DO: make Sphinx work with MathJax.  So:
    - upgrade sphinx to version >= 1.1 or add mathjax.py
      (this patch adds mathjax.py to sage/doc/common)
    - set mathjax_path correctly in conf.py?
    - fix pathname at the end of mathjax_sage.js_t?
    - also: don't include MathJax in all_notebook.py?
    - in latex.py, make "jsmath" an alias to "mathjax"?
    - in scripts repo, there are a few references to jsmath which
      need to be fixed
    
    diff --git a/doc/common/builder.py b/doc/common/builder.py
    a b  
    758758    s += "    sage -docbuild -FDC all\n"
    759759    s += "    sage -docbuild constructions pdf\n"
    760760    s += "    sage -docbuild reference html -jv3\n"
    761     s += "    sage -docbuild --jsmath tutorial html\n"
     761    s += "    sage -docbuild --mathjax tutorial html\n"
    762762    s += "    sage -docbuild reference print_unincluded_modules\n"
    763763    s += "    sage -docbuild developer -j html --sphinx-opts -q,-aE --verbose 2"
    764764    return s
     
    931931                        default=False, action="store_true",
    932932                        help="include variables prefixed with '_' in reference manual; may be slow, may fail for PDF output")
    933933
    934     standard.add_option("-j", "--jsmath", dest="jsmath",
     934    standard.add_option("-j", "--mathjax", "--jsmath", dest="mathjax",
    935935                        action="store_true",
    936                         help="render math using jsMath; FORMATs: html, json, pickle, web")
     936                        help="render math using MathJax; FORMATs: html, json, pickle, web")
    937937    standard.add_option("--no-pdf-links", dest="no_pdf_links",
    938938                        action="store_true",
    939939                        help="do not include PDF links in DOCUMENT 'website'; FORMATs: html, json, pickle, web")
     
    10381038    logger = setup_logger(options.verbose, options.color)
    10391039
    10401040    # Process selected options.
    1041     if options.jsmath:
    1042         os.environ['SAGE_DOC_JSMATH'] = "True"
     1041    if (options.mathjax or (os.environ.get('SAGE_DOC_MATHJAX', False))
     1042        or (os.environ.get('SAGE_DOC_JSMATH', False))):
     1043        os.environ['SAGE_DOC_MATHJAX'] = "True"
    10431044
    10441045    if options.check_nested:
    10451046        os.environ['SAGE_CHECK_NESTED'] = 'True'
  • doc/common/conf.py

    diff --git a/doc/common/conf.py b/doc/common/conf.py
    a b  
    1717              'sphinx.ext.inheritance_diagram', 'sphinx.ext.todo']
    1818#, 'sphinx.ext.intersphinx', 'sphinx.ext.extlinks']
    1919
    20 if 'SAGE_DOC_JSMATH' in os.environ:
    21     extensions.append('sphinx.ext.jsmath')
     20# The environment variable SAGE_DOC_MATHJAX may be set by the user or
     21# by the file "builder.py".  If it's set, or if SAGE_DOC_JSMATH is set
     22# (for backwards compatibility), use MathJax.
     23if (os.environ.get('SAGE_DOC_MATHJAX', False)
     24    or os.environ.get('SAGE_DOC_JSMATH', False)):
     25    extensions.append('mathjax')
     26    # This setting for mathjax_path requires that mathjax_sage.js be
     27    # created in the right directory.  See below (search this file for
     28    # "mathjax_sage") for details.
     29    # TODO MATHJAX: figure out the right path below
     30    #mathjax_path = 'MathJax.js?config=TeX-AMS_HTML-full,local/mathjax_sage.js'
     31    mathjax_path = 'MathJax.js'
    2232else:
    23     extensions.append('sphinx.ext.pngmath')
    24 jsmath_path = 'jsmath_sage.js'
     33     extensions.append('sphinx.ext.pngmath')
    2534
    2635# Add any paths that contain templates here, relative to this directory.
    2736templates_path = [os.path.join(SAGE_DOC, 'common/templates'), 'templates']
     
    103112# -----------------------
    104113
    105114# HTML theme (e.g., 'default', 'sphinxdoc').  We use a custom Sage
    106 # theme to set a Pygments style, stylesheet, and insert jsMath macros. See
     115# theme to set a Pygments style, stylesheet, and insert MathJax macros. See
    107116# the directory doc/common/themes/sage/ for files comprising the custom Sage
    108117# theme.
    109118html_theme = 'sage'
     
    113122# see the documentation.
    114123html_theme_options = {}
    115124
    116 if 'SAGE_DOC_JSMATH' in os.environ:
    117     from sage.misc.latex_macros import sage_jsmath_macros_easy
    118     html_theme_options['jsmath_macros'] = sage_jsmath_macros_easy
    119 
    120     from sage.misc.package import is_package_installed
    121     html_theme_options['jsmath_image_fonts'] = is_package_installed('jsmath-image-fonts')
    122 
    123125# Add any paths that contain custom themes here, relative to this directory.
    124126html_theme_path = [os.path.join(SAGE_DOC, 'common/themes')]
    125127
     
    148150# so a file named "default.css" will overwrite the builtin "default.css".
    149151html_static_path = [os.path.join(SAGE_DOC, 'common/static'), 'static']
    150152
    151 # If we're using jsMath, we prepend its location to the static path
     153# If we're using MathJax, we prepend its location to the static path
    152154# array.  We can override / overwrite selected files by putting them
    153 # in the remaining paths.
    154 if 'SAGE_DOC_JSMATH' in os.environ:
     155# in the remaining paths.  We also write the local config file,
     156# containing Sage-specific macros and allowing the use of dollar signs
     157# to delimit math.  We write the file to the directory
     158#    sagenb/data/mathjax/config/local/mathjax_sage.js,
     159# in the sagenb-... subdirectory of
     160#    SAGE_ROOT/local/lib/python/site-libraries.
     161# This is in the static path, so the file gets copied to the
     162# appropriate place, allowing us to use the above setting for
     163# mathjax_path.
     164if (os.environ.get('SAGE_DOC_MATHJAX', False)
     165    or os.environ.get('SAGE_DOC_JSMATH', False)):
     166
     167    # TODO MATHJAX (Jason): this option is used with the themes/sage/static/mathjax_sage.js_t
     168    # template.  Either this method or the method below should be used, I think.
     169
     170    #from sage.misc.latex_macros import sage_mathjax_macros
     171    #html_theme_options['mathjax_macros'] = sage_mathjax_macros
     172
     173    # TODO MATHJAX: OR do the following to write the configuration each time.
     174
    155175    from pkg_resources import Requirement, working_set
     176    from sage.misc.latex_macros import sage_mathjax_macros
    156177    sagenb_path = working_set.find(Requirement.parse('sagenb')).location
    157     jsmath_static = os.path.join(sagenb_path, 'sagenb', 'data', 'jsmath')
    158     html_static_path.insert(0, jsmath_static)
     178    mathjax_static = os.path.join(sagenb_path, 'sagenb', 'data', 'mathjax')
     179    # Write the local configuration file.  If it already exists,
     180    # overwrite it (in case the macros have been modified since it was
     181    # first created).
     182    mathjax_configuration_string = '''
     183MathJax.Hub.Config({
     184  tex2jax: {
     185    inlineMath: [['$','$'],['\\(','\\)']],
     186    processEscapes: true
     187  },
     188  styles: {
     189    ".MathJax .mo, .MathJax .mi": {
     190      color: "inherit ! important"
     191    }
     192  },
     193  TeX: {
     194    Macros: {
     195     %s
     196    }
     197  }
     198});
     199
     200MathJax.Ajax.loadComplete("[MathJax]/local/mathjax_sage.js")
     201''' % ',\n'.join(sage_mathjax_macros)
     202    config_file = os.path.join(mathjax_static, 'config', 'local',
     203                               'mathjax_sage.js')
     204    with open(config_file, 'w') as F:
     205        F.write(mathjax_configuration_string)
     206
     207    html_static_path.insert(0, mathjax_static)
    159208
    160209# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
    161210# using the given strftime format.
     
    402451
    403452def process_mathtt(app, what, name, obj, options, docstringlines):
    404453    r"""
    405     Replace \mathtt{BLAH} with \verb|BLAH| if using jsMath.
     454    Replace \mathtt{BLAH} with \verb|BLAH| if using MathJax.
    406455    See sage.misc.sagedoc.process_mathtt for more information
    407456    """
    408     if (len(docstringlines) > 0 and 'SAGE_DOC_JSMATH' in os.environ
     457    if (len(docstringlines) > 0 and
     458        (os.environ.get('SAGE_DOC_MATHJAX', False)
     459         or os.environ.get('SAGE_DOC_JSMATH', False))
    409460        and name.find("process_mathtt") == -1):
    410461        from sage.misc.sagedoc import process_mathtt as sagedoc_mathtt
    411462        s = sagedoc_mathtt("\n".join(docstringlines), True)
  • .js_t

    diff --git a/doc/common/themes/sage/static/jsmath_sage.js_t b/doc/common/themes/sage/static/mathjax_sage.js_t
    rename from doc/common/themes/sage/static/jsmath_sage.js_t
    rename to doc/common/themes/sage/static/mathjax_sage.js_t
    old new  
    1 /**********************************************************************
    2  *
    3  *   Customize the values given below to suit your needs.
    4  *   You can make additional copies of this file with
    5  *   different customizated settings if you need to load
    6  *   jsMath with different parameters.
    7  *
    8  *   Load this page via:
    9  *
    10  *   <SCRIPT SRC="path-to-jsMath/easy/load.js"></SCRIPT>
    11  *
    12  *   (If you are including this file into your page via Server-Side
    13  *   Includes, you should remove line above.)
    14  *
    15  *   You can make copies of this file with different settings
    16  *   if you need to have several different configurations.
    17  *
    18  **********************************************************************/
     1MathJax.Hub.Config({
     2  tex2jax: {
     3    inlineMath: [['$','$'],['\\(','\\)']],
     4    processEscapes: true
     5  },
     6  styles: {
     7    ".MathJax .mo, .MathJax .mi": {
     8      color: "inherit ! important"
     9    }
     10  },
     11  TeX: {
     12    Macros: {
     13     {{ theme_mathjax_macros|join(',\n') }}
     14    }
     15  }
     16});
    1917
    20     if (!window.jsMath) {window.jsMath = {}}
    21 
    22 //  Move the jsMath button 20 pixels from the right edge (apparently
    23 //  in some browsers, it covers up the scroll bar)
    24 jsMath.styles = {
    25     '#jsMath_button' : 'position:fixed; bottom:1px; right:20px; '
    26         + 'background-color:white; border: solid 1px #959595; margin:0px; '
    27         + 'padding: 0px 3px 1px 3px; z-index:102; color:black; '
    28         + 'text-decoration:none; font-size:x-small; width:auto; cursor:hand;'
    29 }
    30 
    31 jsMath.Easy = {
    32     //
    33     //  The URL of the root jsMath directory on your server
    34     //  (it must be in the same domain as the HTML page).
    35     //  It should include "http://yoursite.com/", or should
    36     //  be relative to the root of your server.  It is possible
    37     //  to be a relative URL, but it will be relative to the
    38     //  HTML page loading this file.
    39     //
    40     //  If you leave this blank, jsMath will try to look it up from
    41     //  the URL where it loaded this file, but that may not work.
    42     //
    43     root: "",
    44 
    45     //
    46     //  The default scaling factor for mathematics compared to the
    47     //  surrounding text.
    48     //
    49     scale: 115,
    50 
    51     //
    52     //  1 means use the autoload plug-in to decide if jsMath should be loaded
    53     //  0 means always load jsMath
    54     //
    55     autoload: 1,
    56 
    57     //
    58     //  Setting any of these will cause the tex2math plugin to be used
    59     //  to add the <DIV> and <SPAN> tags that jsMath needs.  See the
    60     //  documentation for the tex2math plugin for more information.
    61     //
    62     processSlashParens: 0,       // process \(...\) in text?
    63     processSlashBrackets: 0,     // process \[...\] in text?
    64     processDoubleDollars: 0,     // process $$...$$ in text?
    65     processSingleDollars: 0,     // process $...$ in text?
    66     processLaTeXenvironments: 0, // process \begin{xxx}...\end{xxx} outside math mode?
    67     fixEscapedDollars: 0,        // convert \$ to $ outside of math mode?
    68     doubleDollarsAreInLine: 0,   // make $$...$$ be in-line math?
    69     allowDisableTag: 0,          // allow ID="tex2math_off" to disable tex2math?
    70     //
    71     //  If you want to use your own custom delimiters for math instead
    72     //  of the usual ones, then uncomment the following four lines and
    73     //  insert your own delimiters within the quotes.  You may want to
    74     //  turn off processing of the dollars and other delimiters above
    75     //  as well, though you can use them in combination with the
    76     //  custom delimiters if you wish.  See the tex2math documentation
    77     //  for more details.
    78     //
    79     //customDelimiters: [
    80     //  '[math]','[/math]',        // to begin and end in-line math
    81     //  '[display]','[/display]'   // to begin and end display math
    82     //],
    83 
    84     //
    85     //  Disallow the use of the @(...) mechanism for including raw HTML
    86     //  in the contents of \hbox{}?  (If used in a content-management system
    87     //  where users are allowed to enter mathematics, setting this to 0
    88     //  would allow them to enter arbitrary HTML code within their
    89     //  math formulas, and that poses a security risk.)
    90     //
    91     safeHBoxes: 1,
    92 
    93     //
    94     //  Show TeX source when mathematics is double-clicked?
    95     //
    96     allowDoubleClicks: 1,
    97 
    98     //
    99     //  Show jsMath font warning messages?  (Disabling this prevents yours
    100     //  users from finding out that they can have a better experience on your
    101     //  site by installing some fonts, so don't disable this).
    102     //
    103     showFontWarnings: 0,
    104 
    105     //
    106     //  Use "Process" or "ProcessBeforeShowing".  See the jsMath
    107     //  author's documentation for the difference between these
    108     //  two routines.
    109     //
    110     method: "Process",
    111 
    112     //
    113     //  List of plug-ins and extensions that you want to be
    114     //  loaded automatically.  E.g.
    115     //      ["plugins/mimeTeX.js","extensions/AMSsymbols.js"]
    116     //
    117     loadFiles: [
    118         "extensions/verb.js",
    119         "extensions/moreArrows.js",
    120         "extensions/AMSmath.js",
    121         "extensions/AMSsymbols.js"
    122     ],
    123 
    124     //
    125     //  List of fonts to load automatically.  E.g.
    126     //      ["cmmib10"]
    127     //
    128     loadFonts: [],
    129 
    130     //
    131     //  List of macros to define.  These are of the form
    132     //      name: value
    133     //  where 'value' is the replacement text for the macro \name.
    134     //  The 'value' can also be [value,n] where 'value' is the replacement
    135     //  text and 'n' is the number of parameters for the macro.
    136     //  Note that backslashes must be doubled in the replacement string.
    137     //  E.g.,
    138     //      {
    139     //        RR: '{\\bf R}',
    140     //        bold: ['{\\bf #1}', 1]
    141     //      }
    142     //
    143     // Sage-specific jsMath macros.
    144     macros: {
    145     {{ theme_jsmath_macros|join(',\n') }}
    146     },
    147 
    148     //
    149     //  Allow jsMath to enter global mode?
    150     //  (Uses frames, so may not always work with complex web sites)
    151     //
    152     allowGlobal: 1,
    153 
    154     //
    155     //  Disable image fonts?  (In case you don't load them on your server.)
    156     //
    157     // If we set this to 1, we do not need to load plugins/noImageFonts.js
    158     {% if theme_jsmath_image_fonts %}
    159     noImageFonts: 0
    160     {% else %}
    161     noImageFonts: 1
    162     {% endif %}
    163 };
    164 
    165 /****************************************************************/
    166 /****************************************************************/
    167 //
    168 //            DO NOT MAKE CHANGES BELOW THIS
    169 //
    170 /****************************************************************/
    171 /****************************************************************/
    172 
    173 jsMath.Easy.find_root = function () {
    174     if (jsMath.Easy.root == "") {
    175         jsMath.Easy.root = document.getElementsByTagName("script");
    176         for (var i = 0; i < jsMath.Easy.root.length; i++) {
    177             if (jsMath.Easy.root[i].src.match(/doctools.js$/)) {
    178                 jsMath.Easy.root = jsMath.Easy.root[i].src.replace(/doctools.js$/, "");
    179                 return;
    180             }
    181         }
    182         jsMath.Easy.root = jsMath.Easy.root[jsMath.Easy.root.length-1].src
    183         if (jsMath.Easy.root.match(/\/easy\/[^\/]*$/)) {
    184             jsMath.Easy.root = jsMath.Easy.root.replace(/\/easy\/[^\/]*$/,"");
    185         } else {
    186             jsMath.Easy.root = jsMath.Easy.root.replace(/\/(jsMath\/(easy\/)?)?[^\/]*$/,"/jsMath");
    187         }
    188     }
    189 };
    190 
    191 jsMath.Easy.find_root();
    192 
    193 jsMath.Easy.root = jsMath.Easy.root.replace(/\/$/,""); // trim trailing "/" if any
    194 
    195 document.write('<SCRIPT SRC="'+jsMath.Easy.root+'/jsMath-easy-load.js"><'+'/SCRIPT>');
     18MathJax.Ajax.loadComplete("[MathJax]/config/local/local.js")
  • doc/common/themes/sage/theme.conf

    diff --git a/doc/common/themes/sage/theme.conf b/doc/common/themes/sage/theme.conf
    a b  
    66[options]
    77# Custom Sage theme options
    88
    9 # jsMath settings filled in by conf.py
    10 jsmath_macros =
    11 jsmath_image_fonts =
     9# MathJax settings filled in by conf.py
     10mathjax_macros =
    1211
    1312# Sphinx default theme options
    1413
  • doc/en/introspect/conf.py

    diff --git a/doc/en/introspect/conf.py b/doc/en/introspect/conf.py
    a b  
    66sys.path.append(os.environ['SAGE_DOC'])
    77from common.conf import *
    88
    9 extensions = ['sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.todo']
     9extensions = ['sphinx.ext.autodoc', 'sphinx.ext.mathjax', 'sphinx.ext.todo']
    1010
    1111templates_path = ['templates']
    1212html_static_path = ['static']
  • doc/en/thematic_tutorials/conf.py

    diff --git a/doc/en/thematic_tutorials/conf.py b/doc/en/thematic_tutorials/conf.py
    a b  
    2828# Output file base name for HTML help builder.
    2929htmlhelp_basename = "thematic_tutorials"
    3030
    31 # mathfrak isn't defined in jsMath, so using it gives errors.  The
    32 # following line turns it into bold face only when using jsMath, thus
    33 # avoiding the errors, while keeping the nice mathfrak fonts when not
    34 # using jsMath.
    35 try:
    36     html_theme_options['jsmath_macros'].append("mathfrak : ['\\\\mathbf{#1}', 1]")
    37 except KeyError:
    38     html_theme_options['jsmath_macros'] = ["mathfrak : ['\\\\mathbf{#1}', 1]"]
    39 
    4031# Grouping the document tree into LaTeX files. List of tuples
    4132# (source start file, target name, title, author,
    4233# document class [howto/manual]).
  • sage/all_notebook.py

    diff --git a/sage/all_notebook.py b/sage/all_notebook.py
    a b  
    1111
    1212sage_mode = 'notebook'
    1313
    14 from sage.misc.latex import Latex, pretty_print_default, JSMath
     14from sage.misc.latex import Latex, pretty_print_default, MathJax
    1515latex = Latex(density=130)
    1616latex_debug = Latex(debug=True, density=130)
    1717slide = Latex(slide=True, density=256)
    1818slide_debug = Latex(slide=True, debug=True, density=256)
    1919pdflatex = Latex(density=130, pdflatex=True)
    2020pdflatex_debug = Latex(density=130, pdflatex=True, debug=True)
    21 # we need a global instance of this in order to get %jsmath to work...
    22 jsmath = JSMath()
     21# we need a global instance of this in order to get %mathjax to work...
     22mathjax = MathJax()
    2323
    2424from sage.misc.python import python
    2525
  • sage/graphs/graph_latex.py

    diff --git a/sage/graphs/graph_latex.py b/sage/graphs/graph_latex.py
    a b  
    4848
    4949Customizing the output is accomplished in several ways.  Suppose ``g`` is a graph, then ``g.set_latex_options()`` can be used to efficiently set or modify various options.  Setting individual options, or querying options, can be accomplished by first using a command like ``opts = g.latex_options()`` to obtain a :class:`sage.graphs.graph_latex.GraphLatex` object which has several methods to set and retrieve options.
    5050
    51 Here is a minimal session demonstrating how to use these features. The following setup should work in the notebook or at the command-line, though the call to :meth:`~sage.misc.latex.Latex.jsmath_avoid_list` is only needed in the notebook. ::
     51Here is a minimal session demonstrating how to use these features. The following setup should work in the notebook or at the command-line, though the call to :meth:`~sage.misc.latex.Latex.mathjax_avoid_list` is only needed in the notebook. ::
     52
    5253
    5354    sage: from sage.graphs.graph_latex import setup_latex_preamble
    5455    sage: setup_latex_preamble()
     
    5859    \usepackage{tkz-berge}
    5960    \usetikzlibrary{arrows,shapes}
    6061    sage: latex.engine('pdflatex')
    61     sage: latex.jsmath_avoid_list('tikzpicture')
     62    sage: latex.mathjax_avoid_list('tikzpicture')
    6263    sage: H=graphs.HeawoodGraph()
    6364    sage: H.set_latex_options(
    6465    ...   graphic_size=(5,5),
  • sage/matrix/matrix0.pyx

    diff --git a/sage/matrix/matrix0.pyx b/sage/matrix/matrix0.pyx
    a b  
    18501850       
    18511851        row_divs, col_divs = self.subdivisions()
    18521852       
    1853         from sage.server.support import EMBEDDED_MODE
    1854 
    1855         # jsmath doesn't know the command \hline, so have to do things
    1856         # differently (and not as attractively) in embedded mode:
    1857         # construct an array with a subarray for each block.
    1858         if len(row_divs) + len(col_divs) > 0 and EMBEDDED_MODE:
    1859             for r in range(len(row_divs)+1):
    1860                 s = ""
    1861                 for c in range(len(col_divs)+1):
    1862                     if c == len(col_divs):
    1863                         sep=""
    1864                     else:
    1865                         sep=" & "
    1866                     sub = self.subdivision(r,c)
    1867                     if sub.nrows() > 0 and sub.ncols() > 0:
    1868                         entry = latex(self.subdivision(r,c))
    1869                         s = s + entry + sep
    1870                 rows.append(s)
    1871                
    1872             # Put brackets around in a single string
    1873             tmp = []
    1874             for row in rows:
    1875                 tmp.append(str(row))
    1876 
    1877             s = " \\\\\n".join(tmp)
    1878             format = 'r'*len(row_divs)
    1879             return "\\left" + matrix_delimiters[0] + "\\begin{array}{%s}\n"%format + s + "\n\\end{array}\\right" + matrix_delimiters[1]
    1880 
    1881         # not in EMBEDDED_MODE, or in EMBEDDED_MODE with just a single
    1882         # block: construct one large array, using \hline and vertical
     1853        # construct one large array, using \hline and vertical
    18831854        # bars | in the array descriptor to indicate subdivisions.
    18841855        for r from 0 <= r < nr:
    18851856            if r in row_divs:
  • sage/misc/html.py

    diff --git a/sage/misc/html.py b/sage/misc/html.py
    a b  
    2424    Do the following:
    2525    \begin{verbatim}
    2626       * Replace all $ text $'s by
    27          <span class='math'> text </span>
     27         <script type="math/tex"> text </script>
    2828       * Replace all $$ text $$'s by
    29          <div class='math'> text </div>
     29         <script type="math/tex; mode=display"> text </script>
    3030       * Replace all \$'s by $'s.  Note that in
    3131         the above two cases nothing is done if the $
    3232         is preceeded by a backslash.
    3333       * Replace all \[ text \]'s by
    34          <div class='math'> text </div>
     34         <script type="math/tex; mode=display"> text </script>
    3535    \end{verbatim}
    3636
    3737    EXAMPLES:
    3838        sage: sage.misc.html.math_parse('This is $2+2$.')
    39         'This is <span class="math">2+2</span>.'
     39        'This is <script type="math/tex">2+2</script>.'
    4040        sage: sage.misc.html.math_parse('This is $$2+2$$.')
    41         'This is <div class="math">2+2</div>.'
     41        'This is <script type="math/tex; mode=display">2+2</script>.'
    4242        sage: sage.misc.html.math_parse('This is \\[2+2\\].')
    43         'This is <div class="math">2+2</div>.'
     43        'This is <script type="math/tex; mode=display">2+2</script>.'
    4444        sage: sage.misc.html.math_parse(r'This is \[2+2\].')
    45         'This is <div class="math">2+2</div>.'
     45        'This is <script type="math/tex; mode=display">2+2</script>.'
    4646
    4747    TESTS:
    4848        sage: sage.misc.html.math_parse(r'This \$\$is $2+2$.')
    49         'This $$is <span class="math">2+2</span>.'   
     49        'This $$is <script type="math/tex">2+2</script>.'
    5050    """
    5151    # first replace \\[ and \\] by <div class="math"> and </div>, respectively.
    5252    while True:
     
    5454        if i == -1:
    5555            break
    5656        else:
    57             s = s[:i] + '<div class="math">' + s[i+2:]
     57            s = s[:i] + '<script type="math/tex; mode=display">' + s[i+2:]
    5858            j = s.find('\\]')
    5959            if j == -1:  # missing right-hand delimiter, so add one
    60                 s = s + '</div>'
     60                s = s + '</script>'
    6161            else:
    62                 s = s[:j] + '</div>' + s[j+2:]
     62                s = s[:j] + '</script>' + s[j+2:]
    6363   
    6464    # Below t always has the "parsed so far" version of s, and s is
    6565    # just the part of the original input s that hasn't been parsed.
     
    7777            s = s[i+1:]
    7878            continue
    7979        elif i+1 < len(s) and s[i+1] == '$':
    80             # Found a math environment. Double dollar sign so div mode.
    81             typ = 'div'
     80            # Found a math environment. Double dollar sign so display mode.
     81            disp = '; mode=display'
    8282        else:
    83             # Found math environment. Single dollar sign so span mode.
    84             typ = 'span'
     83            # Found math environment. Single dollar sign so default mode.
     84            disp = ''
    8585
    86         # Now find the matching $ sign and form the span or div.
    87         j = s[i+2:].find('$')
    88         if j == -1:
    89             j = len(s)
    90             s += '$'
    91             if typ == 'div':
     86        # Now find the matching $ sign and form the html string.
     87
     88        if len(disp) > 0:
     89            j = s[i+2:].find('$$')
     90            if j == -1:
     91                j = len(s)
    9292                s += '$$'
    93         else:
    94             j += i + 2
    95         if typ == 'div':
     93            else:
     94                j += i + 2
    9695            txt = s[i+2:j]
    9796        else:
     97            j = s[i+2:].find('$')
     98            if j == -1:
     99                j = len(s)
     100                s += '$'
     101            else:
     102                j += i + 2
    98103            txt = s[i+1:j]
    99         t += s[:i] + '<%s class="math">%s</%s>'%(typ,
    100                       ' '.join(txt.splitlines()), typ)
     104
     105        t += s[:i] + '<script type="math/tex%s">%s</script>'%(disp,
     106                      ' '.join(txt.splitlines()))
    101107        s = s[j+1:]
    102         if typ == 'div':
     108        if len(disp) > 0:
    103109            s = s[1:]
    104110    return t
    105111
     
    160166            if j == -1:
    161167                 t += s
    162168                 break
    163             t += s[:i] + '<span class="math">%s</span>'%\
     169            t += s[:i] + '<script type="math/tex">%s</script>'%\
    164170                     latex(sage_eval(s[6+i:j], locals=locals))
    165171            s = s[j+7:]
    166172        print "<html><font color='black'>%s</font></html>"%t
     
    188194            <table class="table_form">
    189195            <tbody>
    190196            <tr class ="row-a">
    191             <td><span class="math">0</span></td>
    192             <td><span class="math">0</span></td>
    193             <td><span class="math">\mathrm{True}</span></td>
     197            <td><script type="math/tex">0</script></td>
     198            <td><script type="math/tex">0</script></td>
     199            <td><script type="math/tex">\mathrm{True}</script></td>
    194200            </tr>
    195201            <tr class ="row-b">
    196             <td><span class="math">0</span></td>
    197             <td><span class="math">1</span></td>
    198             <td><span class="math">\mathrm{False}</span></td>
     202            <td><script type="math/tex">0</script></td>
     203            <td><script type="math/tex">1</script></td>
     204            <td><script type="math/tex">\mathrm{False}</script></td>
    199205            </tr>
    200206            <tr class ="row-a">
    201             <td><span class="math">1</span></td>
    202             <td><span class="math">0</span></td>
    203             <td><span class="math">\mathrm{False}</span></td>
     207            <td><script type="math/tex">1</script></td>
     208            <td><script type="math/tex">0</script></td>
     209            <td><script type="math/tex">\mathrm{False}</script></td>
    204210            </tr>
    205211            <tr class ="row-b">
    206             <td><span class="math">1</span></td>
    207             <td><span class="math">1</span></td>
    208             <td><span class="math">\mathrm{True}</span></td>
     212            <td><script type="math/tex">1</script></td>
     213            <td><script type="math/tex">1</script></td>
     214            <td><script type="math/tex">\mathrm{True}</script></td>
    209215            </tr>
    210216            </tbody>
    211217            </table>
     
    218224            <table class="table_form">
    219225            <tbody>
    220226            <tr>
    221             <th>Functions <span class="math">f(x)</span></th>
     227            <th>Functions <script type="math/tex">f(x)</script></th>
    222228            </tr>
    223229            <tr class ="row-a">
    224             <td><span class="math">\sin\left(x\right)</span></td>
     230            <td><script type="math/tex">\sin\left(x\right)</script></td>
    225231            </tr>
    226232            <tr class ="row-b">
    227             <td><span class="math">\cos\left(x\right)</span></td>
     233            <td><script type="math/tex">\cos\left(x\right)</script></td>
    228234            </tr>
    229235            </tbody>
    230236            </table>
     
    237243            <table class="table_form">
    238244            <tbody>
    239245            <tr>
    240             <th><span class="math">x</span></th>
    241             <th><span class="math">\sin(x)</span></th>
     246            <th><script type="math/tex">x</script></th>
     247            <th><script type="math/tex">\sin(x)</script></th>
    242248            </tr>
    243249            <tr class ="row-a">
    244             <td><span class="math">0</span></td>
    245             <td><span class="math">0.00</span></td>
     250            <td><script type="math/tex">0</script></td>
     251            <td><script type="math/tex">0.00</script></td>
    246252            </tr>
    247253            <tr class ="row-b">
    248             <td><span class="math">1</span></td>
    249             <td><span class="math">0.84</span></td>
     254            <td><script type="math/tex">1</script></td>
     255            <td><script type="math/tex">0.84</script></td>
    250256            </tr>
    251257            <tr class ="row-a">
    252             <td><span class="math">2</span></td>
    253             <td><span class="math">0.91</span></td>
     258            <td><script type="math/tex">2</script></td>
     259            <td><script type="math/tex">0.91</script></td>
    254260            </tr>
    255261            <tr class ="row-b">
    256             <td><span class="math">3</span></td>
    257             <td><span class="math">0.14</span></td>
     262            <td><script type="math/tex">3</script></td>
     263            <td><script type="math/tex">0.14</script></td>
    258264            </tr>
    259265            </tbody>
    260266            </table>
     
    298304        TESTS::
    299305       
    300306            sage: html._table_columns(["a $x^2$",1, sin(x)])
    301             <td>a <span class="math">x^2</span></td>
    302             <td><span class="math">1</span></td>
    303             <td><span class="math">\sin\left(x\right)</span></td>
     307            <td>a <script type="math/tex">x^2</script></td>
     308            <td><script type="math/tex">1</script></td>
     309            <td><script type="math/tex">\sin\left(x\right)</script></td>
    304310            sage: html._table_columns("a", header=True)
    305311            <th>a</th>
    306312        """       
     
    318324            elif isinstance(row[column], str):
    319325                print column_tag % math_parse(row[column])
    320326            else:
    321                 print column_tag % ('<span class="math">'
     327                print column_tag % ('<script type="math/tex">'
    322328                                    + latex(row[column])
    323                                     + '</span>')
     329                                    + '</script>')
    324330
    325331    def iframe(self, url, height=400, width=800):
    326332        r"""
  • sage/misc/latex.py

    diff --git a/sage/misc/latex.py b/sage/misc/latex.py
    a b  
    463463        self._option["preamble"] = ""
    464464        self._option["engine"] = "latex"
    465465        self._option["engine_name"] = "LaTeX"
    466         self._option["jsmath_avoid"] = []
     466        self._option["mathjax_avoid"] = []
    467467
    468468_Latex_prefs = _Latex_prefs_object()
    469469
     
    941941        """
    942942        if t is None:
    943943            return _Latex_prefs._option["blackboard_bold"]
    944         from latex_macros import sage_latex_macros, sage_jsmath_macros, sage_configurable_latex_macros, convert_latex_macro_to_jsmath
     944        from latex_macros import sage_latex_macros, sage_mathjax_macros, sage_configurable_latex_macros, convert_latex_macro_to_mathjax
    945945        global sage_latex_macros
    946         global sage_jsmath_macros
     946        global sage_mathjax_macros
    947947        old = _Latex_prefs._option["blackboard_bold"]
    948948        _Latex_prefs._option["blackboard_bold"] = bool(t)
    949949        if bool(old) != bool(t):
     
    959959            sage_configurable_latex_macros.remove(old_macro)
    960960            sage_latex_macros.append(macro)
    961961            sage_configurable_latex_macros.append(macro)
    962             sage_jsmath_macros.remove(convert_latex_macro_to_jsmath(old_macro))
    963             sage_jsmath_macros.append(convert_latex_macro_to_jsmath(macro))
     962            sage_mathjax_macros.remove(convert_latex_macro_to_mathjax(old_macro))
     963            sage_mathjax_macros.append(convert_latex_macro_to_mathjax(macro))
    964964
    965965    def matrix_delimiters(self, left=None, right=None):
    966966        r"""nodetex
     
    11381138    def extra_macros(self, macros=None):
    11391139        r"""nodetex
    11401140        String containing extra LaTeX macros to use with %latex,
    1141         %html, and %jsmath.
     1141        %html, and %mathjax.
    11421142
    11431143        INPUT: ``macros`` - string
    11441144
     
    11631163    def add_macro(self, macro):
    11641164        r"""nodetex
    11651165        Append to the string of extra LaTeX macros, for use with
    1166         %latex, %html, and %jsmath.
     1166        %latex, %html, and %mathjax.
    11671167
    11681168        INPUT: ``macro`` - string
    11691169
     
    11831183    def extra_preamble(self, s=None):
    11841184        r"""nodetex
    11851185        String containing extra preamble to be used with %latex.
    1186         Anything in this string won't be processed by %jsmath.
     1186        Anything in this string won't be processed by %mathjax.
    11871187
    11881188        INPUT: ``s`` - string or ``None``
    11891189
     
    12171217        r"""nodetex
    12181218        Append to the string of extra LaTeX macros, for use with
    12191219        %latex.  Anything in this string won't be processed by
    1220         %jsmath.
     1220        %mathjax.
    12211221
    12221222        EXAMPLES::
    12231223
     
    12831283        if self.has_file(package_name+".sty"):
    12841284            self.add_to_preamble("\\usepackage{%s}\n"%package_name)
    12851285
    1286     def jsmath_avoid_list(self, L=None):
     1286    def mathjax_avoid_list(self, L=None):
    12871287        r"""nodetex
    1288         List of strings which signal that jsMath should not
     1288        List of strings which signal that MathJax should not
    12891289        be used when 'view'ing.
    12901290
    12911291        INPUT: ``L`` - list or ``None``
     
    12931293        If ``L`` is ``None``, then return the current list.
    12941294        Otherwise, set it to ``L``.  If you want to *append* to the
    12951295        current list instead of replacing it, use
    1296         :meth:`latex.add_to_jsmath_avoid_list <Latex.add_to_jsmath_avoid_list>`.
     1296        :meth:`latex.add_to_mathjax_avoid_list <Latex.add_to_mathjax_avoid_list>`.
    12971297
    12981298        EXAMPLES::
    12991299
    1300             sage: latex.jsmath_avoid_list(["\\mathsf", "pspicture"])
    1301             sage: latex.jsmath_avoid_list()  # display current setting
     1300            sage: latex.mathjax_avoid_list(["\\mathsf", "pspicture"])
     1301            sage: latex.mathjax_avoid_list()  # display current setting
    13021302            ['\\mathsf', 'pspicture']
    1303             sage: latex.jsmath_avoid_list([])  # reset to default
    1304             sage: latex.jsmath_avoid_list()
     1303            sage: latex.mathjax_avoid_list([])  # reset to default
     1304            sage: latex.mathjax_avoid_list()
    13051305            []
    13061306        """
    13071307        if L is None:
    1308             return _Latex_prefs._option['jsmath_avoid']
     1308            return _Latex_prefs._option['mathjax_avoid']
    13091309        else:
    1310             _Latex_prefs._option['jsmath_avoid'] = L
    1311 
    1312     def add_to_jsmath_avoid_list(self, s):
     1310            _Latex_prefs._option['mathjax_avoid'] = L
     1311
     1312    def add_to_mathjax_avoid_list(self, s):
    13131313        r"""nodetex
    1314         Add to the list of strings which signal that jsMath should not
     1314        Add to the list of strings which signal that MathJax should not
    13151315        be used when 'view'ing.
    13161316
    1317         INPUT: ``s`` - string -- add ``s`` to the list of 'jsMath avoid' strings
     1317        INPUT: ``s`` - string -- add ``s`` to the list of 'MathJax avoid' strings
    13181318
    13191319        If you want to replace the current list instead of adding to
    1320         it, use :meth:`latex.jsmath_avoid_list <Latex.jsmath_avoid_list>`.
     1320        it, use :meth:`latex.mathjax_avoid_list <Latex.mathjax_avoid_list>`.
    13211321
    13221322        EXAMPLES::
    13231323
    1324             sage: latex.add_to_jsmath_avoid_list("\\mathsf")
    1325             sage: latex.jsmath_avoid_list()  # display current setting
     1324            sage: latex.add_to_mathjax_avoid_list("\\mathsf")
     1325            sage: latex.mathjax_avoid_list()  # display current setting
    13261326            ['\\mathsf']
    1327             sage: latex.add_to_jsmath_avoid_list("tkz-graph")
    1328             sage: latex.jsmath_avoid_list()  # display current setting
     1327            sage: latex.add_to_mathjax_avoid_list("tkz-graph")
     1328            sage: latex.mathjax_avoid_list()  # display current setting
    13291329            ['\\mathsf', 'tkz-graph']
    1330             sage: latex.jsmath_avoid_list([])  # reset to default
    1331             sage: latex.jsmath_avoid_list()
     1330            sage: latex.mathjax_avoid_list([])  # reset to default
     1331            sage: latex.mathjax_avoid_list()
    13321332            []
    13331333        """
    1334         current = latex.jsmath_avoid_list()
     1334        current = latex.mathjax_avoid_list()
    13351335        if s not in current:
    1336             _Latex_prefs._option['jsmath_avoid'].append(s)
     1336            _Latex_prefs._option['mathjax_avoid'].append(s)
    13371337
    13381338    def pdflatex(self, t = None):  # this is deprecated since 4.3.3
    13391339        """
     
    15471547
    15481548    return s
    15491549
    1550 class JSMathExpr:
     1550class MathJaxExpr:
    15511551    """
    1552     An arbitrary JSMath expression that can be nicely concatenated.
     1552    An arbitrary MathJax expression that can be nicely concatenated.
    15531553
    15541554    EXAMPLES::
    15551555
    1556         sage: from sage.misc.latex import JSMathExpr
    1557         sage: JSMathExpr("a^{2}") + JSMathExpr("x^{-1}")
     1556        sage: from sage.misc.latex import MathJaxExpr
     1557        sage: MathJaxExpr("a^{2}") + MathJaxExpr("x^{-1}")
    15581558        a^{2}x^{-1}
    15591559    """
    15601560    def __init__(self, y):
    15611561        """
    1562         Initialize a JSMath expression.
     1562        Initialize a MathJax expression.
    15631563
    15641564        INPUT:
    15651565
     
    15691569
    15701570        EXAMPLES::
    15711571
    1572             sage: from sage.misc.latex import JSMathExpr
    1573             sage: js = JSMathExpr(3); js  # indirect doctest
     1572            sage: from sage.misc.latex import MathJaxExpr
     1573            sage: jax = MathJaxExpr(3); jax  # indirect doctest
    15741574            3
    15751575        """
    15761576        self.__y = y
     
    15811581
    15821582        EXAMPLES::
    15831583
    1584             sage: from sage.misc.latex import JSMathExpr
    1585             sage: js = JSMathExpr('3')
    1586             sage: js.__repr__()
     1584            sage: from sage.misc.latex import MathJaxExpr
     1585            sage: jax = MathJaxExpr('3')
     1586            sage: jax.__repr__()
    15871587            '3'
    15881588        """
    15891589        return str(self.__y)
    15901590
    15911591    def __add__(self, y):
    15921592        """
    1593         'Add' JSMathExpr ``self`` to ``y``.  This concatenates them
     1593        'Add' MathJaxExpr ``self`` to ``y``.  This concatenates them
    15941594        (assuming that they're strings).
    15951595
    15961596        EXAMPLES::
    15971597
    1598             sage: from sage.misc.latex import JSMathExpr
    1599             sage: j3 = JSMathExpr('3')
    1600             sage: jx = JSMathExpr('x')
     1598            sage: from sage.misc.latex import MathJaxExpr
     1599            sage: j3 = MathJaxExpr('3')
     1600            sage: jx = MathJaxExpr('x')
    16011601            sage: j3 + jx
    16021602            3x
    16031603        """
    1604         return JSMathExpr(self.__y + y)
     1604        return MathJaxExpr(self.__y + y)
    16051605
    16061606    def __radd__(self, y):
    16071607        """
    1608         'Add' JSMathExpr ``y`` to ``self``.  This concatenates them
     1608        'Add' MathJaxExpr ``y`` to ``self``.  This concatenates them
    16091609        (assuming that they're strings).
    16101610
    16111611        EXAMPLES::
    16121612
    1613             sage: from sage.misc.latex import JSMathExpr
    1614             sage: j3 = JSMathExpr('3')
    1615             sage: jx = JSMathExpr('x')
     1613            sage: from sage.misc.latex import MathJaxExpr
     1614            sage: j3 = MathJaxExpr('3')
     1615            sage: jx = MathJaxExpr('x')
    16161616            sage: j3.__radd__(jx)
    16171617            x3
    16181618        """
    1619         return JSMathExpr(y + self.__y)
    1620 
    1621 class JSMath:
     1619        return MathJaxExpr(y + self.__y)
     1620
     1621class MathJax:
    16221622    r"""
    1623     Render LaTeX input using JSMath.  This returns a :class:`JSMathExpr`.
     1623    Render LaTeX input using MathJax.  This returns a :class:`MathJaxExpr`.
    16241624
    16251625    EXAMPLES::
    16261626
    1627         sage: from sage.misc.latex import JSMath
    1628         sage: JSMath()(3)
    1629         <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</div></html>
    1630         sage: JSMath()(ZZ)
    1631         <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</div></html>
     1627        sage: from sage.misc.latex import MathJax
     1628        sage: MathJax()(3)
     1629        <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
     1630        sage: MathJax()(ZZ)
     1631        <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</script></html>
    16321632    """
    16331633
    16341634    def __call__(self, x):
    16351635        r"""
    1636         Render LaTeX input using JSMath.  This returns a :class:`JSMathExpr`.
     1636        Render LaTeX input using MathJax.  This returns a :class:`MathJaxExpr`.
    16371637
    16381638        INPUT:
    16391639
    16401640        - ``x`` - a Sage object
    16411641
    1642         OUTPUT: a JSMathExpr
     1642        OUTPUT: a MathJaxExpr
    16431643
    16441644        EXAMPLES::
    16451645
    1646             sage: from sage.misc.latex import JSMath
    1647             sage: JSMath()(3)
    1648             <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</div></html>
    1649             sage: str(JSMath().eval(ZZ[x], mode='display')) == str(JSMath()(ZZ[x]))
     1646            sage: from sage.misc.latex import MathJax
     1647            sage: MathJax()(3)
     1648            <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
     1649            sage: str(MathJax().eval(ZZ[x], mode='display')) == str(MathJax()(ZZ[x]))
    16501650            True
    16511651        """
    16521652        return self.eval(x)
    16531653
    16541654    def eval(self, x, globals=None, locals=None, mode='display'):
    16551655        r"""
    1656         Render LaTeX input using JSMath.  This returns a :class:`JSMathExpr`.
     1656        Render LaTeX input using MathJax.  This returns a :class:`MathJaxExpr`.
    16571657
    16581658        INPUT:
    16591659
     
    16671667        -  ``mode`` - string (optional, default 'display): 'display'
    16681668           for displaymath or 'inline' for inline math
    16691669
    1670         OUTPUT: a JSMathExpr
     1670        OUTPUT: a MathJaxExpr
    16711671
    16721672        EXAMPLES::
    16731673
    1674             sage: from sage.misc.latex import JSMath
    1675             sage: JSMath().eval(3, mode='display')
    1676             <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</div></html>
    1677             sage: JSMath().eval(3, mode='inline')
    1678             <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</span></html>
    1679             sage: JSMath().eval(type(3), mode='inline')
    1680             <html>...\verb|&lt;type|\phantom{x}\verb|'sage.rings.integer.Integer'&gt;|</span></html>
     1674            sage: from sage.misc.latex import MathJax
     1675            sage: MathJax().eval(3, mode='display')
     1676            <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
     1677            sage: MathJax().eval(3, mode='inline')
     1678            <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
     1679            sage: MathJax().eval(type(3), mode='inline')
     1680            <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < type 'sage.rings.integer.Integer' > }</script></html>
    16811681        """
    16821682        # If x is already a LaTeX expression, i.e. the output of latex(blah),
    16831683        # we will treat it as a string, so that we can see the code itself.
     
    16871687        x = latex(x)
    16881688        # ... and make it suitable for jsMath, which has issues with < and >.
    16891689        x = x.replace('<', '&lt;').replace('>', '&gt;')
    1690         # In jsMath:
    1691         #   inline math: <span class="math">...</span>
    1692         #   displaymath: <div class="math">...</div>
     1690        # In MathJax:
     1691        #   inline math: <script type="math/tex">...</script>
     1692        #   displaymath: <script type="math/tex">...</script>
    16931693        from sage.misc.latex_macros import sage_configurable_latex_macros
    1694         if 'display' == mode:
    1695             return JSMathExpr('<html><div class="math">'
    1696                               + ''.join(sage_configurable_latex_macros)
    1697                               + _Latex_prefs._option['macros']
    1698                               + '%s</div></html>'%x)
    1699         elif 'inline' == mode:
    1700             return JSMathExpr('<html><span class="math">'
    1701                               + ''.join(sage_configurable_latex_macros)
    1702                               + _Latex_prefs._option['macros']
    1703                               + '%s</span></html>'%x)
     1694        if mode == 'display':
     1695            modecode = '; mode=display'
     1696        elif mode == 'inline':
     1697            modecode = ''
    17041698        else:
    17051699            # what happened here?
    17061700            raise ValueError, "mode must be either 'display' or 'inline'"
    1707 
    1708 def jsmath(x, mode='display'):
    1709     r"""
    1710     Attempt to nicely render an arbitrary Sage object with jsMath typesetting.
    1711     Tries to call ._latex_() on x. If that fails, it will render a string
    1712     representation of x.
    1713 
    1714     .. warning::
    1715 
    1716         2009-04: This function is deprecated; use :func:`html`
    1717         instead: replace ``jsmath('MATH', mode='display')`` with
    1718         ``html('$$MATH$$')``, and replace ``jsmath('MATH',
    1719         mode='inline')`` with ``html('$MATH$')``.
    1720 
    1721     INPUT:
    1722         x -- the object to render
    1723         mode -- 'display' for displaymath or 'inline' for inline math
    1724 
    1725     OUTPUT:
    1726         A string of html that contains the LaTeX representation of x. In the
    1727         notebook this gets embedded into the cell.
    1728 
    1729     EXAMPLES::
    1730 
    1731         sage: from sage.misc.latex import jsmath
    1732         sage: f = maxima('1/(x^2+1)')
    1733         sage: g = f.integrate()
    1734         sage: jsmath(f)
    1735         doctest:1: DeprecationWarning: The jsmath function is deprecated.  Use html('$math$') for inline mode or html('$$math$$') for display mode.
    1736         <html><font color='black'><div class="math">{{1}\over{x^2+1}}</div></font></html>
    1737         sage: jsmath(g, 'inline')
    1738         <html><font color='black'><span class="math">\tan^{-1} x</span></font></html>
    1739         sage: jsmath('\int' + latex(f) + '\ dx=' + latex(g))
    1740         <html><font color='black'><div class="math">\int{{1}\over{x^2+1}}\ dx=\tan^{-1} x</div></font></html>
    1741 
    1742     AUTHORS:
    1743 
    1744     - William Stein (2006-10): general layout (2006-10)
    1745 
    1746     - Bobby Moretti (2006-10): improvements, comments, documentation
    1747     """
    1748     from sage.misc.misc import deprecation
    1749     from sage.misc.html import html
    1750     deprecation("The jsmath function is deprecated.  Use html('$math$') for inline mode or html('$$math$$') for display mode.")
    1751     if mode == 'display':
    1752         delimiter = '$$'
    1753     elif mode == 'inline':
    1754         delimiter = '$'
    1755     else:
    1756         raise ValueError, "mode must be either 'display' or 'inline'"
    1757     try:
    1758         # try to get a latex representation of the object
    1759         x = x._latex_()
    1760     except AttributeError:
    1761         # otherwise just get the string representation
    1762         x = str(x)
    1763     return html(delimiter + x + delimiter)
     1701        return MathJaxExpr('<html><script type="math/tex%s">'%modecode
     1702                         + ''.join(sage_configurable_latex_macros)
     1703                         + _Latex_prefs._option['macros']
     1704                         + '%s</script></html>'%x)
    17641705
    17651706def view(objects, title='SAGE', debug=False, sep='', tiny=False, pdflatex=None, engine=None, viewer = None, tightpage = None, mode='inline', **kwds):
    17661707    r"""nodetex
     
    18451786    each object by ``\\begin{page}$`` and ``$\\end{page}``.
    18461787
    18471788    If in notebook mode with ``viewer`` equal to ``None``, this
    1848     usually uses jsMath -- see the next paragraph for the exception --
     1789    usually uses MathJax -- see the next paragraph for the exception --
    18491790    to display the output in the notebook. Only the first argument,
    18501791    ``objects``, is relevant; the others are ignored. If ``objects``
    18511792    is a list, each object is printed on its own line.
    18521793
    1853     In the notebook, this *does* *not* use jsMath if the LaTeX code
     1794    In the notebook, this *does* *not* use MathJax if the LaTeX code
    18541795    for ``objects`` contains a string in
    1855     :meth:`latex.jsmath_avoid_list() <Latex.jsmath_avoid_list>`.  In
     1796    :meth:`latex.mathjax_avoid_list() <Latex.mathjax_avoid_list>`.  In
    18561797    this case, it creates and displays a png file.
    18571798
    18581799    EXAMPLES::
    18591800
    18601801        sage: sage.misc.latex.EMBEDDED_MODE = True
    18611802        sage: view(3)
    1862         <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</span></html>
     1803        <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
    18631804        sage: view(3, mode='display')
    1864         <html><div class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</div></html>
     1805        <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
    18651806        sage: sage.misc.latex.EMBEDDED_MODE = False
    18661807
    18671808    TESTS::
     
    18861827        s = _latex_file_(objects, title=title, sep=sep, tiny=tiny, debug=debug, **latex_options)
    18871828    # notebook
    18881829    if EMBEDDED_MODE and viewer is None:
    1889         jsMath_okay = True
    1890         for t in latex.jsmath_avoid_list():
     1830        MathJax_okay = True
     1831        for t in latex.mathjax_avoid_list():
    18911832            if s.find(t) != -1:
    1892                 jsMath_okay = False
    1893             if not jsMath_okay:
     1833                MathJax_okay = False
     1834            if not MathJax_okay:
    18941835                break
    1895         if jsMath_okay:
    1896             print JSMath().eval(objects, mode=mode)  # put comma at end of line?
     1836        if MathJax_okay:
     1837            print MathJax().eval(objects, mode=mode)  # put comma at end of line?
    18971838        else:
    18981839            if pdflatex is True:
    18991840                engine = "pdflatex"
     
    21102051        sage: TEMP = sys.displayhook
    21112052        sage: sys.displayhook = sage.misc.latex.pretty_print
    21122053        sage: sage.misc.latex.print_or_typeset(3)
    2113         <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}3</span></html>
     2054        <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}3</script></html>
    21142055        sage: sage.misc.latex.EMBEDDED_MODE=False
    21152056        sage: sys.displayhook = TEMP
    21162057    """
     
    21262067    objects, this returns their default representation.  For other
    21272068    objects, in the notebook, this calls the :func:`view` command,
    21282069    while from the command line, this produces an html string suitable
    2129     for processing by jsMath.
     2070    for processing by MathJax.
    21302071
    21312072    INPUT:
    21322073
     
    21392080
    21402081        sage: from sage.misc.latex import pretty_print
    21412082        sage: pretty_print(ZZ)  # indirect doctest
    2142         <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</span></html>
     2083        <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</script></html>
    21432084    """
    21442085    if object is None:
    21452086        return
     
    21552096        if EMBEDDED_MODE:
    21562097            view(object)
    21572098        else:
    2158             print JSMath().eval(object, mode='inline')
     2099            print MathJax().eval(object, mode='inline')
    21592100        return
    21602101
    21612102def pretty_print_default(enable=True):
    21622103    r"""
    21632104    Enable or disable default pretty printing. Pretty printing means
    2164     rendering things so that jsMath or some other latex-aware front end
     2105    rendering things so that MathJax or some other latex-aware front end
    21652106    can render real math.
    21662107
    21672108    INPUT:
     
    23992340the TeX package pgf installed, along with the LaTeX package tkz-graph.
    24002341Run 'latex.add_to_preamble("\\usepackage{tkz-graph}")', and try viewing
    24012342it again.  From the command line, this should pop open a nice window
    2402 with a picture of a graph.  In the notebook, you should get a jsMath
    2403 error.  Finally, run 'latex.add_to_jsmath_avoid_list("tikzpicture")'
     2343with a picture of a graph.  In the notebook, you should get a MathJax
     2344error.  Finally, run 'latex.add_to_mathjax_avoid_list("tikzpicture")'
    24042345and try again from the notebook -- you should get a nice picture.
    24052346
    24062347(LaTeX code taken from http://altermundus.com/pages/graph.html)
     
    24822423open a nice window with a picture of forces acting on a mass
    24832424on a pendulum. In the notebook, you should get an error.
    24842425Finally, run
    2485 'latex.add_to_jsmath_avoid_list("pspicture")' and try again
     2426'latex.add_to_mathjax_avoid_list("pspicture")' and try again
    24862427-- you should get a nice picture."""
    24872428
    24882429        def _latex_(self):
     
    25492490'latex.add_to_preamble("\\usepackage[graph,knot,poly,curve]{xypic}")',
    25502491and try viewing again -- it should work in the command line but not
    25512492from the notebook.  In the notebook, run
    2552 'latex.add_to_jsmath_avoid_list("xygraph")' and try again -- you
     2493'latex.add_to_mathjax_avoid_list("xygraph")' and try again -- you
    25532494should get a nice picture.
    25542495
    25552496(LaTeX code taken from the xypic manual)
     
    26132554'latex.add_to_preamble("\\usepackage[matrix,arrow,curve,cmtip]{xy}")',
    26142555and try viewing again -- it should work in the command line but not
    26152556from the notebook.  In the notebook, run
    2616 'latex.add_to_jsmath_avoid_list("xymatrix")' and try again -- you
     2557'latex.add_to_mathjax_avoid_list("xymatrix")' and try again -- you
    26172558should get a picture (a part of the diagram arising from a filtered
    26182559chain complex)."""
    26192560
  • sage/misc/latex_macros.py

    diff --git a/sage/misc/latex_macros.py b/sage/misc/latex_macros.py
    a b  
    99documentation. To add a macro, modify the list ``macros``, near the
    1010end of this file, and then run 'sage -b'. The entries in this list are
    1111used to produce ``sage_latex_macros``, a list of strings of the form
    12 '\\newcommand...', and ``sage_js_macros``, a list of strings of the
    13 form 'jsMath.Macro...'.  The LaTeX macros are produced using the
    14 ``_latex_`` method for each Sage object listed in ``macros``, and the
    15 jsMath macros are produced from the LaTeX macros.  The list of LaTeX
    16 macros is used in the file ``SAGE_ROOT/devel/sage/doc/common/conf.py``
    17 to add to the preambles of both the LaTeX file used to build the PDF
    18 version of the documentation and the LaTeX file used to build the HTML
    19 version.  The list of jsMath macros is used in the file
    20 ``sage/server/notebook/notebook.py`` to define jsMath macros for use
     12'\\newcommand...', and ``sage_mathjax_macros``, a list of strings
     13suitable for parsing by MathJax.  The LaTeX macros are produced using
     14the ``_latex_`` method for each Sage object listed in ``macros``, and
     15the MathJax macros are produced from the LaTeX macros.  The list of
     16LaTeX macros is used in the file
     17``SAGE_ROOT/devel/sage/doc/common/conf.py`` to add to the preambles of
     18both the LaTeX file used to build the PDF version of the documentation
     19and the LaTeX file used to build the HTML version.  The list of
     20MathJax macros is used in the file
     21``sage/server/notebook/notebook.py`` to define MathJax macros for use
    2122in the live documentation (and also in the notebook).
    2223
    2324Any macro defined here may be used in docstrings or in the tutorial
     
    101102        defn = defn.replace(str(x), "#" + str(count))
    102103    return newcommand + defn
    103104
    104 def convert_latex_macro_to_jsmath(macro):
     105def convert_latex_macro_to_mathjax(macro):
    105106    r"""
    106107    This converts a LaTeX macro definition (\newcommand...) to a
    107     jsMath macro definition (jsMath.Macro...).
     108    MathJax macro definition (MathJax.Macro...).
    108109
    109110    INPUT:
    110111
    111112    -  ``macro`` - LaTeX macro definition
    112113
    113114    See the web page
    114     http://www.math.union.edu/~dpvc/jsMath/authors/macros.html for a
    115     description of the format for jsMath macros.
     115    http://www.mathjax.org/docs/1.1/options/TeX.html for a
     116    description of the format for MathJax macros.
    116117
    117118    EXAMPLES::
    118119
    119         sage: from sage.misc.latex_macros import convert_latex_macro_to_jsmath
    120         sage: convert_latex_macro_to_jsmath('\\newcommand{\\ZZ}{\\Bold{Z}}')
    121         "jsMath.Macro('ZZ','\\\\Bold{Z}');"
    122         sage: convert_latex_macro_to_jsmath('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
    123         "jsMath.Macro('GF','\\\\Bold{F}_{#1}',1);"
     120        sage: from sage.misc.latex_macros import convert_latex_macro_to_mathjax
     121        sage: convert_latex_macro_to_mathjax('\\newcommand{\\ZZ}{\\Bold{Z}}')
     122        'ZZ: "\\Bold{Z}"'
     123        sage: convert_latex_macro_to_mathjax('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
     124        'GF: ["\\Bold{F}_{#1}",1]'
    124125    """
    125126    left_bracket = macro.find('[')
    126127    right_bracket = macro.find('[')
     
    134135    name = macro[start_name+1:end_name]
    135136    start_defn = macro.find('{', end_name)
    136137    end_defn = macro.rfind('}')
    137     defn = macro[start_defn+1: end_defn].replace('\\', '\\\\')
    138     if num_args > 0:
    139         args_str = "," + str(num_args)
     138    # TODO MATHJAX: this line in John's patch is defn = macro[start_defn+1: end_defn].replace('\\', '\\\\')
     139    defn = macro[start_defn+1: end_defn]
     140    if num_args == 0:
     141        return name + ': "' + defn + '"'
    140142    else:
    141         args_str = ""
    142     return "jsMath.Macro('" + name + "','" + defn + "'" + args_str + ");"
    143 
    144 def convert_latex_macro_to_jsmath_easy(macro):
    145     r"""
    146     This converts a LaTeX macro definition (\newcommand...) to a
    147     definition for jsMath's easy/load.js macro array.
    148 
    149     INPUT:
    150 
    151     -  ``macro`` - LaTeX macro definition
    152 
    153     EXAMPLES::
    154 
    155         sage: from sage.misc.latex_macros import convert_latex_macro_to_jsmath_easy
    156         sage: convert_latex_macro_to_jsmath_easy('\\newcommand{\\ZZ}{\\Bold{Z}}')
    157         "ZZ : '{\\\\Bold{Z}}'"
    158         sage: convert_latex_macro_to_jsmath_easy('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
    159         "GF : ['{\\\\Bold{F}_{#1}}', 1]"
    160     """
    161     left_bracket = macro.find('[')
    162     right_bracket = macro.find('[')
    163     if left_bracket >= 0:
    164         right_bracket = macro.find(']')
    165         num_args = macro[left_bracket+1:right_bracket]
    166     else:
    167         num_args = 0
    168     start_name = macro.find('{') + 1  # add one to go past the backslash
    169     end_name = macro.find('}')
    170     name = macro[start_name+1:end_name]
    171     start_defn = macro.find('{', end_name)
    172     end_defn = macro.rfind('}')
    173     defn = macro[start_defn+1: end_defn].replace('\\', '\\\\')
    174     if num_args > 0:
    175         args_str = "," + str(num_args)
    176         return name + " : ['{" + defn + "}', " + str(num_args) + ']'
    177     else:
    178         return name + " : '{" + defn + "}'"
     143        return name + ': ["' + defn + '",' + str(num_args) + ']'
    179144
    180145# To add a new macro for use in the Sage documentation, add a list or
    181146# tuple to the following list.  Each list (or tuple) should have the
     
    212177
    213178sage_latex_macros += sage_configurable_latex_macros
    214179
    215 # jsMath macro definitions as JavaScript, e.g., to include in HTML
     180# MathJax macro definitions as JavaScript, e.g., to include in HTML
    216181# script elements.
    217 sage_jsmath_macros = [convert_latex_macro_to_jsmath(m) for m in sage_latex_macros]
    218 
    219 # jsMath macro definitions for an easy/load.js file's "macros" array.
    220 sage_jsmath_macros_easy = [convert_latex_macro_to_jsmath_easy(m) for m in sage_latex_macros]
     182sage_mathjax_macros = [convert_latex_macro_to_mathjax(m) for m in sage_latex_macros]
  • sage/misc/sagedoc.py

    diff --git a/sage/misc/sagedoc.py b/sage/misc/sagedoc.py
    a b  
    3131
    3232# two kinds of substitutions: math, which should only be done on the
    3333# command line -- in the notebook, these should instead by taken care
    34 # of by jsMath -- and nonmath, which should be done always.
     34# of by MathJax -- and nonmath, which should be done always.
    3535math_substitutes = [ # don't forget leading backslash '\\'
    3636    ('\\to', '-->'),
    3737    ('\\leq', '<='),
     
    12501250    </script>
    12511251    <script type="text/javascript" src="%(static_path)s/jquery.js"></script>
    12521252    <script type="text/javascript" src="%(static_path)s/doctools.js"></script>
    1253     <script type="text/javascript" src="%(static_path)s/jsmath_sage.js"></script>
     1253    <script type="text/javascript" src="%(static_path)s/mathjax_sage.js"></script>
    12541254    <link rel="shortcut icon" href="%(static_path)s/favicon.ico" />
    12551255    <link rel="icon" href="%(static_path)s/sageicon.png" type="image/x-icon" />
    12561256  </head>
     
    13111311
    13121312        if not os.path.exists(path):
    13131313            raise OSError, """The document '%s' does not exist.  Please build it
    1314 with 'sage -docbuild %s html --jsmath' and try again.""" %(name, name)
     1314with 'sage -docbuild %s html --mathjax' and try again.""" %(name, name)
    13151315
    13161316        from sage.server.support import EMBEDDED_MODE
    13171317        if EMBEDDED_MODE: