-
Notifications
You must be signed in to change notification settings - Fork 220
WeBWorK: better handling of LaTeX macros in interactive exercises #2613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Since this came up before, and I'm looking this over again just now, I though I should explain better something that I wrote concisely above. We already write the author's LaTeX macros into the HTML like this: But when the page loads, that span has been changed by MathJax to this: In other words, the definitions of the macros are gone. The pretext-webwork.js has nowhere to look for them. So this explains the need for a redundant copy (in order to accomplish the goal here). |
|
I presume we will wait a bit on https://groups.google.com/g/mathjax-users/c/0aG9NmDAIgI/m/eqIbGkSOAAAJ I'll see progress. Holler when you are satisfied (or give up!). |
|
Got some help from Davide, and I can use the outer page's instance of MathJax to access an array containing all the math chunks. Can I presume the 0th chunk (earliest span.process-math on the page) will always be the one that loads macros? And will always be nonempty because it defines |
|
Great! That mathjax-users thread sounded very hopeful, so I'm glad that offers a way forward. I can't see any reason why the macros can't be first on the page, now or later. It'll come before any math in the masthead/title, no? Let's put extensive code comments in the XSL so nobody is later tempted to move these to a bad place. Also, let's put a short one-line HTML comment into every page right prior to the macros saying "these go first for WW" and try to make it so that any bad pre-/post- diff might see that comment migrating around. Or something like that. You've probably already thought this through. I saw that this must be some sort of JS Off-duty for much of the day - run with this? |
|
I poked around more in the giant MathJax object but I can't work out a better way to zero in on which math chunk has the macros. I could search the math chunks for strings like Except you are right that any math in the title will come earlier in the linearization of the page than where we currently place the macros. So here are two options:
|
|
Stand by. Off-list messaging with Davide have led to a better way. |
I know I am on standby. We could add a LaTeX comment with a magic string. There is one floating around that might be available for reuse... |
Before this commit, when a WW exercise uses a custom LaTeX macro, and when that exercise is going to be rendered live, we open each chunk of math with whatever custom LaTeX definitions are needed for that chunk of math. This is pretty inefficient, since you might be redefining macros over and over again in the same exercise. Also it clutters up the MathJax tool that gives a user the tex code that was used to generate that chunk of math.
This changes all that. The PG being used for rendering the live version of the exercise now has no latex macro definitions at all. Instead, all of the project's custom LaTeX macros are loaded into MathJax once at the start of the problem (which, I should remind everyone, is within an iframe and not subject to the MathJax happenings in the ambient page.)
To accomplish that, the LaTeX macros text is kept in a visually hidden place in the ambient page, so that javascript can grab it and insert it at the start of the problem. This needs to be a separate instance of writing the LaTeX macros into the ambient page from what is already there. Because what is already there gets ingestedby MathJax, and becomes something completely different in the DOM to how it was born.
I can't think of an alternate way to reach the objective, except maybe to put the latex macros into a data attribute instead of into an element. I'll make that change if it seems better.
Either way, the second copy of the latex macros text will only show up in the HTML if the project is using WeBWorK. So no unnecessary clutter for other projects.