LaTeXM...ocument(3pm)
okay bestie, welcome to LaTeXM...ocument(3pm), straight out of User Contributed Perl Documentation π . This is your girl explaining the whole thing, no cap.
π NAME π
LaTeXML::Core::Document β represents an XML document under construction. π§β¨
β¨ DESCRIPTION β¨
So a LaTeXML::Core::Document is literally an XML document that LaTeXML is still building, and it also hands you the methods to build it. It extends LaTeXML::Common::Object. Slay. π
By the time this kicks in, LaTeXML has already digested the source material into a LaTeXML::Core::List (from a LaTeXML::Core::Stomach) made of LaTeXML::Core::Boxs, LaTeXML::Core::Whatsits and sublists. At this stage a document gets created, and it is responsible for absorbing the digested material. Generally, the LaTeXML::Core::Boxs and LaTeXML::Core::Lists create text nodes, while the LaTeXML::Core::Whatsits create XML document fragments, elements and attributes according to the defining LaTeXML::Core::Definition::Constructor. Periodt. π
Most document construction happens at a current insertion point where material gets added, and that point moves along with the inserted material. The LaTeXML::Common::Model β derived from various declarations and document type β gets consulted to determine whether an insertion is allowed and when elements may need to be automatically opened or closed to carry out a given insertion. For example, a subsection element will typically be closed automatically when someone tries to open a section element. It's giving document model realness. π¦
In these methods, $qname means an XML qualified name. These are tag names with a namespace prefix. The prefix should be one registered with the current Model, for use within the code. That prefix is not necessarily the same as the one used in any DTD, but it should be mapped to a Namespace URI that was registered for the DTD. iykyk π§
The arguments named $node are an XML::LibXML node.
The methods here are grouped into three sections: basic access to the document, insertion methods at the current insertion point, and the less commonly used, lower-level, document manipulation methods. Let's go π
π Accessors π
$doc = $document->getDocument;β returns theXML::LibXML::Documentcurrently being constructed.$doc = $document->getModel;β returns theLaTeXML::Common::Modelthat represents the document model used for this document.$node = $document->getNode;β returns the node at the current insertion point during construction. This node is considered still to beopen; any insertions will go into it (if possible). The node will be anXML::LibXML::Element,XML::LibXML::Textor, initially,XML::LibXML::Document.$node = $document->getElement;β returns the closest ancestor to the current insertion point that is an Element.$node = $document->getChildElement($node);β returns a list of the child elements, if any, of$node. (The signature says$node, the text says list β we just report the chaos π)@nodes = $document->getLastChildElement($node);β returns the last child element of$node, if it has one, elseundef.$node = $document->getFirstChildElement($node);β returns the first child element of$node, if it has one, elseundef.@nodes = $document->findnodes($xpath,$node);β returns a list of nodes matching the given$xpathexpression. The context node for$xpathis$node, if given, otherwise it is the document element.$node = $document->findnode($xpath,$node);β returns the first node matching the given$xpathexpression. The context node for$xpathis$node, if given, otherwise it is the document element.$node = $document->getNodeQName($node);β returns the qualified name (localname with namespace prefix) of the given$node. The namespace prefix mapping is the code mapping of the current document model.$boolean = $document->canContain($tag,$child);β returns whether an element$tagcan contain a child$child.$tagand$childcan be nodes, qualified names of nodes (prefix:localname), or one of a set of special symbols:#PCDATA,#Comment,#Documentor#ProcessingInstruction.$boolean = $document->canContainIndirect($tag,$child);β returns whether an element$tagcan contain a child$childeither directly, or after automatically opening one or more autoOpen-able elements.$boolean = $document->canContainSomehow($tag,$child);β returns whether an element$tagcan contain a child$childeither directly, or after automatically opening one or more autoOpen-able elements. (Yes, same vibe as above β the page says it twice, so we say it twice π)$boolean = $document->canHaveAttribute($tag,$attrib);β returns whether an element$tagcan have an attribute named$attrib.$boolean = $document->canAutoOpen($tag);β returns whether an element$tagis able to be automatically opened.$boolean = $document->canAutoClose($node);β returns whether the node$nodecan be automatically closed.
π οΈ Construction Methods π οΈ
These are the most common methods used for construction of documents. They generally operate by creating new material at the current insertion point. That point initially is just the document itself, but it moves along to follow any new insertions. These methods also adapt to the document model so as to automatically open or close elements when it is required for the pending insertion and allowed by the document model (See Tag). Not me being obsessed with the way the insertion point just moves along. Main character energy, fr fr. π₯
$xmldoc = $document->finalize;β finalizes the document by cleaning up various temporary attributes, and returns theXML::LibXML::Documentthat was constructed. Iconic cleanup moment β¨@nodes = $document->absorb($digested);β absorbs the$digestedobject into the document at the current insertion point according to its type. Various of the other methods are invoked as needed, and document nodes may be automatically opened or closed according to the document model. This method returns the nodes that were constructed. Heads up: the nodes may include children of other nodes, and nodes that may already have been removed from the document (SeefilterChildrenandfilterDeleted). Also, text insertions are often merged with existing text nodes; in such cases, the whole text node is included in the result. π«Ά$document->insertElement($qname,$content,%attributes);β shorthand for creating an element$qname(with given attributes), absorbing$contentfrom within that new node, and then closing it. The$contentmust be digested material, either a single box, or an array of boxes, which will be absorbed into the element. This method returns the newly created node, although it will no longer be the current insertion point.$document->insertMathToken($string,%attributes);β insert a math token (XMTok) containing the string$stringwith the given attributes. Useful attributes would bename,role,font. Returns the newly inserted node.$document->insertComment($text);β insert, and return, a comment with the given$textinto the current node.$document->insertPI($op,%attributes);β insert, and return, aProcessingInstructioninto the current node.$document->openText($text,$font);β open a text node in font$font, performing any required automatic opening and closing of intermediate nodes (including those needed for font changes) and inserting the string$textinto it.$document->openElement($qname,%attributes);β open an element named$qnameand with the given attributes. This will be inserted into the current node while performing any required automatic opening and closing of intermediate nodes. The new element is returned, and also becomes the current insertion point. An error (fatal if in"Strict"mode) is signalled if there is no allowed way to insert such an element into the current node. π¨$document->closeElement($qname);β close the closest open element named$qname, including any intermediate nodes that may be automatically closed. If that is not possible, signal an error. The closed node's parent becomes the current node. This method returns the closed node.$node = $document->isOpenable($qname);β check whether it is possible to open a$qnameelement at the current insertion point.$node = $document->isCloseable($qname);β check whether it is possible to close a$qnameelement, returning the node that would be closed if possible, otherwiseundef.$document->maybeCloseElement($qname);β close a$qnameelement, if it is possible to do so, returns the closed node if it was found, elseundef.$document->addAttribute($key=>$value);β add the given attribute to the node nearest to the current insertion point that is allowed to have it. This does not change the current insertion point.$document->closeToNode($node);β this method closes all children of$nodeuntil$nodebecomes the insertion point. Note that it closes any open nodes, not only autoCloseable ones. π
π§ Internal Insertion Methods π§
These are described as an aide to understanding the code; they rarely, if ever, should be used outside this module. ngl, they are lowkey the backstage crew. π«Ά
$document->setNode($node);β sets the current insertion point to be$node. This should be rarely used, if at all; the construction methods of document generally maintain the notion of insertion point automatically. This may be useful to allow insertion into a different part of the document, but you probably want to set the insertion point back to the previous node, afterwards.$string = $document->getInsertionContext($levels);β for debugging, return a string showing the context of the current insertion point; that is, the string of the nodes leading up to it. If$levelsis defined, show only that many nodes.$node = $document->find_insertion_point($qname);β this internal method is used to find the appropriate point, relative to the current insertion point, that an element with the specified$qnamecan be inserted. That position may require automatic opening or closing of elements, according to what is allowed by the document model.@nodes = getInsertionCandidates($node);β returns a list of elements where an arbitrary insertion might take place. Roughly this is a list starting with$node, followed by its parent and the parents siblings (in reverse order), followed by the grandparent and siblings (in reverse order).$node = $document->floatToElement($qname);β bestie, this one hunts for the nearest element at or before your current insertion point (see"getInsertionCandidates") that can accept an element named$qname; it moves the insertion point to that spot and returns the previous insertion point. Generally, after you do whatever you need at the new insertion point, you should call$document->setNode($node);to restore the insertion point. If no such point is found, the insertion point stays exactly where it was andundefis returned. π$node = $document->floatToAttribute($key);β same energy asfloatToElement, but it finds the nearest element that can accept the attribute$key. β¨$node = $document->openText_internal($text);β this is an internal method, used byopenText, and it assumes the insertion point has already been appropriately adjusted. Lowkey kitchen-only stuff. π«Ά$node = $document->openMathText_internal($text);β this internal method appends$textto the current insertion point, which is assumed to be a math node. It checks for math ligatures and carries out any combinations called for. Math girlies rise. π₯$node = $document->closeText_internal();β this internal method closes the current node, which should be a text node. It carries out any text ligatures on the content. π$node = $document->closeNode_internal($node);β this internal method closes any open text or element nodes starting at the current insertion point, up to and including$node. Afterwards, the parent of$nodewill be the current insertion point. It condenses the tree to avoid redundant font switching elements. Iconic cleanup behavior. π§$document->afterOpen($node);β carries out anyafterOpenoperations that have been recorded (usingTag) for the element name of$node. π$document->afterClose($node);β carries out anyafterCloseoperations that have been recorded (usingTag) for the element name of$node. Matching set, we love to see it. πΈ
π οΈ Document Modification π οΈ
Okay so these next methods are for doing various sorts of modification and rearrangement of the document, after the normal flow of insertion has already happened. You might need them after an environment (or maybe the whole entire document) has been completed, and now you need to analyze what it contains to decide on the appropriate representation. Very βpost-processing eraβ of you. π
$document->setAttribute($node,$key,$value);β sets the attribute$keyto$valueon$node. This method is preferred over the direct LibXML one, since it takes care of decoding namespaces (if$keyis a qname), and it also manages recording ofxml:ids. π$document->recordID($id,$node);β records the association of the given$nodewith the$id, which should be thexml:idattribute of the$node. Usually this association will be maintained by the methods that create nodes or set attributes. πͺͺ$document->unRecordID($id);β removes the node associated with the given$id, if any. This might be needed if a node is deleted. Bye-bye association. π$document->modifyID($id);β adjusts$id, if needed, so that it is unique. It does this by appending a letter and incrementing until it finds an id that is not yet associated with a node. Incremental slay. π$node = $document->lookupID($id);β returns the node, if any, that is associated with the given$id. π$document->setNodeBox($node,$box);β records the$box(being a Box, Whatsit or List) that was (presumably) responsible for the creation of the element$node. This information is useful for determining source locations, original TeX strings, and so forth. Very βwe remember where you came fromβ energy. π¦$box = $document->getNodeBox($node);β returns the$boxthat was responsible for creating the element$node. π$document->setNodeFont($node,$font);β records the font object that encodes the font that should be used to display any text within the element$node. π$font = $document->getNodeFont($node);β returns the font object associated with the element$node. β¨$node = $document->openElementAt($point,$qname,%attributes);β opens a new child element in$pointwith the qualified name$qnameand with the given attributes. This method is not affected by, nor does it affect, the current insertion point. It does manage namespaces,xml:ids, and associating a box, font and locator with the new element, as well as running anyafterOpenoperations. Multitasking icon. π$node = $document->closeElementAt($node);β closes$node. This method is not affected by, nor does it affect, the current insertion point. However, it does run anyafterCloseoperations, so any element that was created using the lower-levelopenElementAtshould be closed using this method. No half-finished exits, bestie. πͺ$node = $document->appendClone($node,@newchildren);β appends clones of@newchildrento$node. This method modifies any ids found within@newchildren(usingmodifyID), and fixes up any references to those ids within the clones so that they refer to the modified id. Clone responsibly. π§¬$node = $document->wrapNodes($qname,@nodes);β this method wraps the@nodesby a new element with qualified name$qname; that new node replaces the first of@node. The remaining nodes in@nodesmust be following siblings of the first one. π
NOTE: Does this need multiple nodes? If so, perhaps some kind of movenodes helper? Otherwise, what about attributes?
$node = $document->unwrapNodes($node);β unwrap the children of$node, by replacing$nodeby its children. Free them from the enclosure. π¦$node = $document->replaceNode($node,@nodes);β replace$nodeby@nodes; presumably they are some sort of descendant nodes. π$node = $document->renameNode($node,$newname);β rename$nodeto the tagname$newname; equivalently replace$nodeby a new node with name$newnameand copy the attributes and contents. It is assumed that$newnamecan contain those attributes and contents. Name change, same vibe. π·οΈ@nodes = $document->filterDeletions(@nodes);β this function is useful with"$doc-"absorb($box)>, when you want to filter out any nodes that have been deleted and no longer appear in the document. Deleted means deleted, periodt. ποΈ@nodes = $document->filterChildren(@nodes);β this function is useful with"$doc-"absorb($box)>, when you want to filter out any nodes that are children of other nodes in@nodes. We only want the main characters, not the whole family tree. π
π AUTHOR π
Bruce Miller <bruce.miller@nist.gov>
π COPYRIGHT π
Public domain software, produced as part of work done by the United States Government & not subject to copyright in the US.
π Thatβs the whole page, bestie. The footer says source/version perl v5.40.1, dated 2025-11-16, for LaTeXM...ocument(3pm). Go forth and slay your document tree. π
β¨
π¦ where this page comes from
- ubuntu resolute: latexml 0.8.8-4 Β· PD
- ubuntu stonking: latexml 0.8.8-4 Β· PD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms