WeBWorK: refactor LaTeX macros - #3147
Conversation
|
Something is wrong with this. I think it is because I left out changes that I thought had only to do with my last paragraph. I'm converting to draft until I work it out. |
4aebf28 to
3d490c9
Compare
|
OK, tested, working, and force pushed. I had uncommitted changes that mostly should come after this to eradicate |
|
Looking good. A few boo-boos coming from Claude Code. With those patched up (and a force-push) we should be good. Can you put code changes on one commit, and all the re-generated stuff onto a separate commit? Thanks. |
|
This is the right direction. Moving the macros out of every math block and into the project's PG macro file is a clear improvement, and the I checked the regeneration rather than assume it: running Two things in the four new lines of JavaScript, both of which I confirmed in a browser rather than reasoned about.
|
|
You must not have liked something about the MathJax introspection idea on #2761. Curious about what that was? |
|
Thanks, I will update this soon, maybe late tonight.
There are two items at this comment. And what is happening here in this PR is my understanding of the second item. That's the one I would call "MathJax introspection" since it looks into the active MathJax JSON. I went with that one simply because I understood that one first, before I grokked what option 1 was saying. But option 1 could work too. It plants the original macro definitions into the window's variables, separately from MathJax (but has MathJax do the planting). Should I switch? I don't mind switching if you have a preference. |
|
Thanks for the reply. No need to switch, its your call. Especially since this is contained to MathJax stuff. Just trying to stay in the know about what decisions we make any why. Carry on. |
3d490c9 to
9e6a07d
Compare
|
OK, force pushed. Ready to review again.
|
Before this change, PreTeXt produces PG problems where LaTeX macros are defined within the math block in which they are used. This may mean they are loaded repeatedly in an exercise. This adds clutter to the PG that PTX produces, but has been necessary for the embedded problems to use an author's macros (or
\amp) in a WW exercise. All because the WW exercise is loaded inside an iframe. Also the PG problem files can't really be used in a WW problem set because hardcopy production will fail (because of the duplicate macro definitions).The first change here is to stop writing LaTeX macro definitions in the .pg. Instead, for live embedding, the
pretext-webwork.jsextracts them from the ambient page'sMathJaxvariable and then inserts them in the iframe's srcdoc.And then what about the .pg files if they make their way onto an actual WW server? Well now the macros are written into the project's PG macros file, and all problems load that macro file. Custom LaTeX macros work in vanilla WeBWorK (both HTML and hardcopy rendering).
And then, most of the affected files here are the repo's webwork representations and pg files where LaTeX macros are now absent, and the project's PG macros file is included in the load.
Finally, for the three WW-using examples (showcase, minimal, and sample chapter) the PG macros file is updated to include the LaTeX macros. Since the macros are multiline expressions, I used perl's heredoc construction (
<<'EOF') which looks a little awkward. For WW HTML output, the macros are put into a hidden div at the start of rendering. For WW PDF hardcopy output, we only want them loaded once, even if a problem set uses lots of problems from this project. So there is a dummy\ptxmacroscommand defined. We check if this has already been defined before trying to define all the custom macros.Since the js is changed here, you will have to run
jsbuildwhen testing this.If this is approved, then 99% of the need for
$b-human-readableinextract-pg.xslis gone. And there can be a net cutting of 78 lines from that file. I could add that here as a second commit, or just wait and make a separate PR later.