Ticket #9774: trac_9774-mathjax-flask-notebook.patch

File trac_9774-mathjax-flask-notebook.patch, 11.4 KB (added by rbeezer, 9 years ago)
  • flask_version/base.py

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1308194098 25200
    # Node ID 73be77c19ca7d755c5c1f0e6401073d98b802e1b
    # Parent  fe1c57bfbb7632a03bc29d9186d57cd2b7b318cd
    #9774: flask notebook changes for MathJax incorporation
    
    diff -r fe1c57bfbb76 -r 73be77c19ca7 flask_version/base.py
    a b  
    8383
    8484#XXX: This should probably be made able to put in a "central" place
    8585#with all of the jsmath stuff rather than just a global variable here.
    86 from sagenb.misc.misc import is_package_installed
    87 jsmath_image_fonts = is_package_installed("jsmath-image-fonts")
     86# Image fonts are not needed with MathJax
     87# they should be in the same spkg as MathJax routines
     88# Commented out as part of conversion to Flask notebook
     89#
     90# from sagenb.misc.misc import is_package_installed
     91# jsmath_image_fonts = is_package_installed("jsmath-image-fonts")
    8892
    8993base = Module('flask_version.base')
    9094
     
    126130    response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
    127131    return response
    128132
    129 @base.route('/javascript/sage/jsmath.js')
     133@base.route('/javascript/sage/mathjax.js')
    130134def jsmath_js():
    131     from sagenb.misc.misc import jsmath_macros
    132     response = make_response(render_template('js/jsmath.js', jsmath_macros=jsmath_macros,
    133                                              jsmath_image_fonts=jsmath_image_fonts))
     135    from sagenb.misc.misc import mathjax_macros
     136    response = make_response(render_template('js/mathjax.js', theme_mathjax_macros=mathjax_macros))
    134137    response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
    135138    return response
    136139
  • sagenb/data/sage/html/notebook/base.html

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/data/sage/html/notebook/base.html
    a b  
    3535{% endif %}
    3636
    3737{% if JSMATH %}
    38 <!-- jsMath - typeset mathematics -->
    39 <script type="text/javascript" src="/javascript/sage/jsmath.js"></script>
     38<!-- MathJax - typeset mathematics -->
     39<script type="text/x-mathjax-config">
     40MathJax.Hub.Config({
     41  extensions: ["jsMath2jax.js"],
     42  styles: {
     43    ".MathJax .mo, .MathJax .mi": {
     44      color: "inherit ! important"
     45    }
     46  }
     47});
     48</script>
     49<!-- Remove http on /javascript/sage/mathjax.js when standalone mathJax -->
     50<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full,http://localhost:8000/javascript/sage/mathjax.js"></script>
    4051{% endif %}
    4152
    4253<!-- Sage3d - accelerated 3D graphics -->
  • sagenb/data/sage/html/notebook/specific_revision.html

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/data/sage/html/notebook/specific_revision.html
    a b  
    3030    {{ worksheet.html(do_print=true, publish=true) }}
    3131</div>
    3232{{ actions() }}
    33 <script type="text/javascript">
     33<!--<script type="text/javascript">
    3434  $(document).ready(function () {
    35     jsMath.Process();
     35    MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
    3636  });
    37 </script>
     37</script>-->
    3838{% endblock %}
  • sagenb/data/sage/html/notebook/worksheet_page.html

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/data/sage/html/notebook/worksheet_page.html
    a b  
    1515<div class="worksheet" id="worksheet">
    1616    {{ worksheet.html() }}
    1717    {% if do_print %}
    18     <script>
    19         jsMath.ProcessBeforeShowing();
    20     </script>
     18<!--    <script>
     19        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
     20    </script>-->
    2121    {% else %}
    2222    <script type="text/javascript">
    2323        cell_id_list = {{ worksheet.cell_id_list() }};
  • sagenb/data/sage/js/notebook_lib.js

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/data/sage/js/notebook_lib.js
    a b  
    234234    // Get the keyboard codes for our browser/os combination.
    235235    get_keyboard();
    236236
    237     // Attempt to render any jsmath in this page.
    238     jsmath_init();
    239 
    240237    // Parse the cell ID list.
    241238    cell_id_list = $.map(cell_id_list, function (id) {
    242239        // Reset each cell's introspection variables.
     
    318315}
    319316
    320317
    321 function jsmath_init() {
    322     /*
    323     Process all the jsmath in this page.
    324     */
    325     try {
    326         jsMath.Process();
    327     } catch (e) {}
    328 }
    329 
    330 
    331318function get_element(id) {
    332319    /*
    333320    Return the DOM element with the given id.  If no element has the
     
    11611148        introspect_div.html(text);
    11621149        if (contains_jsmath(text)) {
    11631150            try {
    1164                 jsMath.ProcessBeforeShowing(introspect_div.get(0));
     1151                MathJax.Hub.Queue(["Typeset",MathJax.Hub,introspect_div.get(0)]);
    11651152            } catch (e) {
    11661153                introspect_div.html(jsmath_font_msg + introspect_div.html());
    11671154            }
     
    20922079
    20932080    if (contains_jsmath(text)) {
    20942081        try {
    2095             jsMath.ProcessBeforeShowing(text_cell);
     2082            MathJax.Hub.Queue(["Typeset",MathJax.Hub,text_cell]);
    20962083        } catch (e) {
    20972084            text_cell.innerHTML = jsmath_font_msg + text_cell.innerHTML;
    20982085        }
     
    35793566    */
    35803567    // TODO: Use a RegExp.
    35813568    text = text.toLowerCase();
     3569    // Mathjax - match math/tex and math/tex; mode=display
    35823570    return (text.indexOf('class="math"') !== -1 ||
    3583             text.indexOf("class='math'") !== -1);
     3571            text.indexOf("class='math'") !== -1 ||
     3572            text.indexOf('type="math/tex') !== -1 ||
     3573            text.indexOf("type='math/tex") !== -1);
    35843574}
    35853575
    35863576
     
    36433633            cell_interact = get_element('cell-interact-' + id);
    36443634            cell_interact.innerHTML = new_interact_output;
    36453635            if (contains_jsmath(new_interact_output)) {
    3646                 jsMath.ProcessBeforeShowing(cell_interact);
     3636                MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_interact]);
    36473637            }
    36483638        }
    36493639
     
    36703660    // Call jsMath on the final output.
    36713661    if (stat === 'd' && contains_jsmath(output_text)) {
    36723662        try {
    3673             jsMath.ProcessBeforeShowing(cell_output);
     3663            MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_output]);
    36743664        } catch (e) {
    36753665            cell_output.innerHTML = jsmath_font_msg + cell_output.innerHTML;
    36763666            cell_output_nowrap.innerHTML = jsmath_font_msg +
     
    36943684        // function (i.e., interact.recompute) is actually called!
    36953685        if (contains_jsmath(output_text_wrapped)) {
    36963686            try {
    3697                 jsMath.ProcessBeforeShowing(cell_output);
     3687                MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_output]);
    36983688            } catch (e2) {
    36993689                // Do nothing.
    37003690            }
  • sagenb/misc/misc.py

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/misc/misc.py
    a b  
    181181# TODO: Get macros from server and user settings.
    182182try:
    183183    import sage.all
    184     from sage.misc.latex_macros import sage_jsmath_macros_easy
     184    from sage.misc.latex_macros import sage_mathjax_macros
    185185except ImportError:
    186 #    sage_jsmath_macros = []
    187     sage_jsmath_macros_easy = [
     186    sage_mathjax_macros = [
    188187        "ZZ : '{\\\\Bold{Z}}'",
    189188        "RR : '{\\\\Bold{R}}'",
    190189        "CC : '{\\\\Bold{C}}'",
     
    203202        "Bold : ['{\\\\mathbf{#1}}', 1]"
    204203        ]
    205204finally:
    206     jsmath_macros = ',\n'.join(sage_jsmath_macros_easy)
     205    mathjax_macros = ',\n'.join(sage_mathjax_macros)
    207206
    208207try:
    209208    from sage.misc.session import init as session_init
  • sagenb/misc/sphinxify.py

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/misc/sphinxify.py
    a b  
    9191        suffix = '.txt'
    9292    output_name = base_name + suffix
    9393
    94     # This is needed for jsMath to work.
     94    # This is needed for MathJax to work.
    9595    docstring = docstring.replace('\\\\', '\\')
    9696
    9797    filed = open(rst_name, 'w')
  • sagenb/notebook/cell.py

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/notebook/cell.py
    a b  
    1818import shutil
    1919from cgi import escape
    2020
    21 from jsmath import math_parse
     21from mathjax import math_parse
    2222from sagenb.misc.misc import (word_wrap, SAGE_DOC, strip_string_literals,
    2323                              set_restrictive_permissions, unicode_str,
    2424                              encoded_str)
     
    240240          cell for printing
    241241
    242242        - ``do_math_parse`` - a boolean (default: True); whether to
    243           process the contents for JSMath (see
    244           :func:`sagenb.notebook.jsmath.math_parse`)
     243          process the contents for MathJax (see
     244          :func:`sagenb.notebook.mathjax.math_parse`)
    245245
    246246        - ``editing`` - a boolean (default: False); whether to open an
    247247          editor for this cell
     
    17751775        # version of the output.
    17761776        if ncols == 0:
    17771777            t = re_script.sub('', t)
     1778        #  This is a temporary hack
     1779        #re_inline = re.compile('<script type="math/tex">(.*?)</script>')
     1780        #re_display = re.compile('<script type="math/tex; mode=display">(.*?)</script>')
     1781        #t = re_inline.sub('<span class="math">\1</span>', t)
     1782        #t = re_display.sub('<div class="math">\1</div>', t)
     1783        #t = t.replace('<script type="math/tex">(.*?)</script>', '<span class="math">\1</span>')
     1784        #t = t.replace('<script type="math/tex; mode=display">(.*?)</script>', '<div class="math">\1</div>')
     1785        ####t = t.replace('<script type="math/tex">', '<span class="math">')
     1786        ####t = t.replace('</script>', '</span>')
    17781787        return t
    17791788
    17801789
     
    20812090
    20822091        This is a hack and needs to be improved.  The problem is how
    20832092        to get the documentation HTML to display nicely between the
    2084         example cells.  The type setting (jsMath formatting) needs
     2093        example cells.  The MathJax formatting needs
    20852094        attention too.
    20862095
    20872096        TODO: Remove this hack (:meth:`doc_html`)
  • sagenb/notebook/tutorial.py

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/notebook/tutorial.py
    a b  
    139139"sage(...)" inside the input block.  This is planned.)
    140140
    141141\subsubsection{Typesetting Mathematics}
    142 SAGE \emph{includes} jsMath, which is an implementation of the TeX
     142SAGE \emph{includes} MathJax, which is an implementation of the TeX
    143143math layout engine in javascript.  If you use the show or view
    144144commands, they display a given Sage object typeset using jsmath.
    145145Moreover, if you put \code{\%jsmath} at the beginning of an input
  • sagenb/notebook/twist.py

    diff -r fe1c57bfbb76 -r 73be77c19ca7 sagenb/notebook/twist.py
    a b  
    5252
    5353from sagenb.misc.misc import (SAGE_DOC, DATA, SAGE_VERSION, walltime,
    5454                              tmp_filename, tmp_dir, is_package_installed,
    55                               jsmath_macros, encoded_str, unicode_str)
     55                              mathjax_macros, encoded_str, unicode_str)
    5656
    5757css_path             = os.path.join(DATA, "sage", "css")
    5858image_path           = os.path.join(DATA, "sage", "images")