itutor-mathlive
Version:
Beautifully typeset math made easy
645 lines (545 loc) • 61.5 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"><title>addons/outputMathML.js - MathLive Docs</title><meta name="description" content="Beautifully typeset math made easy"><meta name="keywords" content="latex, tex, math, typesetting, documentation, docs">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700|Source+Sans+Pro:400,400i,700,900" rel="stylesheet">
<style>pre.prettyprint{background: #35434e;}</style>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow-night.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/custom.css">
</head>
<body>
<div class="forkme"><a href="https://github.com/arnog/mathlive"><img style="position: absolute; top: 0; right: 0; border: 0; z-index:1;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a></div>
<section role="navigation">
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav id="nav">
<h3 class="group-title home"><a href="index.html">MathLive Docs</a></h3><input class="search" placeholder="Search" type="text"><div class="list"><h3 class="group-title">Tutorials</h3><ul><li><a href="tutorial-CONTRIBUTOR_GUIDE.html">Contributor Guide</a></li><li><a href="tutorial-MASTON.html">MASTON</a></li><li><a href="tutorial-USAGE_GUIDE.html">Usage Guide</a></li></ul><h3 class="group-title">Classes</h3><ul><li class="private"><a href="Context.html" class="className">Context</a><ul class='methods private'><li data-type='method' class='private'><a href="Context.html#clone" class="methodName">clone</a></li><li data-type='method' class='private'><a href="Context.html#cloneWith" class="methodName">cloneWith</a></li><li data-type='method' class='private'><a href="Context.html#getBackgroundColor" class="methodName">getBackgroundColor</a></li><li data-type='method' class='private'><a href="Context.html#getColor" class="methodName">getColor</a></li><li data-type='method' class='private'><a href="Context.html#setMathstyle" class="methodName">setMathstyle</a></li><li data-type='method' class='private'><a href="Context.html#withMathstyle" class="methodName">withMathstyle</a></li></ul></li><li><a href="EditableMathlist.html" class="className">EditableMathlist</a><ul class='methods'><li data-type='method'><a href="EditableMathlist.html#_addCell" class="methodName">_addCell</a></li><li data-type='method'><a href="EditableMathlist.html#_deleteAtoms" class="methodName">_deleteAtoms</a></li><li data-type='method'><a href="EditableMathlist.html#addColumnAfter_" class="methodName">addColumnAfter_</a></li><li data-type='method'><a href="EditableMathlist.html#addColumnBefore_" class="methodName">addColumnBefore_</a></li><li data-type='method'><a href="EditableMathlist.html#addRowAfter_" class="methodName">addRowAfter_</a></li><li data-type='method'><a href="EditableMathlist.html#addRowBefore_" class="methodName">addRowBefore_</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#ancestor" class="methodName">ancestor</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#anchor" class="methodName">anchor</a></li><li data-type='method'><a href="EditableMathlist.html#applyStyle" class="methodName">applyStyle</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#commandOffsets" class="methodName">commandOffsets</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#commitCommandStringBeforeInsertionPoint" class="methodName">commitCommandStringBeforeInsertionPoint</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#contains" class="methodName">contains</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#decorateCommandStringAroundInsertionPoint" class="methodName">decorateCommandStringAroundInsertionPoint</a></li><li data-type='method'><a href="EditableMathlist.html#delete" class="methodName">delete</a></li><li data-type='method'><a href="EditableMathlist.html#delete_" class="methodName">delete_</a></li><li data-type='method'><a href="EditableMathlist.html#deleteAll_" class="methodName">deleteAll_</a></li><li data-type='method'><a href="EditableMathlist.html#deleteNextChar_" class="methodName">deleteNextChar_</a></li><li data-type='method'><a href="EditableMathlist.html#deleteNextWord_" class="methodName">deleteNextWord_</a></li><li data-type='method'><a href="EditableMathlist.html#deletePreviousChar_" class="methodName">deletePreviousChar_</a></li><li data-type='method'><a href="EditableMathlist.html#deletePreviousWord_" class="methodName">deletePreviousWord_</a></li><li data-type='method'><a href="EditableMathlist.html#deleteToGroupEnd_" class="methodName">deleteToGroupEnd_</a></li><li data-type='method'><a href="EditableMathlist.html#deleteToGroupStart_" class="methodName">deleteToGroupStart_</a></li><li data-type='method'><a href="EditableMathlist.html#deleteToMathFieldEnd_" class="methodName">deleteToMathFieldEnd_</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#endOffset" class="methodName">endOffset</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#extend" class="methodName">extend</a></li><li data-type='method'><a href="EditableMathlist.html#extendDown_" class="methodName">extendDown_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToGroupEnd_" class="methodName">extendToGroupEnd_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToGroupStart_" class="methodName">extendToGroupStart_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToMathFieldEnd_" class="methodName">extendToMathFieldEnd_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToMathFieldStart_" class="methodName">extendToMathFieldStart_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToNextBoundary_" class="methodName">extendToNextBoundary_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToNextChar_" class="methodName">extendToNextChar_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToNextWord_" class="methodName">extendToNextWord_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToPreviousBoundary_" class="methodName">extendToPreviousBoundary_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToPreviousChar_" class="methodName">extendToPreviousChar_</a></li><li data-type='method'><a href="EditableMathlist.html#extendToPreviousWord_" class="methodName">extendToPreviousWord_</a></li><li data-type='method'><a href="EditableMathlist.html#extendUp_" class="methodName">extendUp_</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#extractCharactersBeforeInsertionPoint" class="methodName">extractCharactersBeforeInsertionPoint</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#extractCommandStringAroundInsertionPoint" class="methodName">extractCommandStringAroundInsertionPoint</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#extractContents" class="methodName">extractContents</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#extractContentsOrdInGroupBeforeInsertionPoint" class="methodName">extractContentsOrdInGroupBeforeInsertionPoint</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#filter" class="methodName">filter</a></li><li data-type='method'><a href="EditableMathlist.html#insert" class="methodName">insert</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#insertFirstAtom" class="methodName">insertFirstAtom</a></li><li data-type='method'><a href="EditableMathlist.html#isCollapsed" class="methodName">isCollapsed</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#jump" class="methodName">jump</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#leap" class="methodName">leap</a></li><li data-type='method'><a href="EditableMathlist.html#moveAfterParent_" class="methodName">moveAfterParent_</a></li><li data-type='method'><a href="EditableMathlist.html#moveBeforeParent_" class="methodName">moveBeforeParent_</a></li><li data-type='method'><a href="EditableMathlist.html#moveDown_" class="methodName">moveDown_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToGroupEnd_" class="methodName">moveToGroupEnd_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToGroupStart_" class="methodName">moveToGroupStart_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToMathFieldEnd_" class="methodName">moveToMathFieldEnd_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToMathFieldStart_" class="methodName">moveToMathFieldStart_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToNextChar_" class="methodName">moveToNextChar_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToNextPlaceholder_" class="methodName">moveToNextPlaceholder_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToNextWord_" class="methodName">moveToNextWord_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToOpposite_" class="methodName">moveToOpposite_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToPreviousChar_" class="methodName">moveToPreviousChar_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToPreviousPlaceholder_" class="methodName">moveToPreviousPlaceholder_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToPreviousWord_" class="methodName">moveToPreviousWord_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToSubscript_" class="methodName">moveToSubscript_</a></li><li data-type='method'><a href="EditableMathlist.html#moveToSuperscript_" class="methodName">moveToSuperscript_</a></li><li data-type='method'><a href="EditableMathlist.html#moveUp_" class="methodName">moveUp_</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#next" class="methodName">next</a></li><li data-type='method'><a href="EditableMathlist.html#selectAll_" class="methodName">selectAll_</a></li><li data-type='method'><a href="EditableMathlist.html#selectGroup_" class="methodName">selectGroup_</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#setExtent" class="methodName">setExtent</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#setRange" class="methodName">setRange</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#setSelection" class="methodName">setSelection</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#sibling" class="methodName">sibling</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#siblings" class="methodName">siblings</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#skip" class="methodName">skip</a></li><li data-type='method'><a href="EditableMathlist.html#speakAll_" class="methodName">speakAll_</a></li><li data-type='method'><a href="EditableMathlist.html#speakAllWithSynchronizedHighlighting_" class="methodName">speakAllWithSynchronizedHighlighting_</a></li><li data-type='method'><a href="EditableMathlist.html#speakGroup_" class="methodName">speakGroup_</a></li><li data-type='method'><a href="EditableMathlist.html#speakLeftSibling_" class="methodName">speakLeftSibling_</a></li><li data-type='method'><a href="EditableMathlist.html#speakParent_" class="methodName">speakParent_</a></li><li data-type='method'><a href="EditableMathlist.html#speakRightSibling_" class="methodName">speakRightSibling_</a></li><li data-type='method'><a href="EditableMathlist.html#speakSelection_" class="methodName">speakSelection_</a></li><li data-type='method'><a href="EditableMathlist.html#speakSelectionWithSynchronizedHighlighting_" class="methodName">speakSelectionWithSynchronizedHighlighting_</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#startOffset" class="methodName">startOffset</a></li><li data-type='method' class='private'><a href="EditableMathlist.html#toString" class="methodName">toString</a></li><li data-type='method'><a href="EditableMathlist.html#transpose_" class="methodName">transpose_</a></li></ul></li><li class="private"><a href="Lexer.html" class="className">Lexer</a><ul class='methods private'><li data-type='method' class='private'><a href="Lexer.html#end" class="methodName">end</a></li><li data-type='method' class='private'><a href="Lexer.html#get" class="methodName">get</a></li><li data-type='method' class='private'><a href="Lexer.html#isWhiteSpace" class="methodName">isWhiteSpace</a></li><li data-type='method' class='private'><a href="Lexer.html#makeToken" class="methodName">makeToken</a></li><li data-type='method' class='private'><a href="Lexer.html#peek" class="methodName">peek</a></li><li data-type='method' class='private'><a href="Lexer.html#scan" class="methodName">scan</a></li></ul></li><li class="private"><a href="MathAtom.html" class="className">MathAtom</a><ul class='methods private'><li data-type='method' class='private'><a href="MathAtom.html#.toSpeakableText" class="methodName">toSpeakableText</a></li><li data-type='method' class='private'><a href="MathAtom.html#bind" class="methodName">bind</a></li><li data-type='method' class='private'><a href="MathAtom.html#decompose" class="methodName">decompose</a></li><li data-type='method' class='private'><a href="MathAtom.html#decomposeGenfrac" class="methodName">decomposeGenfrac</a></li><li data-type='method' class='private'><a href="MathAtom.html#decomposeLeftright" class="methodName">decomposeLeftright</a></li><li data-type='method' class='private'><a href="MathAtom.html#decomposeLine" class="methodName">decomposeLine</a></li><li data-type='method' class='private'><a href="MathAtom.html#decomposeRule" class="methodName">decomposeRule</a></li><li data-type='method' class='private'><a href="MathAtom.html#filter" class="methodName">filter</a></li><li data-type='method' class='private'><a href="MathAtom.html#makeSpan" class="methodName">makeSpan</a></li></ul></li><li><a href="MathField.html" class="className">MathField</a><ul class='methods'><li data-type='method' class='private'><a href="MathField.html#_getCaretPosition" class="methodName">_getCaretPosition</a></li><li data-type='method' class='private'><a href="MathField.html#_onKeystroke" class="methodName">_onKeystroke</a></li><li data-type='method' class='private'><a href="MathField.html#complete_" class="methodName">complete_</a></li><li data-type='method'><a href="MathField.html#el" class="methodName">el</a></li><li data-type='method' class='private'><a href="MathField.html#enterCommandMode_" class="methodName">enterCommandMode_</a></li><li data-type='method'><a href="MathField.html#insert" class="methodName">insert</a></li><li data-type='method'><a href="MathField.html#keystroke" class="methodName">keystroke</a></li><li data-type='method'><a href="MathField.html#latex" class="methodName">latex</a></li><li data-type='method'><a href="MathField.html#perform" class="methodName">perform</a></li><li data-type='method'><a href="MathField.html#perform" class="methodName">perform</a></li><li data-type='method' class='private'><a href="MathField.html#render" class="methodName">render</a></li><li data-type='method'><a href="MathField.html#revertToOriginalContent" class="methodName">revertToOriginalContent</a></li><li data-type='method'><a href="MathField.html#selectedText" class="methodName">selectedText</a></li><li data-type='method'><a href="MathField.html#selectionAtEnd" class="methodName">selectionAtEnd</a></li><li data-type='method'><a href="MathField.html#selectionAtStart" class="methodName">selectionAtStart</a></li><li data-type='method'><a href="MathField.html#selectionDepth" class="methodName">selectionDepth</a></li><li data-type='method'><a href="MathField.html#selectionIsCollapsed" class="methodName">selectionIsCollapsed</a></li><li data-type='method'><a href="MathField.html#setConfig" class="methodName">setConfig</a></li><li data-type='method'><a href="MathField.html#text" class="methodName">text</a></li><li data-type='method'><a href="MathField.html#typedText" class="methodName">typedText</a></li></ul></li><li class="private"><a href="module-mathstyle.Mathstyle.html" class="className">Mathstyle</a></li><li class="private"><a href="Parser.html" class="className">Parser</a><ul class='methods private'><li data-type='method' class='private'><a href="Parser.html#end" class="methodName">end</a></li><li data-type='method' class='private'><a href="Parser.html#hasLiteral" class="methodName">hasLiteral</a></li><li data-type='method' class='private'><a href="Parser.html#hasLiteralPattern" class="methodName">hasLiteralPattern</a></li><li data-type='method' class='private'><a href="Parser.html#hasToken" class="methodName">hasToken</a></li><li data-type='method' class='private'><a href="Parser.html#lastMathAtom" class="methodName">lastMathAtom</a></li><li data-type='method' class='private'><a href="Parser.html#parseAtom" class="methodName">parseAtom</a></li><li data-type='method' class='private'><a href="Parser.html#parseKeyword" class="methodName">parseKeyword</a></li><li data-type='method' class='private'><a href="Parser.html#parseLimits" class="methodName">parseLimits</a></li><li data-type='method' class='private'><a href="Parser.html#parseSupSub" class="methodName">parseSupSub</a></li><li data-type='method' class='private'><a href="Parser.html#parseToken" class="methodName">parseToken</a></li><li data-type='method' class='private'><a href="Parser.html#scanArg" class="methodName">scanArg</a></li><li data-type='method' class='private'><a href="Parser.html#scanColor" class="methodName">scanColor</a></li><li data-type='method' class='private'><a href="Parser.html#scanDelim" class="methodName">scanDelim</a></li><li data-type='method' class='private'><a href="Parser.html#scanDimen" class="methodName">scanDimen</a></li><li data-type='method' class='private'><a href="Parser.html#scanEnvironment" class="methodName">scanEnvironment</a></li><li data-type='method' class='private'><a href="Parser.html#scanGroup" class="methodName">scanGroup</a></li><li data-type='method' class='private'><a href="Parser.html#scanImplicitGroup" class="methodName">scanImplicitGroup</a></li><li data-type='method' class='private'><a href="Parser.html#scanLeftRight" class="methodName">scanLeftRight</a></li><li data-type='method' class='private'><a href="Parser.html#scanModeSet" class="methodName">scanModeSet</a></li><li data-type='method' class='private'><a href="Parser.html#scanModeShift" class="methodName">scanModeShift</a></li><li data-type='method' class='private'><a href="Parser.html#scanNumber" class="methodName">scanNumber</a></li><li data-type='method' class='private'><a href="Parser.html#scanString" class="methodName">scanString</a></li><li data-type='method' class='private'><a href="Parser.html#scanToken" class="methodName">scanToken</a></li></ul></li><li class="private"><a href="Span.html" class="className">Span</a></li><li class="private"><a href="Token.html" class="className">Token</a></li><li class="private"><a href="UndoManager.html" class="className">UndoManager</a><ul class='methods private'><li data-type='method' class='private'><a href="UndoManager.html#canRedo" class="methodName">canRedo</a></li><li data-type='method' class='private'><a href="UndoManager.html#canUndo" class="methodName">canUndo</a></li><li data-type='method' class='private'><a href="UndoManager.html#redo" class="methodName">redo</a></li><li data-type='method' class='private'><a href="UndoManager.html#snapshot" class="methodName">snapshot</a></li><li data-type='method' class='private'><a href="UndoManager.html#undo" class="methodName">undo</a></li></ul></li></ul><h3 class="group-title">Modules</h3><ul><li class="private"><a href="module-color.html" class="className">color</a><ul class='methods private'><li data-type='method' class='private'><a href="module-color.html#.stringToColor" class="methodName">stringToColor</a></li></ul></li><li class="private"><a href="module-definitions.html" class="className">definitions</a><ul class='methods private'><li data-type='method' class='private'><a href="module-definitions.html#.defineEnvironment" class="methodName">defineEnvironment</a></li><li data-type='method' class='private'><a href="module-definitions.html#.defineFunction" class="methodName">defineFunction</a></li><li data-type='method' class='private'><a href="module-definitions.html#.defineSymbol" class="methodName">defineSymbol</a></li><li data-type='method' class='private'><a href="module-definitions.html#.defineSymbolRange" class="methodName">defineSymbolRange</a></li><li data-type='method' class='private'><a href="module-definitions.html#.defineSymbols" class="methodName">defineSymbols</a></li><li data-type='method' class='private'><a href="module-definitions.html#.frequency" class="methodName">frequency</a></li><li data-type='method' class='private'><a href="module-definitions.html#.getInfo" class="methodName">getInfo</a></li><li data-type='method' class='private'><a href="module-definitions.html#.matchCodepoint" class="methodName">matchCodepoint</a></li><li data-type='method' class='private'><a href="module-definitions.html#.matchFunction" class="methodName">matchFunction</a></li><li data-type='method' class='private'><a href="module-definitions.html#.parseParamTemplateArgument" class="methodName">parseParamTemplateArgument</a></li><li data-type='method' class='private'><a href="module-definitions.html#.suggest" class="methodName">suggest</a></li></ul></li><li class="private"><a href="module-delimiters.html" class="className">delimiters</a><ul class='methods private'><li data-type='method' class='private'><a href="module-delimiters.html#.makeCustomSizedDelim" class="methodName">makeCustomSizedDelim</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeInner" class="methodName">makeInner</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeLargeDelim" class="methodName">makeLargeDelim</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeLeftRightDelim" class="methodName">makeLeftRightDelim</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeNullFence" class="methodName">makeNullFence</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeSizedDelim" class="methodName">makeSizedDelim</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeSmallDelim" class="methodName">makeSmallDelim</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.makeStackedDelim" class="methodName">makeStackedDelim</a></li><li data-type='method' class='private'><a href="module-delimiters.html#.traverseSequence" class="methodName">traverseSequence</a></li></ul></li><li class="private"><a href="module-editor_editableMathlist.html" class="className">editor/editableMathlist</a><ul class='methods private'><li data-type='method' class='private'><a href="module-editor_editableMathlist.html#~atomContains" class="methodName">atomContains</a></li></ul></li><li class="private"><a href="module-editor_keyboard.html" class="className">editor/keyboard</a><ul class='methods private'><li data-type='method' class='private'><a href="module-editor_keyboard.html#.delegateKeyboardEvents" class="methodName">delegateKeyboardEvents</a></li><li data-type='method' class='private'><a href="module-editor_keyboard.html#.keyboardEventToString" class="methodName">keyboardEventToString</a></li></ul></li><li class="private"><a href="module-editor_mathfield.html" class="className">editor/mathfield</a><ul class='methods private'><li data-type='method' class='private'><a href="module-editor_mathfield.html#nearestElementFromPoint" class="methodName">nearestElementFromPoint</a></li></ul></li><li class="private"><a href="module-editor_mathpath.html" class="className">editor/mathpath</a><ul class='methods private'><li data-type='method' class='private'><a href="module-editor_mathpath.html#.pathCommonAncestor" class="methodName">pathCommonAncestor</a></li><li data-type='method' class='private'><a href="module-editor_mathpath.html#.pathDistance" class="methodName">pathDistance</a></li><li data-type='method' class='private'><a href="module-editor_mathpath.html#.pathFromString" class="methodName">pathFromString</a></li><li data-type='method' class='private'><a href="module-editor_mathpath.html#.pathToString" class="methodName">pathToString</a></li></ul></li><li class="private"><a href="module-editor_shortcuts.html" class="className">editor/shortcuts</a><ul class='methods private'><li data-type='method' class='private'><a href="module-editor_shortcuts.html#.match" class="methodName">match</a></li><li data-type='method' class='private'><a href="module-editor_shortcuts.html#.matchKeystroke" class="methodName">matchKeystroke</a></li><li data-type='method' class='private'><a href="module-editor_shortcuts.html#.platform" class="methodName">platform</a></li><li data-type='method' class='private'><a href="module-editor_shortcuts.html#.stringify" class="methodName">stringify</a></li></ul></li><li class="private"><a href="module-fontMetrics.html" class="className">fontMetrics</a><ul class='methods private'><li data-type='method' class='private'><a href="module-fontMetrics.html#.getCharacterMetrics" class="methodName">getCharacterMetrics</a></li></ul></li><li class="private"><a href="module-lexer.html" class="className">lexer</a><ul class='methods private'><li data-type='method' class='private'><a href="module-lexer.html#.tokenize" class="methodName">tokenize</a></li></ul></li><li class="private"><a href="module-mathAtom.html" class="className">mathAtom</a><ul class='methods private'><li data-type='method' class='private'><a href="module-mathAtom.html#.decompose" class="methodName">decompose</a></li><li data-type='method' class='private'><a href="module-mathAtom.html#.getFontName" class="methodName">getFontName</a></li><li data-type='method' class='private'><a href="module-mathAtom.html#.makeColGap" class="methodName">makeColGap</a></li><li data-type='method' class='private'><a href="module-mathAtom.html#.makeColOfRepeatingElements" class="methodName">makeColOfRepeatingElements</a></li><li data-type='method' class='private'><a href="module-mathAtom.html#.makeStack" class="methodName">makeStack</a></li></ul></li><li><a href="module-mathlive.html" class="className">mathlive</a><ul class='methods'><li data-type='method'><a href="module-mathlive.html#latexToAST" class="methodName">latexToAST</a></li><li data-type='method'><a href="module-mathlive.html#latexToMarkup" class="methodName">latexToMarkup</a></li><li data-type='method'><a href="module-mathlive.html#latexToMathML" class="methodName">latexToMathML</a></li><li data-type='method'><a href="module-mathlive.html#latexToSpeakableText" class="methodName">latexToSpeakableText</a></li><li data-type='method'><a href="module-mathlive.html#makeMathField" class="methodName">makeMathField</a></li><li data-type='method'><a href="module-mathlive.html#pauseReadAloud" class="methodName">pauseReadAloud</a></li><li data-type='method'><a href="module-mathlive.html#playReadAloud" class="methodName">playReadAloud</a></li><li data-type='method'><a href="module-mathlive.html#readAloud" class="methodName">readAloud</a></li><li data-type='method'><a href="module-mathlive.html#readAloudStatus" class="methodName">readAloudStatus</a></li><li data-type='method'><a href="module-mathlive.html#renderMathInDocument" class="methodName">renderMathInDocument</a></li><li data-type='method'><a href="module-mathlive.html#renderMathInElement" class="methodName">renderMathInElement</a></li><li data-type='method'><a href="module-mathlive.html#resumeReadAloud" class="methodName">resumeReadAloud</a></li><li data-type='method'><a href="module-mathlive.html#revertToOriginalContent" class="methodName">revertToOriginalContent</a></li><li data-type='method'><a href="module-mathlive.html#revertToOriginalContent" class="methodName">revertToOriginalContent</a></li></ul></li><li class="private"><a href="module-mathstyle.html" class="className">mathstyle</a><ul class='methods private'><li data-type='method' class='private'><a href="module-mathstyle.html#.toMathstyle" class="methodName">toMathstyle</a></li></ul></li><li class="private"><a href="module-span.html" class="className">span</a><ul class='methods private'><li data-type='method' class='private'><a href="module-span.html#.coalesce" class="methodName">coalesce</a></li><li data-type='method' class='private'><a href="module-span.html#.makeFontSizer" class="methodName">makeFontSizer</a></li><li data-type='method' class='private'><a href="module-span.html#.makeHlist" class="methodName">makeHlist</a></li><li data-type='method' class='private'><a href="module-span.html#.makeSpan" class="methodName">makeSpan</a></li><li data-type='method' class='private'><a href="module-span.html#.makeSpanOfType" class="methodName">makeSpanOfType</a></li><li data-type='method' class='private'><a href="module-span.html#.makeSymbol" class="methodName">makeSymbol</a></li><li data-type='method' class='private'><a href="module-span.html#.makeVlist" class="methodName">makeVlist</a></li><li data-type='method' class='private'><a href="module-span.html#.toString" class="methodName">toString</a></li></ul></li></ul><label class="checkbox"><input id="toggle-private" type="checkbox" onclick="
if (!document.getElementById('toggle-private').checked) {
document.documentElement.classList.add('no-private')
writeCookie('symbol-access', 'no-private')
} else {
document.documentElement.classList.remove('no-private')
writeCookie('symbol-access', 'private')
}
">Include Private Symbols</input></label></div>
<footer role="contentInfo">
Made with <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>.
</footer>
</nav>
</section>
<main id="main">
<h1 class="page-title">addons/outputMathML.js</h1>
<section>
<article>
<pre class="prettyprint source linenums">
<code>define(['mathlive/core/mathAtom', 'mathlive/core/color'],
function(MathAtom, Color) {
const SPECIAL_OPERATORS = {
'\\pm': '&PlusMinus;',
'\\times': '&times;',
'\\colon': ':',
'\\vert': '|',
'\\Vert': '\u2225',
'\\mid': '\u2223',
'\\lbrace': '{',
'\\rbrace': '}',
'\\langle': '\u27e8',
'\\rangle': '\u27e9',
'\\lfloor': '\u230a',
'\\rfloor': '\u230b',
'\\lceil': '\u2308',
'\\rceil': '\u2309',
'\\vec': '&#x20d7;',
'\\acute': '&#x00b4;',
'\\grave': '&#x0060;',
'\\dot': '&#x02d9;',
'\\ddot': '&#x00a8;',
'\\tilde': '&#x007e;',
'\\bar': '&#x00af;',
'\\breve': '&#x02d8;',
'\\check': '&#x02c7;',
'\\hat': '&#x005e;'
};
function xmlEscape(str) {
return str
// .replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function makeID(id, options) {
if (!id || !options.generateID) return '';
// Note: the 'extid' attribute is recognized by SRE as an attribute
// to be passed to SSML as a <mark> tag.
return ' extid="' + id + '"';
}
function scanIdentifier(stream, final, options) {
let result = false;
final = final || stream.atoms.length;
let mathML = '';
let body = '';
let superscript = -1;
let subscript = -1;
const atom = stream.atoms[stream.index];
if (stream.index < final &&
(atom.type === 'mord' || atom.type === 'textord') &&
'0123456789,.'.indexOf(atom.latex) < 0) {
body = atom.toMathML(options);
if (atom.superscript) {
superscript = stream.index;
}
if (atom.subscript) {
subscript = stream.index;
}
stream.index += 1;
}
if (body.length > 0) {
result = true;
// If there are separate atoms for sub/sup, record them
if (isSuperscriptAtom(stream)) {
superscript = stream.index;
stream.index += 1;
}
if (isSubscriptAtom(stream)) {
subscript = stream.index;
stream.index += 1;
}
if (superscript >= 0 && subscript >= 0) {
mathML = '<msubsup>' + body;
mathML += toMathML(stream.atoms[subscript].subscript, 0, 0, options).mathML;
mathML += toMathML(stream.atoms[superscript].superscript, 0, 0, options).mathML;
mathML += '</msubsup>';
} else if (superscript >= 0) {
mathML = '<msup>' + body;
mathML += toMathML(stream.atoms[superscript].superscript, 0, 0, options).mathML;
mathML += '</msup>';
} else if (subscript >= 0) {
mathML = '<msub>' + body;
mathML += toMathML(stream.atoms[subscript].subscript, 0, 0, options).mathML;
mathML += '</msub>';
} else {
mathML = body;
}
if ((stream.lastType === 'mi' ||
stream.lastType === 'mn' ||
stream.lastType === 'fence') &&
!/^<mo>(.*)<\/mo>$/.test(mathML)) {
mathML = '<mo>&InvisibleTimes;</mo>' + mathML;
}
if (body.endsWith('>f</mi>') || body.endsWith('>g</mi>')) {
mathML += '<mo> &ApplyFunction; </mo>';
stream.lastType = 'applyfunction';
} else {
stream.lastType = /^<mo>(.*)<\/mo>$/.test(mathML) ? 'mo' : 'mi';
}
stream.mathML += mathML;
}
return result;
}
/**
* Return true if the current atom is a standalone superscript atom
* i.e. an atom with no content, except of a superscript.
* Superscripts can be encoded either as an attribute on the last atom
* or as a standalone, empty, atom following the one to which it applies.
* @param {*} stream
*/
function isSuperscriptAtom(stream) {
return stream.index < stream.atoms.length &&
stream.atoms[stream.index].superscript &&
stream.atoms[stream.index].type === 'msubsup'
}
function isSubscriptAtom(stream) {
return stream.index < stream.atoms.length &&
stream.atoms[stream.index].subscript &&
stream.atoms[stream.index].type === 'msubsup'
}
function indexOfSuperscriptInNumber(stream) {
let result = -1;
let i = stream.index;
let done = false;
let found = false;
while (i < stream.atoms.length && !done && !found) {
done = stream.atoms[i].type !== 'mord' ||
'0123456789,.'.indexOf(stream.atoms[i].latex) < 0;
found = !done && stream.atoms[i].superscript;
i++
}
if (found) {
result = i;
}
return result;
}
function parseSubsup(base, stream, options) {
let result = false;
let mathML = '';
let atom = stream.atoms[stream.index - 1];
if (!atom) return false;
if (!atom.superscript && !atom.subscript) {
if (isSuperscriptAtom(stream) || isSubscriptAtom(stream)) {
atom = stream.atoms[stream.index];
stream.index += 1;
}
}
if (!atom) return false;
if (atom.superscript && atom.subscript) {
mathML = '<msubsup>' + base;
mathML += toMathML(atom.subscript, 0, 0, options).mathML;
mathML += toMathML(atom.superscript, 0, 0, options).mathML;
mathML += '</msubsup>';
} else if (atom.superscript) {
mathML = '<msup>' + base;
mathML += toMathML(atom.superscript, 0, 0, options).mathML;
mathML += '</msup>';
} else if (atom.subscript) {
mathML = '<msub>' + base;
mathML += toMathML(atom.subscript, 0, 0, options).mathML;
mathML += '</msub>';
}
if (mathML.length > 0) {
result = true;
stream.mathML += mathML;
stream.lastType = '';
}
return result;
}
function scanNumber(stream, final, options) {
let result = false;
final = final || stream.atoms.length;
const initial = stream.index;
let mathML = '';
let superscript = indexOfSuperscriptInNumber(stream);
if (superscript >= 0 && superscript < final) {
final = superscript;
}
while (stream.index < final &&
stream.atoms[stream.index].type === 'mord' &&
'0123456789,.'.indexOf(stream.atoms[stream.index].latex) >= 0
) {
mathML += stream.atoms[stream.index].latex;
stream.index += 1;
}
if (mathML.length > 0) {
result = true;
mathML = '<mn' + makeID(stream.atoms[initial].id, options) + '>' + mathML + '</mn>';
if (superscript < 0 && isSuperscriptAtom(stream)) {
superscript = stream.index;
stream.index += 1;
}
if (superscript >= 0) {
mathML = '<msup>' + mathML;
mathML += toMathML(stream.atoms[superscript].superscript, 0, 0, options).mathML;
mathML += '</msup>';
}
stream.mathML += mathML;
stream.lastType = 'mn';
}
return result;
}
function scanFence(stream, final, options) {
let result = false;
final = final || stream.atoms.length;
let mathML = '';
let lastType = '';
if (stream.index < final &&
stream.atoms[stream.index].type === 'mopen') {
let found = false;
let depth = 0;
const openIndex = stream.index;
let closeIndex = -1;
let index = openIndex + 1;
while (index < final && !found) {
if (stream.atoms[index].type === 'mopen') {
depth += 1;
} else if (stream.atoms[index].type === 'mclose') {
depth -= 1;
}
if (depth === -1) {
found = true;
closeIndex = index;
}
index += 1;
}
if (found) {
// TODO: could add attribute indicating it's a fence (fence=true)
mathML = '<mrow>';
mathML += toMo(stream.atoms[openIndex], options);
mathML += toMathML(stream.atoms, openIndex + 1, closeIndex, options).mathML;
// TODO: could add attribute indicating it's a fence (fence=true)
mathML += toMo(stream.atoms[closeIndex], options);
mathML += '</mrow>';
if (stream.lastType === 'mi' ||
stream.lastType === 'mn' ||
stream.lastType === 'mfrac' ||
stream.lastType === 'fence') {
mathML = '<mo>&InvisibleTimes;</mo>' + mathML;
}
stream.index = closeIndex + 1;
if (parseSubsup(mathML, stream, options)) {
result = true;
stream.lastType = '';
mathML = '';
}
lastType = 'fence';
}
}
if (mathML.length > 0) {
result = true;
stream.mathML += mathML;
stream.lastType = lastType;
}
return result;
}
function scanOperator(stream, final, options) {
let result = false;
final = final || stream.atoms.length;
let mathML = '';
let lastType = '';
const atom = stream.atoms[stream.index];
if (stream.index < final && (
atom.type === 'mbin' || atom.type === 'mrel')) {
mathML += stream.atoms[stream.index].toMathML(options);
stream.index += 1;
lastType = 'mo';
} else if (stream.index < final && atom.type === 'mop') {
// mathML += '<mrow>';
if (atom.limits && (atom.superscript || atom.subscript)) {
// Operator with limits, e.g. \sum
const op = toMo(atom, options);
if (atom.superscript && atom.subscript) {
// Both superscript and subscript
mathML += (atom.limits !== 'nolimits' ? '<munderover>' : '<msubsup>') + op;
mathML += toMathML(atom.subscript, 0, 0, options).mathML;
mathML += toMathML(atom.superscript, 0, 0, options).mathML;
mathML += (atom.limits !== 'nolimits' ? '</munderover>' : '</msubsup>');
} else if (atom.superscript) {
// Superscript only
mathML += (atom.limits !== 'nolimits' ? '<mover>' : '<msup>') + op;
mathML += toMathML(atom.superscript, 0, 0, options).mathML;
mathML += (atom.limits !== 'nolimits' ? '</mover>' : '</msup>');
} else {
// Subscript only
mathML += (atom.limits !== 'nolimits' ? '<munder>' : '<msub>') + op;
mathML += toMathML(atom.subscript, 0, 0, options).mathML;
mathML += (atom.limits !== 'nolimits' ? '</munder>' : '</msub>');
}
lastType = 'mo';
} else {
const op = toMo(stream.atoms[stream.index], options);
mathML += op;
if (!/^<mo>(.*)<\/mo>$/.test(op)) {
mathML += '<mo> &ApplyFunction; </mo>';
// mathML += scanArgument(stream);
lastType = 'applyfunction';
} else {
lastType = 'mo';
}
}
// mathML += '</mrow>';
if ((stream.lastType === 'mi' || stream.lastType === 'mn') &&
!/^<mo>(.*)<\/mo>$/.test(mathML)) {
mathML = '<mo>&InvisibleTimes;</mo>' + mathML;
}
stream.index += 1;
}
if (mathML.length > 0) {
result = true;
stream.mathML += mathML;
stream.lastType = lastType;
}
return result;
}
/**
* Given an atom or an array of atoms, return their MathML representation as
* a string.
* @return {string}
* @param {string|MathAtom|MathAtom[]} input
* @param {number} initial index of the input to start conversion from
* @param {number} final last index of the input to stop conversion to
* @private
*/
function toMathML(input, initial, final, options) {
const result = {
atoms: input,
index: initial || 0,
mathML: '',
lastType: ''
};
final = final || (input ? input.length : 0);
if (typeof input === 'number' || typeof input === 'boolean') {
result.mathML = input.toString();
} else if (typeof input === 'string') {
result.mathML = input;
} else if (input && typeof input.toMathML === 'function') {
result.mathML = input.toMathML(options);
} else if (Array.isArray(input)) {
let count = 0;
while (result.index < final) {
if (scanNumber(result, final, options) ||
scanIdentifier(result, final, options) ||
scanOperator(result, final, options) ||
scanFence(result, final, options)) {
count += 1;
} else if (result.index < final) {
let mathML = result.atoms[result.index].toMathML(options);
if (result.lastType === 'mn' && mathML.length > 0 &&
result.atoms[result.index].type === 'genfrac') {
// If this is a fraction preceded by a number (e.g. 2 1/2),
// add an "invisible plus" (U+0264) character in front of it
mathML = '<mo>&#x2064;</mo>' + mathML;
}
if (result.atoms[result.index].type === 'genfrac') {
result.lastType = 'mfrac';
} else {
result.lastType = '';
}
if (mathML.length > 0) {
result.mathML += mathML;
count += 1;
}
result.index += 1;
}
}
// If there are more than a single element, wrap them in a mrow tag.
if (count > 1) {
result.mathML = '<mrow>' + result.mathML + '</mrow>';
}
}
return result;
}
function toMo(atom, options) {
let result = '';
if (atom) {
const body = toString(atom.body);
if (body) {
result = '<mo' + makeID(atom.id, options) + '>' + body + '</mo>';
}
}
return result;
}
function toString(atoms) {
if (!atoms) return '';
if (typeof atoms === 'string') return xmlEscape(atoms);
if (!Array.isArray(atoms) && typeof atoms.body === 'string') {
return xmlEscape(atoms.body);
}
let result = '';
for (const atom of atoms) {
if (typeof atom.body === 'string') {
result += atom.body;
}
}
return xmlEscape(result);
}
/**
* Return a MathML fragment representation of a single atom
*
* @return {string}
*/
MathAtom.MathAtom.prototype.toMathML = function(options) {
const SPECIAL_IDENTIFIERS = {
'\\exponentialE': '&ExponentialE;',
'\\imaginaryI': '&ImaginaryI;',
'\\differentialD': '&DifferentialD;',
'\\capitalDifferentialD': '&CapitalDifferentialD;',
'\\alpha': '&alpha;',
'\\pi': '&pi;',
'\\infty' : '&infin;',
'\\forall' : '&forall;',
'\\nexists': '&nexists;',
'\\exists': '&exist;',
'\\hbar': '\u210f',
'\\cdotp': '\u22c5',
'\\ldots': '\u2026',
'\\cdots': '\u22ef',
'\\ddots': '\u22f1',
'\\vdots': '\u22ee',
'\\ldotp': '\u002e',
// TODO: include all the 'textord' that are identifiers, not operators.
};
const MATH_VARIANTS = {
'mathbb': 'double-struck',
'mathbf': 'bold',
'mathcal': 'script',
'mathfrak': 'fraktur',
'mathscr': 'script',
'mathsf': 'sans-serif',
'mathtt': 'monospace'
};
const SPACING = {
'\\!': -3 / 18,
'\\ ': 6 / 18,
'\\,': 3 / 18,
'\\:': 4 / 18,
'\\;': 5 / 18,
'\\enspace': .5,
'\\quad': 1,
'\\qquad': 2,
'\\enskip': .5,
};
let result = '';
let sep = '';
let col, row, i;
let underscript, overscript, body;
let variant = MATH_VARIANTS[this.fontFamily || this.font] || '';
if (variant) {
variant = ' mathvariant="' + variant + '"';
}
const command = this.latex ? this.latex.trim() : null;
let m;
switch(this.type) {
case 'group':
case 'root':
result = toMathML(this.body, 0, 0, options).mathML;
break;
case 'array':
if ((this.lFence && this.lFence !== '.') ||
(this.rFence && this.rFence !== '.')) {
result += '<mrow>';
if ((this.lFence && this.lFence !== '.')) {
result += '<mo>' + (SPECIAL_OPERATORS[this.lFence] || this.lFence) + '</mo>';
}
}
result += '<mtable';
if (this.colFormat) {
result += ' columnalign="';
for (i = 0; i < this.colFormat.length; i++) {
if (this.colFormat[i].align) {
result += {l:'left', c:'center', r:'right'}[this.colFormat[i].align] + ' ';
}
}
result += '"';
}
result += '>';
for (row = 0; row < this.array.length; row++) {
result += '<mtr>';
for (col = 0; col < this.array[row].length; col++) {
result += '<mtd>' + toMathML(this.array[row][col], 0, 0, options).mathML + '</mtd>';
}
result += '</mtr>';
}
result += '</mtable>';
if ((this.lFence && this.lFence !== '.') ||
(this.rFence && this.rFence !== '.')) {
if ((this.rFence && this.rFence !== '.')) {
result += '<mo>' + (SPECIAL_OPERATORS[this.lFence] || this.rFence) + '</mo>';
}
result += '</mrow>';
}
break;
case 'genfrac':
if (this.leftDelim || this.rightDelim) {
result += '<mrow>';
}
if (this.leftDelim && this.leftDelim !== '.') {
result += '<mo' + makeID(this.id, options) + '>' + (SPECIAL_OPERATORS[th