Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#4714 closed defect (fixed)

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

Reported by: jason Owned by: boothby
Priority: minor Milestone: sage-4.3
Component: notebook Keywords:
Cc: jhpalmieri, timdumol, was 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 mpatel)

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 mpatel 12 years ago.
Minimal approach for docs. Depends on #6614.
trac_4714-sagenb_jsmath_init.patch (38.1 KB) - added by mpatel 11 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 mpatel 11 years ago.
Hard-code jsMath macros. Apply to sagenb repository.
trac_4714-sagenb_jsmath_init_v2.patch (38.6 KB) - added by mpatel 11 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 mpatel 11 years ago.
Force jsMath to load always. This patch only. sagenb repo.

Download all attachments as: .zip

Change History (30)

comment:1 Changed 12 years ago by mpatel

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 12 years ago by jhpalmieri

  • Cc jhpalmieri added

comment:3 Changed 12 years ago by mpatel

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 12 years ago by davidloeffler

  • Component changed from notebook to documentation
  • Owner changed from boothby to tba

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

comment:5 follow-up: Changed 12 years ago by 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?

comment:6 in reply to: ↑ 5 Changed 12 years ago by mpatel

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 12 years ago by mpatel

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 12 years ago by mpatel

Minimal approach for docs. Depends on #6614.

comment:8 Changed 12 years ago by mpatel

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 12 years ago by mpatel

  • Component changed from documentation to notebook
  • Owner changed from tba to boothby
  • Summary changed from use easy/load.js when loading jsmath to use 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 12 years ago by mpatel

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

comment:11 Changed 11 years ago by mpatel

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 11 years ago by mpatel

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

comment:12 Changed 11 years ago by mpatel

  • Authors set to Mitesh Patel
  • Status changed from new to needs_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 11 years ago by mpatel

Hard-code jsMath macros. Apply to sagenb repository.

comment:13 Changed 11 years ago by mpatel

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

comment:14 Changed 11 years ago by mpatel

  • 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 11 years ago by was

This works: trac_4714-sagenb_hard_code_macros.patc

comment:16 Changed 11 years ago by mpatel

  • Milestone changed from sage-4.2.1 to sage-4.2

Reminder: Rebase vs. #7269.

comment:17 Changed 11 years ago by mvngu

  • Milestone changed from sage-4.2 to sage-4.3

comment:18 Changed 11 years ago by mpatel

  • Report Upstream set to N/A
  • Status changed from needs_review to needs_work
  • Work issues set to rebase

Changed 11 years ago by mpatel

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

comment:19 Changed 11 years ago by mpatel

  • Status changed from needs_work to needs_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 11 years ago by mpatel

  • Work issues rebase deleted

comment:21 Changed 11 years ago by mpatel

  • Cc timdumol was added
  • Priority changed from major to minor

Changed 11 years ago by mpatel

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

comment:22 Changed 11 years ago by mpatel

  • 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 11 years ago by was

  • Status changed from needs_review to positive_review

Looks good to me.

comment:24 Changed 11 years ago by was

  • Resolution set to fixed
  • Status changed from positive_review to closed

I merged this patch into sagenb-0.4.6.

comment:25 Changed 11 years ago by mvngu

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