Ticket #6673: trac_6673-jsmath_macros_docs_v3.patch

File trac_6673-jsmath_macros_docs_v3.patch, 15.7 KB (added by mpatel, 12 years ago)

Updated template version. Added 'sage' theme. Apply only this patch.

  • MANIFEST.in

    # HG changeset patch
    # User Mitesh Patel <qed777@gmail.com>
    # Date 1249369289 25200
    # Node ID 1cefb2a87ca10e5779de9b4cfa2e6fecbd4a05d2
    # Parent  b0de49d82582aba203ce473f6e6e356f4773cafd
    #6673/docs: Custom jsMath settings and Sage theme with Sphinx 0.6.3
    
    diff --git a/MANIFEST.in b/MANIFEST.in
    a b include doc/en/bordeaux_2008/birch.png 
    3333include doc/en/bordeaux_2008/modpcurve.png
    3434recursive-include doc/en/reference/media *
    3535recursive-include doc/common/static *
     36recursive-include doc/common/themes *
  • doc/common/conf.py

    diff --git a/doc/common/conf.py b/doc/common/conf.py
    a b if 'SAGE_DOC_JSMATH' in os.environ: 
    1818    extensions.append('sphinx.ext.jsmath')
    1919else:
    2020    extensions.append('sphinx.ext.pngmath')
    21 jsmath_path = 'easy/load.js'
     21jsmath_path = 'jsmath_sage.js'
    2222
    2323# Add any paths that contain templates here, relative to this directory.
    2424templates_path = [os.path.join(SAGE_DOC, 'common/templates'), 'templates']
    default_role = 'math' 
    7676# output. They are ignored by default.
    7777#show_authors = False
    7878
    79 # The name of the Pygments (syntax highlighting) style to use.
     79# The name of the Pygments (syntax highlighting) style to use.  NOTE:
     80# This overrides a HTML theme's corresponding setting (see below).
    8081pygments_style = 'sphinx'
    8182
    8283
    8384# Options for HTML output
    8485# -----------------------
    8586
    86 # The style sheet to use for HTML and HTML Help pages. A file of that name
    87 # must exist either in Sphinx' static/ path, or in one of the custom paths
    88 # given in html_static_path.
    89 html_style = 'default.css'
     87# HTML theme (e.g., 'default', 'sphinxdoc').  We use a custom Sage
     88# theme to set a Pygments style, stylesheet, and insert jsMath macros.
     89html_theme = 'sage'
     90
     91# Theme options are theme-specific and customize the look and feel of
     92# a theme further.  For a list of options available for each theme,
     93# see the documentation.
     94html_theme_options = {}
     95
     96if 'SAGE_DOC_JSMATH' in os.environ:
     97    from sage.misc.latex_macros import sage_jsmath_macros_easy
     98    html_theme_options['jsmath_macros'] = sage_jsmath_macros_easy
     99
     100    from sage.misc.package import is_package_installed
     101    html_theme_options['jsmath_image_fonts'] = is_package_installed('jsmath-image-fonts')
     102
     103# Add any paths that contain custom themes here, relative to this directory.
     104html_theme_path = [os.path.join(SAGE_DOC, 'common/themes')]
     105
     106# HTML style sheet NOTE: This overrides a HTML theme's corresponding
     107# setting.
     108#html_style = 'default.css'
    90109
    91110# The name for this set of Sphinx documents.  If None, it defaults to
    92111# "<project> v<release> documentation".
    html_static_path = [os.path.join(SAGE_DO 
    113132# array.  We can override / overwrite selected files by putting them
    114133# in the remaining paths.
    115134if 'SAGE_DOC_JSMATH' in os.environ:
    116     jsmath_static = os.path.join(SAGE_ROOT, 'local/lib/python/site-packages/sagenb/data/javascript/jsmath/')
     135    jsmath_static = os.path.join(SAGE_ROOT, 'local/lib/python/site-packages/sagenb/data/jsmath/')
    117136    html_static_path.insert(0, jsmath_static)
    118137
    119138# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
  • layout.html

    diff --git a/doc/common/templates/layout.html b/doc/common/themes/sage/layout.html
    rename from doc/common/templates/layout.html
    rename to doc/common/themes/sage/layout.html
    old new  
    1 {% extends "!layout.html" %}
     1{% extends "basic/layout.html" %}
    22
    33{% block rootrellink %}
    4     <img src="{{ pathto('_static/sagelogo.png', 1) }}" style="vertical-align: middle" title="Sage Logo">
    5     {{ super() }}
     4  {% if docstitle.startswith('Sage Documentation') %}
     5    <a href="http://www.sagemath.org"><img src="{{ pathto('_static/sagelogo.png', 1) }}" style="vertical-align: middle" title="Sage Logo"></a>
     6  {% else %}
     7    {% if pathto(master_doc).endswith('.html') %}
     8      <a href="{{ '../' + pathto(master_doc) }}"><img src="{{ pathto('_static/sagelogo.png', 1) }}" style="vertical-align: middle" title="Sage Logo"></a>
     9    {% else %}
     10      <a href="{{ '../' + pathto(master_doc) + 'index.html' }}"><img src="{{ pathto('_static/sagelogo.png', 1) }}" style="vertical-align: middle" title="Sage Logo"></a>
     11    {% endif %}
     12  {% endif %}
     13  {{ super() }}
    614{% endblock %}
    715
    816{% block extrahead %}
  • new file doc/common/themes/sage/static/jsmath_sage.js_t

    diff --git a/doc/common/static/favicon.ico b/doc/common/themes/sage/static/favicon.ico
    rename from doc/common/static/favicon.ico
    rename to doc/common/themes/sage/static/favicon.ico
    diff --git a/doc/common/themes/sage/static/jsmath_sage.js_t b/doc/common/themes/sage/static/jsmath_sage.js_t
    new file mode 100644
    - +  
     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 **********************************************************************/
     19
     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)
     24jsMath.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
     31jsMath.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
     173jsMath.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
     191jsMath.Easy.find_root();
     192
     193jsMath.Easy.root = jsMath.Easy.root.replace(/\/$/,""); // trim trailing "/" if any
     194
     195document.write('<SCRIPT SRC="'+jsMath.Easy.root+'/jsMath-easy-load.js"><'+'/SCRIPT>');
  • new file doc/common/themes/sage/theme.conf

    diff --git a/doc/common/static/sageicon.png b/doc/common/themes/sage/static/sageicon.png
    rename from doc/common/static/sageicon.png
    rename to doc/common/themes/sage/static/sageicon.png
    diff --git a/doc/common/static/sagelogo.png b/doc/common/themes/sage/static/sagelogo.png
    rename from doc/common/static/sagelogo.png
    rename to doc/common/themes/sage/static/sagelogo.png
    diff --git a/doc/common/themes/sage/theme.conf b/doc/common/themes/sage/theme.conf
    new file mode 100644
    - +  
     1[theme]
     2inherit = default
     3stylesheet = default.css
     4pygments_style = sphinx
     5
     6[options]
     7# Custom Sage theme options
     8
     9# jsMath settings filled in by conf.py
     10jsmath_macros =
     11jsmath_image_fonts =
     12
     13# Sphinx default theme options
     14
     15#nosidebar = false
     16#rightsidebar = false
     17#stickysidebar = false
     18
     19#footerbgcolor    = #11303d
     20#footertextcolor  = #ffffff
     21#sidebarbgcolor   = #1c4e63
     22#sidebartextcolor = #ffffff
     23#sidebarlinkcolor = #98dbcc
     24#relbarbgcolor    = #133f52
     25#relbartextcolor  = #ffffff
     26#relbarlinkcolor  = #ffffff
     27#bgcolor          = #ffffff
     28#textcolor        = #000000
     29#headbgcolor      = #f2f2f2
     30#headtextcolor    = #20435c
     31#headlinkcolor    = #c60f0f
     32#linkcolor        = #355f7c
     33#codebgcolor      = #eeffcc
     34#codetextcolor    = #333333
     35
     36#bodyfont = sans-serif
     37#headfont = 'Trebuchet MS', sans-serif
  • sage/misc/latex_macros.py

    diff --git a/sage/misc/latex_macros.py b/sage/misc/latex_macros.py
    a b def convert_latex_macro_to_jsmath(macro) 
    118118
    119119        sage: from sage.misc.latex_macros import convert_latex_macro_to_jsmath
    120120        sage: convert_latex_macro_to_jsmath('\\newcommand{\\ZZ}{\\Bold{Z}}')
    121         "jsMath.Macro('ZZ','\\\\Bold{Z}')"
     121        "jsMath.Macro('ZZ','\\\\Bold{Z}');"
    122122        sage: convert_latex_macro_to_jsmath('\\newcommand{\\GF}[1]{\\Bold{F}_{#1}}')
    123         "jsMath.Macro('GF','\\\\Bold{F}_{#1}',1)"
     123        "jsMath.Macro('GF','\\\\Bold{F}_{#1}',1);"
    124124    """
    125125    left_bracket = macro.find('[')
    126126    right_bracket = macro.find('[')
    def convert_latex_macro_to_jsmath(macro) 
    139139        args_str = "," + str(num_args)
    140140    else:
    141141        args_str = ""
    142     return "jsMath.Macro('" + name + "','" + defn + "'" + args_str + ")"
     142    return "jsMath.Macro('" + name + "','" + defn + "'" + args_str + ");"
     143
     144def 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 + "}'"
    143179
    144180# To add a new macro for use in the Sage documentation, add a list or
    145181# tuple to the following list.  Each list (or tuple) should have the
    sage_configurable_latex_macros = ["\\new 
    176212
    177213sage_latex_macros += sage_configurable_latex_macros
    178214
     215# jsMath macro definitions as JavaScript, e.g., to include in HTML
     216# script elements.
    179217sage_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.
     220sage_jsmath_macros_easy = [convert_latex_macro_to_jsmath_easy(m) for m in sage_latex_macros]