LaTeXML...::MathML(3)
πΈ NAME πΈ
okay so bestie, this is the LaTeXML...::MathML(3) page from the User Contributed Perl Documentation, and it's all about LaTeXML::Post::MathML β the Post-Processing modules for converting math to MathML. This page is giving very niche Perl math fairy energy, and I'm obsessed. β¨
π¦ SYNOPSIS π¦
LaTeXML::Post::MathML is the abstract base class for the MathML Postprocessor. This base class ate, no cap. Then LaTeXML::Post::MathML::Presentation and LaTeXML::Post::MathML::Content do the actual converting: they turn XMath into either Presentation MathML or Content MathML, or they use that format as the principle branch for Parallel markup. (Yes, the page says "principle" β I'm not fixing it, I'm just reporting it π)
π DESCRIPTION π
The conversion is mostly a tree walk of the XMath expression. Appropriate handlers get selected and called depending on the operators and forms it encounters. The way this tree walk picks handlers is lowkey main character energy. You can define handlers on applications of operators, or on tokens; when a token is applied, its application handler takes precedence over its token handler.
π
DefMathML($key,$presentation,$content); π
This defines presentation and content handlers for $key. The $key is shaped like TYPE:ROLE:MEANING, where:
TYPEβ is one eitherTokenorApply(orHint?)ROLEβ is a grammatical role (on XMath tokens)MEANINGβ is the meaning attribute (on XMath tokens)
Any of these can be ? to match any role or meaning; matches of both are preferred, then match of meaning or role, or neither. Match vibes, fr fr.
The subroutine handlers for presentation and content are given by $presentation and $content, respectively. Either can be undef, in which case some other matching handler will be invoked.
For Token handlers, the arguments passed are the token node; for Apply handler, the arguments passed are the operator node and any arguments.
However, it looks like someTOKENhandlers are being defined to take$content,%attributesβ being the string content of the token, and the token's attributes! Bestie, I'm just reading the page. π
π Presentation Conversion Utilties π
$mmlpost->pmml_top($node,$style);β this is the top-level converter applied to anXMathnode. It establishes a local context for font, style, size, etc. It generally does the bulk of the work for a PresentationMathML'stranslateNode, although the latter wraps the actualm:mathelement around it. (styleis display or text).pmml($node),pmml_smaller($node),pmml_scriptsizsize($node)β converts theXMath$nodeto Presentation MathML. The latter two are used when the context calls for smaller (eg. fraction parts) or scriptsize (eg sub or superscript) size or style, so that the size encoded within$nodewill be properly accounted for.pmml_mi($node,%attributes),pmml_mn($node,%attributes),pmml_mo($node,%attributes)β these areTokenhandlers, to createm:mi,m:mnandm:moelements, respectively. When called as a handler, they will be supplied only with anXMathnode (typically anXMTok). For convenient reuse, these functions may also be called on a 'virtual' token: with$nodebeing a string (that would have been the text content of theXMTok), and the%attributesthat would have been the token's attributes.pmml_infix($op,@args),pmml_script($op,@args),pmml_bigop($op,@args)β these areApplyhandlers, for handling general infix, sub or superscript, or bigop (eg. summations) constructs. They are called with the operator token, followed by the arguments; all areXMathelements.pmml_row(@items)β this wraps anm:mrowaround the already converted@itemsif need; that is, if there is only a single item it is returned without them:mrow.pmml_unrow($pmml)β this perverse utility takes something that has already been converted to Presentation MathML. If the argument is anm:mrow, it returns a list of the mathml elements within that row, otherwise it returns a list containing the single element$pmml.pmml_parenthesize($item,$open,$close)β this utility parenthesizes the (already converted MathML)$itemwith the string delimiters$openand$close. These are converted to anm:mrowwithm:mofor the fences, unless theusemfencedswitch is set, in which casem:mfencedis used.pmml_punctuate($separators,@items)β this utility creates anm:mrowby interjecting the punctuation between suceessive items in the list of already converted@items. If there are more than one character in$separatorsthe first is used between the first pair, the next between the next pair; if the separators is exhausted, the last is repeated between remaining pairs.$separatorsdefaults to (repeated) comma.
π Content Conversion Utilties π
"$mmlpost-"cmml_top($node); >β okay yes, the page literally prints this signature like that, with the weird quote and the>at the end, and I am not touching it. It's the top-level converter applied to anXMathnode. It establishes a local context for font, style, size, etc (were it needed). It generally does the bulk of the work for a ContentMathML'stranslateNode, although the latter wraps the actualm:mathelement around it.cmml($node)β converts theXMath$nodeto Content MathML.cmml_leaf($token)β converts theXMathtoken to anm:ci,m:cnorm:csymbol, under appropriate circumstances.cmml_decoratedSymbol($item)β similar tocmml_leaf, but used when an operator is itself, apparently, an application. This converts$itemto Presentation MathML to use for the content of them:ci.cmml_not($arg)β construct the not of the argument$arg.cmml_synth_not($op,@args)β synthesize an operator by applyingm:notto another operator ($op) applied to its@args(XMathelements that will be converted to Content MathML). This is useful to define a handler for, eg.,c<not-approximately-equals>in terms ofc<m:approx>.cmml_synth_complement($op,@args)β synthesize an operator by applying a complementary operator ($op) to the reverse of its@args(XMathelements that will be converted to Content MathML). This is useful to define a handler for, eg.superset-of-or-equalsusingm:subset.cmml_or_compose($operators,@args)β synthesize an operator that stands for the"or"of several other operators (eg.c<less-than-or-similar-to-or-approximately-equals>) by composing it of them:orof applying each ofm:lessandm:approxto the arguments. The first operator is applied to the converted arguments, while the rest are applied tom:shareelements referring to the previous ones.cmml_share($node)β converts theXMath$nodeto Content MathML, after assuring that it has an id, so that it can be shared.cmml_shared($node)β generates am:shareelement referting to$node, which should have an id (such as after callingcmml_share). Yes, "referting" β the page said it, not me. π
π Math Processors, Generally. π
We should probably formalize the idea of a Math Processor as an abstract class, but let this description provide a starting overview. A MathProcessor follows the API of LaTeXML::Post processors, by handling process, which invokes processNode on all Math nodes; that latter inserts the result of either translateNode or translateParallel, applied to the XMath representation, into the Math node.
Parallel translation is done whenever additional MathProcessors have been specified, via the setParallel method; these are simply other MathProcessors following the same API. Periodt.
okay that's the whole page, bestie π«Ά. It's perl v5.42.3, dated 2024-02-26, and the manual is LaTeXML...::MathML(3). Mwah πβ¨
π¦ where this page comes from
- nixos 26.05: perl5.42.3-LaTeXML 0.8.8
- nixpkgs unstable: perl5.42.3-LaTeXML 0.8.8
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms