Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#4714 closed defect (fixed)

use easy/load.js when loading jsmath in the notebook

Reported by: Jason Grout Owned by: Kelly Boothby
Priority: minor Milestone: sage-4.3
Component: notebook Keywords:
Cc: John Palmieri, Tim Dumol, William Stein Merged in: sagenb-0.4.6
Authors: Mitesh Patel Reviewers: William Stein
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Mitesh Patel)

The patch

consolidates jsMath setup in /javascript/jsmath.js. It depends on #6673.

Attachments (5)

trac_4714-minimal_doc.patch (8.1 KB) - added by Mitesh Patel 13 years ago.
Minimal approach for docs. Depends on #6614.
trac_4714-sagenb_jsmath_init.patch (38.1 KB) - added by Mitesh Patel 13 years ago.
Consolidate jsMath setup. Apply to sagenb repository. Apply only this patch.
trac_4714-sagenb_hard_code_macros.patch (1.5 KB) - added by Mitesh Patel 13 years ago.
Hard-code jsMath macros. Apply to sagenb repository.
trac_4714-sagenb_jsmath_init_v2.patch (38.6 KB) - added by Mitesh Patel 13 years ago.
Rebased. See the comment for the queue. Apply only this patch. sagenb repo.
trac_4714-sagenb_jsmath_init_v3.patch (38.6 KB) - added by Mitesh Patel 13 years ago.
Force jsMath to load always. This patch only. sagenb repo.

Download all attachments as: .zip

Change History (30)

comment:1 Changed 14 years ago by Mitesh Patel

Copied from jason:

Replying to mpatel:

A related issue: It would be nice to have just one <script> element load jsMath with all of Sage's customizations (extensions, plug-ins, macros, etc.) into regular, published, printed, and docbrowser worksheets, as well as "torn out" introspection windows and offline documentation. Maybe easy/load.js is the right place (see #4714), but I think notebook.py generates the macro list on-the-fly.

Davide (author of jsmath) sent these comments about the above paragraph:

Mpatel is right that jsMath/easy/load.js could be used for this. Rather than putting calls to jsMath.Setup.Script() or jsMath.Extention.Require() in-line in the document itself, these can be be put in the loadFiles array in easy/load.js. It is also possible to put the jsMath.Macro() calls into a file (say jsMath/local/sage.js), and add that file to the loadFiles array as well rather than put them in-line. Any sage-specific customization could go in local/sage.js as well. In the latest version of jsMath, there is even a macros array in easy/load.js for custom macros, so you would not even need an extra file for that. These features are, in fact, one of the important reasons for easy/load.js, so I hope you are able to take advantage of them.

comment:2 Changed 14 years ago by John Palmieri

Cc: John Palmieri added

comment:3 Changed 13 years ago by Mitesh Patel

A few *estions:

  • Should we patch the spkg's jsmath/easy/load.js?
  • Add jsmath/local/sage.js to its loadFiles array?
  • Re-generate this sage.js from the list in sage/misc/latex_macros.py during
    1. sage -docbuild, in doc/common/conf.py?
    2. sage -b?
    3. notebook startup?

comment:4 Changed 13 years ago by David Loeffler

Component: notebookdocumentation
Owner: changed from Kelly Boothby to tba

This is misfiled (should be under "documentation").

comment:5 Changed 13 years ago by Mitesh Patel

After #5799, we have two copies of the jsmath tree, one in doc/common/static and another in javascript_local. That is, one from sage-4.1.spkg and another from jsmath-3.6b.p1.spkg. Can we avoid this? Or should we maintain separate load.js files for the notebook and documentation?

comment:6 in reply to:  5 Changed 13 years ago by Mitesh Patel

Replying to mpatel:

After #5799, we have two copies of the jsmath tree, one in doc/common/static and another in javascript_local. That is, one from sage-4.1.spkg and another from jsmath-3.6b.p1.spkg. Can we avoid this? Or should we maintain separate load.js files for the notebook and documentation?

See #6614 for a potential resolution.

comment:7 Changed 13 years ago by Mitesh Patel

The latest patch at #6614 tells Sphinx to copy jsMath directly from javascript_local to doc/output/html/en/*/_static. In particular, it does this before it copies the files in doc/common/static. How about putting a custom easy/load.js there?

If we're not adding new doc macros frequently, we could just paste them from latex_macros.py. Or we might add an option to sage -docbuild to regenerate load.js on demand (cf. #6187). If we overwrite the file during every build, we may need to synchronize access from multiple Sphinx processes (cf. #6255).

(Note: Sphinx 0.6.2 supports HTML themes, including static templates. It's tempting to create a template static/easy/load.js_t. However, Sphinx does not process user templates in static's subdirectories.)

On the notebook: I believe we can move nearly all jsMath directives from notebook.py to a custom javascript_local/jsmath/easy/load.js that's overwritten on notebook start-up. Perhaps in twist.py?

I'd really like to get moving on this, provided there's agreement. Of course, we can split this into two tickets, [at least] one each for the docs and notebook. Thoughts?

Changed 13 years ago by Mitesh Patel

