Refactor templates to convert <N, T, D> to <DOM> to reduce number of templates. - #1562
Draft
dpvc wants to merge 3 commits into
Draft
Refactor templates to convert <N, T, D> to <DOM> to reduce number of templates.#1562dpvc wants to merge 3 commits into
dpvc wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1562 +/- ##
===========================================
- Coverage 87.12% 86.50% -0.62%
===========================================
Files 392 392
Lines 89098 85308 -3790
Branches 5046 5040 -6
===========================================
- Hits 77628 73798 -3830
- Misses 11450 11510 +60
+ Partials 20 0 -20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dpvc
marked this pull request as draft
September 4, 2026 17:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on the idea of the
DOMtype introduced in #1554 in order to reduce the number of template variables used in the various classes that require information about the DOM nodes being used. In the past, we used<N, T, D>for this, but this PR changes that to use<DOM>, as in the various option types added in #1554, so something likeMathDocument<N, T, D>now becomesMathDocumetn<DOM>. To access theN,T, andDvalues, the class usesN<DOM>, TandD` instead. This helps clarify that the type refers to a DOM node type. This reduces the templates from three to just one in many cases.The biggest impact is in the
ts/output/commonfiles, where there were 12 template variables. By mergingN,T, andDintoDOM, and combing the five font-based template values into a singleCOMMON_FONT(orCHTML_FONTorSVG_FONT) type, those templates are cut in half, to only six. The other four are interdependent and I could don't find an away to combine them into a single type, but six is still better than 12. That reduces the need for/* prettier-ignore */statements, and shortens up the template declarations considerably. The cost is usingN<DOM>rather thanN, but as mentioned above, I think that actually helps clarify what these values are. But it also allow<N<DOM>, T<DOM>, D<DOM>>that was introduced in #1554 to be replaced by<DOM>, so that is a savings as well.In addition to removing
/* prettier-ignore */for the extensive template usage, I tried to remove/* prettier-ignore */in other cases that were just there for comments, so you will see some comment adjustments for that purpose. I also did some alignment adjustments in the comments that had gotten skewed due to earlier changes, so you might want to view this with white-space changes hidden.Some modules used explicit
<HTMLElement, Text, Document>template values; these are replaced by<HTML_DOM>whereHTML_DOMcomes fromts/types/dom/html.tsas part of the new typing system.There is really nothing else going on in this PR, so although there are a lot of files involved (anything that uses
MathItemorMathDocument, which is just about everything), the changes are really just in the templates.One issue to consider, however, is that this is a potentially breaking change to people using MathJax in Typescript projects, as something like
new TeX<HTMLElement, Text, Document>()will have to be changed tonew TeX<HTML_DOM>()andHTML_DOMwill need to be imported. But the newHTML_DOMshould make such things easier, especially for node use, wherenew TeX<LITE_DOM>with one import forLITE_DOMis easier than importingLiteElement,LiteText, andLiteDocumentfrom three separate files, and usingnew TeX<LiteElement, LiteText, LiteDocument>(). So I think this (along with the new typing mechanism) will be a welcome change for developers.