Add support for delimiters that are specific to a mathvariant and use it for mhchem arrows. (mathjax/MathJax#3486) #1424
+306
−211
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 adds support for fonts and font extensions to define delimiters that are specific to a mathvariant. This is needed for the
mhchemextension to handle some of its stretchy arrows without needing to use the PUA for them, which causes problems for speech generation.Resolves part of issue mathjax/MathJax#3486.
Details
This PR touches a large number of files, but many are because the
VariantDatatype now is dependent on theDelimiterDatatype, so has an additional template variable. That means all the Wrapper definitions need to have that template variable added, and that is a large number of files.The
mhchemextension now uses the standard arrow positions (e.g., U+2192) rather than PUA positions, so the test file formhchemneeded to be updated.The
xArrowmethod inAmsMethods.tsfile is modified to accept amathvariantin which the arrow is to be found.That is then used in the
mhchemextension to specify that the arrows are to be taken from the-mhchemvariant. The arrows are now in the usual Unicode positions rather than the PUA. The left-right harpoons use the newly proposed U+1F8D2 and U+1F8D3 positions.The CHTML font data now stores the variant as part of the delimiter usage data (so that it can create the proper CSS), and uses the variant in the calls that get delimiters and stretchy variants. The
mowrapper records the variant when a stretchy delimiter is used. Similarly, the SVG mo wrapper passes the variant when it stretches a delimiter.The main changes are on the
common/FontData.tsfile. Here, theVariantDatanow can include delimiters specific to the variant, and theDelimiterDatacan include a variant specification. A newVDelimiterMaptype is used to specify delimiters for variants, and theFontExtensionDatais extended to include that, which is now processed by the static and instanceaddExtension()functions.The
FontDataobject itself gets a newdefaultVariantDelimitersobject to hold any variant-specific delimiters, and these are now processed in theconstructor()function. ThecreateVariant()method now created avariant.delimsobject similar to thevariant.charsone that has a prototype chain that links delimiters in the same way the characters are links to fallback variants (so, for example,boldhasnormalas a fallback). Thenormaldelimiters use the originalthis.delimitersso that object is still the final fallback for all variants. Thevariant.linkedvalue is now an array consisting of the linked chars and delims objects rather than just he chars. ThedefineChars()method now takes this array into account.The
defineDelimiters()method now takes a variant name, and sets thedelim.vvalue for variants over thannormal. It now assigns the delimiters to the variants delimiter list (which will bethis.delimitersfornormalvariant), and processes linked variants in the same way thatvariant.charsare handled.The
getDelimiter()method now takes an optional variant name as an argument and looks up the delimiter from the variant. Again, note that thenormalvariant will havethis.delimitersas its delimiters, and all variants have the normal variants as the final fallback. So in most cases, the variant-specific list will be empty and will fall back on the normal list (this.delimiters), and this will operate exactly as before. The only change will be when there are variant-specific delimiters that will be found first.The
getSizeVariant(),getStretchVariant(), andgetStretchVariants()methods all now take an optional variant name and look up the delimiter from that variant.