Attachment: trac_4714-minimal_doc.patch added

Minimal approach for docs. Depends on #6614.

comment:8 Changed 13 years ago by Mitesh Patel

This p(r)oof of concept, which depends on a patch at #6614,

  • Adds doc/common/static/jsmath_sage.js.
  • Sets jsmath_path=jsmath_sage.js in doc/common/conf.py.

The new static file is jsMath's "stock" easy/load.js plus all Sage-related customizations I could find, including extensions, macros, and a few other bits from notebook.py. I've also made changes below DO NOT MAKE CHANGES BELOW THIS (gasp!) to help the loader find jsMath from its new [relative] location.

I think this means we don't need to patch the spkg. Later, we may be able to use Sphinx 0.6.2's static templates to insert an updated macro list at build time (cf. #6586).

Perhaps we can do something similar for the notebook, e.g., in sage/server/notebook/templates.

comment:9 Changed 13 years ago by Mitesh Patel

Component: documentationnotebook
Owner: changed from tba to Kelly Boothby
Summary: use easy/load.js when loading jsmathuse easy/load.js when loading jsmath in the notebook

With major changes in afoot in the notebook at #6568, I've put the doc patch up for review at #6673 and made this ticket specific to the notebook.

comment:10 Changed 13 years ago by Mitesh Patel

See this comment (and the next one) at #6673 for a suggested path to "unification."

comment:11 Changed 13 years ago by Mitesh Patel

In sagenb.notebook.twist, we can use a cached sage.misc.latex_macros.sage_jsmath_macros_easy (cf. #6673's v3) and JSMATH_IMAGE_FONTS, plus a user's own macros, to serve a dynamic javascript/jsmath.js.

Changed 13 years ago by Mitesh Patel

Consolidate jsMath setup. Apply to sagenb repository. Apply only this patch.

comment:12 Changed 13 years ago by Mitesh Patel

Authors: Mitesh Patel
Status: newneeds_review

The patch trac_4714-sagenb_jsmath_init.patch consolidates jsMath setup in /javascript/jsmath.js. It depends on #6673.

The patch still hard-codes the sage.misc.latex_macros's macros. Still to do: Generate the macros from server/user settings and latex_macros's helper functions.

Changed 13 years ago by Mitesh Patel

Hard-code jsMath macros. Apply to sagenb repository.

comment:13 Changed 13 years ago by Mitesh Patel

I've reattached trac_4714-sagenb_hard_code_macros.patch, since my first try didn't work (server problems?).

comment:14 Changed 13 years ago by Mitesh Patel

Description: modified (diff)

Note: With Jinja2 (cf. #7269, #7249), we can instead use, e.g.,

    macros: {
       {{ jsmath_macros|join(',\n') }}
    },

in jsmath.js (cf. #6673).

comment:15 Changed 13 years ago by William Stein

This works: trac_4714-sagenb_hard_code_macros.patc

comment:16 Changed 13 years ago by Mitesh Patel

Milestone: sage-4.2.1sage-4.2

Reminder: Rebase vs. #7269.

comment:17 Changed 13 years ago by Minh Van Nguyen

Milestone: sage-4.2sage-4.3

comment:18 Changed 13 years ago by Mitesh Patel

Report Upstream: N/A
Status: needs_reviewneeds_work
Work issues: rebase

Changed 13 years ago by Mitesh Patel

Rebased. See the comment for the queue. Apply only this patch. sagenb repo.

comment:19 Changed 13 years ago by Mitesh Patel

Status: needs_workneeds_review

Rebased against this sequence:

trac_7390-sagenb_test_report_A.patch
trac_7390-sagenb_test_report_B_v2.patch
trac_7390-sagenb_test_report_referee.patch
trac_7402-pkg_resources.patch
trac_7428-publish_last_edited_v2.patch
trac_7444-search_after_publish.patch
trac_7376-search_by_username_v2.patch
trac_1321-sagenb_graphed.patch
sagenb_7483.patch
sagenb_7482.patch
sagenb-7495.patch
sagenb_3849.patch
trac_4714-sagenb_jsmath_init_v2.patch

comment:20 Changed 13 years ago by Mitesh Patel

Work issues: rebase

comment:21 Changed 13 years ago by Mitesh Patel

Cc: Tim Dumol William Stein added
Priority: majorminor

Changed 13 years ago by Mitesh Patel

Force jsMath to load always. This patch only. sagenb repo.

comment:22 Changed 13 years ago by Mitesh Patel

Description: modified (diff)

Version 3:

  • Disables jsMath's autoload plug-in. Otherwise, jsMath does not load itself and run in worksheets that initially do not contain expressions to typeset.

comment:23 Changed 13 years ago by William Stein

Status: needs_reviewpositive_review

Looks good to me.

comment:24 Changed 13 years ago by William Stein

Resolution: fixed
Status: positive_reviewclosed

I merged this patch into sagenb-0.4.6.

comment:25 Changed 13 years ago by Minh Van Nguyen

Merged in: sagenb-0.4.6
Reviewers: William Stein
Note: See TracTickets for help on using tickets.