Support providecommand in STACK MathJax output - #1853
Conversation
|
One broader motivation worth recording is that this offers a narrower alternative for the notation-only part of #993 and #1327. Those issues considered making STACK read course or category context, which raised valid concerns about caching, regrading and platform independence; #1327 therefore pointed towards gitsync-managed course variants. |
|
Thanks @adamant-pwn I'm going to need a little time to digest and consider this. Any comments @timhunt and @aharjula in the mean time? |
Summary
\providecommandsupport to STACK's Moodle MathJax output.\providecommand.Motivation
This lets a portable question carry its own fallback notation while allowing an earlier surrounding definition to win. For example, a question can contain
while a course defines
The same question then works with its own default in native LaTeX or an uncustomised STACK page, and adopts the course notation when the earlier definition is present. It does not need an attached script or site-wide MathJax configuration.
This provides the TeX-side foundation for the course-overridable semantic matrix and vector hooks discussed in #1848. It does not itself add those wrappers or change the HTML matrix-input widget; those remain separate follow-up work.
MathJax does not currently implement
\providecommand; the MathJax maintainer supplied the parser-level workaround used here in MathJax #3603.Implementation notes
The command reuses MathJax's existing
newcommandparser utilities and preserves an existing macro or delimiter definition. The Moodle integration handles both startup-time configuration and a running MathJax instance. If fragment content was typeset first, only STACK equations containing aprovidecommanderror are reprocessed. Ordinary STACK mathematics does not load the module.The minimal API client has no Moodle AMD loader, so its fixed MathJax 3 setup registers the same small command map directly. This is a separate commit so it can be reviewed independently.
The implementation uses MathJax internals, following the maintainer's proposed workaround, and therefore needs retesting when STACK changes supported MathJax versions. It can be removed when MathJax provides the command natively.
This PR only supplies the generic TeX primitive. It does not add course-aware logic to STACK and does not change STACK's ordinary HTML input widgets.
Verification
noErrorsfragment repair passed.