diff --git a/TODO b/TODO
deleted file mode 100644
index 99e7e542..00000000
--- a/TODO
+++ /dev/null
@@ -1,10 +0,0 @@
-1、把 log 提取出 dbgout 之类的方法;已改作 beego.Info() 调用;
-2、把源代码里的 TODO 完成;
-3、Export 的两个 URL 应该可以合并,用是否有 :id 来区分;这样 0 号文档输出整个 book 更顺;已完成;
-4、统一代码风格,空格、命名之类的;
-5、美化 PDF 的输出格式;
-6、自动登录新开标签页而且并不能跳转至起始请求页的问题;
-7、用户分组管理;
-8、[自动]展示历史版本;增强历史版本对比显示的能力;
-9、[自动]展示作者信息;也许可以和上一需求合并考虑;
-10、查看了解评论功能;
diff --git a/static/css/markdown.css b/static/css/markdown.css
index 9e5e408e..fe24f160 100644
--- a/static/css/markdown.css
+++ b/static/css/markdown.css
@@ -131,17 +131,16 @@ body{
left: 0;
right: 0;
}
+.btn-toolbar{position: absolute;}
.editormd-group{
float: left;
height: 32px;
margin-right: 10px;
}
-.editormd-group a{
+.editormd-group a,.editormd-group .editor-item{
float: left;
}
-.editormd-group a.change{
-}
.editormd-group .change i{
color: #ffffff;
background-color: #44B036 !important;
@@ -158,10 +157,10 @@ body{
opacity: .6;
cursor: default
}
-.editormd-group a>i {
+.editormd-group a>i{
display: inline-block;
- width: 34px;
- height: 30px;
+ width: 34px !important;
+ height: 30px !important;
line-height: 30px;
text-align: center;
color: #4b4b4b;
diff --git a/static/katex/README.md b/static/katex/README.md
new file mode 100644
index 00000000..c7de02a7
--- /dev/null
+++ b/static/katex/README.md
@@ -0,0 +1,94 @@
+# [](https://khan.github.io/KaTeX/) [![Build Status](https://travis-ci.org/Khan/KaTeX.svg?branch=master)](https://travis-ci.org/Khan/KaTeX)
+
+[![Join the chat at https://gitter.im/Khan/KaTeX](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Khan/KaTeX?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+
+KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web.
+
+ * **Fast:** KaTeX renders its math synchronously and doesn't need to reflow the page. See how it compares to a competitor in [this speed test](http://www.intmath.com/cg5/katex-mathjax-comparison.php).
+ * **Print quality:** KaTeX’s layout is based on Donald Knuth’s TeX, the gold standard for math typesetting.
+ * **Self contained:** KaTeX has no dependencies and can easily be bundled with your website resources.
+ * **Server side rendering:** KaTeX produces the same output regardless of browser or environment, so you can pre-render expressions using Node.js and send them as plain HTML.
+
+KaTeX supports all major browsers, including Chrome, Safari, Firefox, Opera, Edge, and IE 9 - IE 11. A list of supported commands can be found on the [wiki](https://github.com/Khan/KaTeX/wiki/Function-Support-in-KaTeX).
+
+## Usage
+
+You can [download KaTeX](https://github.com/khan/katex/releases) and host it on your server or include the `katex.min.js` and `katex.min.css` files on your page directly from a CDN:
+
+```html
+
+
+```
+
+#### In-browser rendering
+
+Call `katex.render` with a TeX expression and a DOM element to render into:
+
+```js
+katex.render("c = \\pm\\sqrt{a^2 + b^2}", element);
+```
+
+If KaTeX can't parse the expression, it throws a `katex.ParseError` error.
+
+#### Server side rendering or rendering to a string
+
+To generate HTML on the server or to generate an HTML string of the rendered math, you can use `katex.renderToString`:
+
+```js
+var html = katex.renderToString("c = \\pm\\sqrt{a^2 + b^2}");
+// '...'
+```
+
+Make sure to include the CSS and font files, but there is no need to include the JavaScript. Like `render`, `renderToString` throws if it can't parse the expression.
+
+#### Rendering options
+
+You can provide an object of options as the last argument to `katex.render` and `katex.renderToString`. Available options are:
+
+- `displayMode`: `boolean`. If `true` the math will be rendered in display mode, which will put the math in display style (so `\int` and `\sum` are large, for example), and will center the math on the page on its own line. If `false` the math will be rendered in inline mode. (default: `false`)
+- `throwOnError`: `boolean`. If `true`, KaTeX will throw a `ParseError` when it encounters an unsupported command. If `false`, KaTeX will render the unsupported command as text in the color given by `errorColor`. (default: `true`)
+- `errorColor`: `string`. A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option determines the color which unsupported commands are rendered in. (default: `#cc0000`)
+- `macros`: `object`. A collection of custom macros. Each macro is a property with a name like `\name` (written `"\\name"` in JavaScript) which maps to a string that describes the expansion of the macro.
+- `colorIsTextColor`: `boolean`. If `true`, `\color` will work like LaTeX's `\textcolor`, and take two arguments (e.g., `\color{blue}{hello}`), which restores the old behavior of KaTeX (pre-0.8.0). If `false` (the default), `\color` will work like LaTeX's `\color`, and take one argument (e.g., `\color{blue}hello`). In both cases, `\textcolor` works as in LaTeX (e.g., `\textcolor{blue}{hello}`).
+
+For example:
+
+```js
+katex.render("c = \\pm\\sqrt{a^2 + b^2}\\in\\RR", element, {
+ displayMode: true,
+ macros: {
+ "\\RR": "\\mathbb{R}"
+ }
+});
+```
+
+#### Automatic rendering of math on a page
+
+Math on the page can be automatically rendered using the auto-render extension. See [the Auto-render README](contrib/auto-render/README.md) for more information.
+
+#### Font size and lengths
+
+By default, KaTeX math is rendered in a 1.21× larger font than the surrounding
+context, which makes super- and subscripts easier to read. You can control
+this using CSS, for example:
+
+```css
+.katex { font-size: 1.1em; }
+```
+
+KaTeX supports all TeX units, including absolute units like `cm` and `in`.
+Absolute units are currently scaled relative to the default TeX font size of
+10pt, so that `\kern1cm` produces the same results as `\kern2.845275em`.
+As a result, relative and absolute units are both uniformly scaled relative
+to LaTeX with a 10pt font; for example, the rectangle `\rule{1cm}{1em}` has
+the same aspect ratio in KaTeX as in LaTeX. However, because most browsers
+default to a larger font size, this typically means that a 1cm kern in KaTeX
+will appear larger than 1cm in browser units.
+
+## Contributing
+
+See [CONTRIBUTING.md](CONTRIBUTING.md)
+
+## License
+
+KaTeX is licensed under the [MIT License](http://opensource.org/licenses/MIT).
diff --git a/static/katex/contrib/auto-render.min.js b/static/katex/contrib/auto-render.min.js
new file mode 100644
index 00000000..96e1ddec
--- /dev/null
+++ b/static/katex/contrib/auto-render.min.js
@@ -0,0 +1 @@
+(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.renderMathInElement=e()}})(function(){var e,t,n;return function e(t,n,r){function o(c,a){if(!n[c]){if(!t[c]){var u=typeof require=="function"&&require;if(!a&&u)return u(c,!0);if(i)return i(c,!0);var f=new Error("Cannot find module '"+c+"'");throw f.code="MODULE_NOT_FOUND",f}var s=n[c]={exports:{}};t[c][0].call(s.exports,function(e){var n=t[c][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[c].exports}var i=typeof require=="function"&&require;for(var c=0;cf){s=a[f++];if(s!=s)return true}else for(;u>f;f++)if(e||f in a){if(a[f]===n)return e||f||0}return!e&&-1}}},{"./_to-index":32,"./_to-iobject":34,"./_to-length":35}],8:[function(e,t,n){var r={}.toString;t.exports=function(e){return r.call(e).slice(8,-1)}},{}],9:[function(e,t,n){var r=t.exports={version:"2.4.0"};if(typeof __e=="number")__e=r},{}],10:[function(e,t,n){var r=e("./_a-function");t.exports=function(e,t,n){r(e);if(t===undefined)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,o){return e.call(t,n,r,o)}}return function(){return e.apply(t,arguments)}}},{"./_a-function":5}],11:[function(e,t,n){t.exports=function(e){if(e==undefined)throw TypeError("Can't call method on "+e);return e}},{}],12:[function(e,t,n){t.exports=!e("./_fails")(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7})},{"./_fails":16}],13:[function(e,t,n){var r=e("./_is-object"),o=e("./_global").document,i=r(o)&&r(o.createElement);t.exports=function(e){return i?o.createElement(e):{}}},{"./_global":17,"./_is-object":22}],14:[function(e,t,n){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},{}],15:[function(e,t,n){var r=e("./_global"),o=e("./_core"),i=e("./_ctx"),c=e("./_hide"),a="prototype";var u=function(e,t,n){var f=e&u.F,s=e&u.G,l=e&u.S,p=e&u.P,d=e&u.B,_=e&u.W,v=s?o:o[t]||(o[t]={}),h=v[a],b=s?r:l?r[t]:(r[t]||{})[a],y,g,x;if(s)n=t;for(y in n){g=!f&&b&&b[y]!==undefined;if(g&&y in v)continue;x=g?b[y]:n[y];v[y]=s&&typeof b[y]!="function"?n[y]:d&&g?i(x,r):_&&b[y]==x?function(e){var t=function(t,n,r){if(this instanceof e){switch(arguments.length){case 0:return new e;case 1:return new e(t);case 2:return new e(t,n)}return new e(t,n,r)}return e.apply(this,arguments)};t[a]=e[a];return t}(x):p&&typeof x=="function"?i(Function.call,x):x;if(p){(v.virtual||(v.virtual={}))[y]=x;if(e&u.R&&h&&!h[y])c(h,y,x)}}};u.F=1;u.G=2;u.S=4;u.P=8;u.B=16;u.W=32;u.U=64;u.R=128;t.exports=u},{"./_core":9,"./_ctx":10,"./_global":17,"./_hide":19}],16:[function(e,t,n){t.exports=function(e){try{return!!e()}catch(e){return true}}},{}],17:[function(e,t,n){var r=t.exports=typeof window!="undefined"&&window.Math==Math?window:typeof self!="undefined"&&self.Math==Math?self:Function("return this")();if(typeof __g=="number")__g=r},{}],18:[function(e,t,n){var r={}.hasOwnProperty;t.exports=function(e,t){return r.call(e,t)}},{}],19:[function(e,t,n){var r=e("./_object-dp"),o=e("./_property-desc");t.exports=e("./_descriptors")?function(e,t,n){return r.f(e,t,o(1,n))}:function(e,t,n){e[t]=n;return e}},{"./_descriptors":12,"./_object-dp":24,"./_property-desc":29}],20:[function(e,t,n){t.exports=!e("./_descriptors")&&!e("./_fails")(function(){return Object.defineProperty(e("./_dom-create")("div"),"a",{get:function(){return 7}}).a!=7})},{"./_descriptors":12,"./_dom-create":13,"./_fails":16}],21:[function(e,t,n){var r=e("./_cof");t.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return r(e)=="String"?e.split(""):Object(e)}},{"./_cof":8}],22:[function(e,t,n){t.exports=function(e){return typeof e==="object"?e!==null:typeof e==="function"}},{}],23:[function(e,t,n){"use strict";var r=e("./_object-keys"),o=e("./_object-gops"),i=e("./_object-pie"),c=e("./_to-object"),a=e("./_iobject"),u=Object.assign;t.exports=!u||e("./_fails")(function(){var e={},t={},n=Symbol(),r="abcdefghijklmnopqrst";e[n]=7;r.split("").forEach(function(e){t[e]=e});return u({},e)[n]!=7||Object.keys(u({},t)).join("")!=r})?function e(t,n){var u=c(t),f=arguments.length,s=1,l=o.f,p=i.f;while(f>s){var d=a(arguments[s++]),_=l?r(d).concat(l(d)):r(d),v=_.length,h=0,b;while(v>h)if(p.call(d,b=_[h++]))u[b]=d[b]}return u}:u},{"./_fails":16,"./_iobject":21,"./_object-gops":25,"./_object-keys":27,"./_object-pie":28,"./_to-object":36}],24:[function(e,t,n){var r=e("./_an-object"),o=e("./_ie8-dom-define"),i=e("./_to-primitive"),c=Object.defineProperty;n.f=e("./_descriptors")?Object.defineProperty:function e(t,n,a){r(t);n=i(n,true);r(a);if(o)try{return c(t,n,a)}catch(e){}if("get"in a||"set"in a)throw TypeError("Accessors not supported!");if("value"in a)t[n]=a.value;return t}},{"./_an-object":6,"./_descriptors":12,"./_ie8-dom-define":20,"./_to-primitive":37}],25:[function(e,t,n){n.f=Object.getOwnPropertySymbols},{}],26:[function(e,t,n){var r=e("./_has"),o=e("./_to-iobject"),i=e("./_array-includes")(false),c=e("./_shared-key")("IE_PROTO");t.exports=function(e,t){var n=o(e),a=0,u=[],f;for(f in n)if(f!=c)r(n,f)&&u.push(f);while(t.length>a)if(r(n,f=t[a++])){~i(u,f)||u.push(f)}return u}},{"./_array-includes":7,"./_has":18,"./_shared-key":30,"./_to-iobject":34}],27:[function(e,t,n){var r=e("./_object-keys-internal"),o=e("./_enum-bug-keys");t.exports=Object.keys||function e(t){return r(t,o)}},{"./_enum-bug-keys":14,"./_object-keys-internal":26}],28:[function(e,t,n){n.f={}.propertyIsEnumerable},{}],29:[function(e,t,n){t.exports=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}}},{}],30:[function(e,t,n){var r=e("./_shared")("keys"),o=e("./_uid");t.exports=function(e){return r[e]||(r[e]=o(e))}},{"./_shared":31,"./_uid":38}],31:[function(e,t,n){var r=e("./_global"),o="__core-js_shared__",i=r[o]||(r[o]={});t.exports=function(e){return i[e]||(i[e]={})}},{"./_global":17}],32:[function(e,t,n){var r=e("./_to-integer"),o=Math.max,i=Math.min;t.exports=function(e,t){e=r(e);return e<0?o(e+t,0):i(e,t)}},{"./_to-integer":33}],33:[function(e,t,n){var r=Math.ceil,o=Math.floor;t.exports=function(e){return isNaN(e=+e)?0:(e>0?o:r)(e)}},{}],34:[function(e,t,n){var r=e("./_iobject"),o=e("./_defined");t.exports=function(e){return r(o(e))}},{"./_defined":11,"./_iobject":21}],35:[function(e,t,n){var r=e("./_to-integer"),o=Math.min;t.exports=function(e){return e>0?o(r(e),9007199254740991):0}},{"./_to-integer":33}],36:[function(e,t,n){var r=e("./_defined");t.exports=function(e){return Object(r(e))}},{"./_defined":11}],37:[function(e,t,n){var r=e("./_is-object");t.exports=function(e,t){if(!r(e))return e;var n,o;if(t&&typeof(n=e.toString)=="function"&&!r(o=n.call(e)))return o;if(typeof(n=e.valueOf)=="function"&&!r(o=n.call(e)))return o;if(!t&&typeof(n=e.toString)=="function"&&!r(o=n.call(e)))return o;throw TypeError("Can't convert object to primitive value")}},{"./_is-object":22}],38:[function(e,t,n){var r=0,o=Math.random();t.exports=function(e){return"Symbol(".concat(e===undefined?"":e,")_",(++r+o).toString(36))}},{}],39:[function(e,t,n){var r=e("./_export");r(r.S+r.F,"Object",{assign:e("./_object-assign")})},{"./_export":15,"./_object-assign":23}]},{},[1])(1)});
diff --git a/static/katex/fonts/KaTeX_AMS-Regular.eot b/static/katex/fonts/KaTeX_AMS-Regular.eot
new file mode 100644
index 00000000..784276a3
Binary files /dev/null and b/static/katex/fonts/KaTeX_AMS-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_AMS-Regular.ttf b/static/katex/fonts/KaTeX_AMS-Regular.ttf
new file mode 100644
index 00000000..6f1e0be2
Binary files /dev/null and b/static/katex/fonts/KaTeX_AMS-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_AMS-Regular.woff b/static/katex/fonts/KaTeX_AMS-Regular.woff
new file mode 100644
index 00000000..4dded473
Binary files /dev/null and b/static/katex/fonts/KaTeX_AMS-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_AMS-Regular.woff2 b/static/katex/fonts/KaTeX_AMS-Regular.woff2
new file mode 100644
index 00000000..ea81079c
Binary files /dev/null and b/static/katex/fonts/KaTeX_AMS-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Bold.eot b/static/katex/fonts/KaTeX_Caligraphic-Bold.eot
new file mode 100644
index 00000000..1a0db0c5
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Bold.eot differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Bold.ttf b/static/katex/fonts/KaTeX_Caligraphic-Bold.ttf
new file mode 100644
index 00000000..b94907da
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Bold.ttf differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Bold.woff b/static/katex/fonts/KaTeX_Caligraphic-Bold.woff
new file mode 100644
index 00000000..799fa812
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Bold.woff differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Bold.woff2 b/static/katex/fonts/KaTeX_Caligraphic-Bold.woff2
new file mode 100644
index 00000000..73bb5422
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Bold.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Regular.eot b/static/katex/fonts/KaTeX_Caligraphic-Regular.eot
new file mode 100644
index 00000000..6cc83d09
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Regular.ttf b/static/katex/fonts/KaTeX_Caligraphic-Regular.ttf
new file mode 100644
index 00000000..cf51e202
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Regular.woff b/static/katex/fonts/KaTeX_Caligraphic-Regular.woff
new file mode 100644
index 00000000..f5e5c623
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Caligraphic-Regular.woff2 b/static/katex/fonts/KaTeX_Caligraphic-Regular.woff2
new file mode 100644
index 00000000..dd76d348
Binary files /dev/null and b/static/katex/fonts/KaTeX_Caligraphic-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Bold.eot b/static/katex/fonts/KaTeX_Fraktur-Bold.eot
new file mode 100644
index 00000000..1960b106
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Bold.eot differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Bold.ttf b/static/katex/fonts/KaTeX_Fraktur-Bold.ttf
new file mode 100644
index 00000000..7b0790f1
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Bold.ttf differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Bold.woff b/static/katex/fonts/KaTeX_Fraktur-Bold.woff
new file mode 100644
index 00000000..dc325713
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Bold.woff differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Bold.woff2 b/static/katex/fonts/KaTeX_Fraktur-Bold.woff2
new file mode 100644
index 00000000..fdc42922
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Bold.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Regular.eot b/static/katex/fonts/KaTeX_Fraktur-Regular.eot
new file mode 100644
index 00000000..e4e73796
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Regular.ttf b/static/katex/fonts/KaTeX_Fraktur-Regular.ttf
new file mode 100644
index 00000000..063bc026
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Regular.woff b/static/katex/fonts/KaTeX_Fraktur-Regular.woff
new file mode 100644
index 00000000..c4b18d86
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Fraktur-Regular.woff2 b/static/katex/fonts/KaTeX_Fraktur-Regular.woff2
new file mode 100644
index 00000000..4318d938
Binary files /dev/null and b/static/katex/fonts/KaTeX_Fraktur-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Main-Bold.eot b/static/katex/fonts/KaTeX_Main-Bold.eot
new file mode 100644
index 00000000..80fbd022
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Bold.eot differ
diff --git a/static/katex/fonts/KaTeX_Main-Bold.ttf b/static/katex/fonts/KaTeX_Main-Bold.ttf
new file mode 100644
index 00000000..8e10722a
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Bold.ttf differ
diff --git a/static/katex/fonts/KaTeX_Main-Bold.woff b/static/katex/fonts/KaTeX_Main-Bold.woff
new file mode 100644
index 00000000..43b361a6
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Bold.woff differ
diff --git a/static/katex/fonts/KaTeX_Main-Bold.woff2 b/static/katex/fonts/KaTeX_Main-Bold.woff2
new file mode 100644
index 00000000..af57a96c
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Bold.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Main-Italic.eot b/static/katex/fonts/KaTeX_Main-Italic.eot
new file mode 100644
index 00000000..fc770166
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Italic.eot differ
diff --git a/static/katex/fonts/KaTeX_Main-Italic.ttf b/static/katex/fonts/KaTeX_Main-Italic.ttf
new file mode 100644
index 00000000..d124495d
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Italic.ttf differ
diff --git a/static/katex/fonts/KaTeX_Main-Italic.woff b/static/katex/fonts/KaTeX_Main-Italic.woff
new file mode 100644
index 00000000..e623236b
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Italic.woff differ
diff --git a/static/katex/fonts/KaTeX_Main-Italic.woff2 b/static/katex/fonts/KaTeX_Main-Italic.woff2
new file mode 100644
index 00000000..944e9740
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Italic.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Main-Regular.eot b/static/katex/fonts/KaTeX_Main-Regular.eot
new file mode 100644
index 00000000..dc60c090
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Main-Regular.ttf b/static/katex/fonts/KaTeX_Main-Regular.ttf
new file mode 100644
index 00000000..da5797ff
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Main-Regular.woff b/static/katex/fonts/KaTeX_Main-Regular.woff
new file mode 100644
index 00000000..37db672e
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Main-Regular.woff2 b/static/katex/fonts/KaTeX_Main-Regular.woff2
new file mode 100644
index 00000000..48820424
Binary files /dev/null and b/static/katex/fonts/KaTeX_Main-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Math-BoldItalic.eot b/static/katex/fonts/KaTeX_Math-BoldItalic.eot
new file mode 100644
index 00000000..52c8b8c6
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-BoldItalic.eot differ
diff --git a/static/katex/fonts/KaTeX_Math-BoldItalic.ttf b/static/katex/fonts/KaTeX_Math-BoldItalic.ttf
new file mode 100644
index 00000000..a8b527c7
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-BoldItalic.ttf differ
diff --git a/static/katex/fonts/KaTeX_Math-BoldItalic.woff b/static/katex/fonts/KaTeX_Math-BoldItalic.woff
new file mode 100644
index 00000000..8940e0b5
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-BoldItalic.woff differ
diff --git a/static/katex/fonts/KaTeX_Math-BoldItalic.woff2 b/static/katex/fonts/KaTeX_Math-BoldItalic.woff2
new file mode 100644
index 00000000..15cf56d3
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-BoldItalic.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Math-Italic.eot b/static/katex/fonts/KaTeX_Math-Italic.eot
new file mode 100644
index 00000000..64c8992c
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Italic.eot differ
diff --git a/static/katex/fonts/KaTeX_Math-Italic.ttf b/static/katex/fonts/KaTeX_Math-Italic.ttf
new file mode 100644
index 00000000..06f39d3a
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Italic.ttf differ
diff --git a/static/katex/fonts/KaTeX_Math-Italic.woff b/static/katex/fonts/KaTeX_Math-Italic.woff
new file mode 100644
index 00000000..cf3b4b79
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Italic.woff differ
diff --git a/static/katex/fonts/KaTeX_Math-Italic.woff2 b/static/katex/fonts/KaTeX_Math-Italic.woff2
new file mode 100644
index 00000000..5f8c4bfa
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Italic.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Math-Regular.eot b/static/katex/fonts/KaTeX_Math-Regular.eot
new file mode 100644
index 00000000..5521e6a5
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Math-Regular.ttf b/static/katex/fonts/KaTeX_Math-Regular.ttf
new file mode 100644
index 00000000..73127082
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Math-Regular.woff b/static/katex/fonts/KaTeX_Math-Regular.woff
new file mode 100644
index 00000000..0e2ebdf1
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Math-Regular.woff2 b/static/katex/fonts/KaTeX_Math-Regular.woff2
new file mode 100644
index 00000000..ebe3d028
Binary files /dev/null and b/static/katex/fonts/KaTeX_Math-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Bold.eot b/static/katex/fonts/KaTeX_SansSerif-Bold.eot
new file mode 100644
index 00000000..1660e76a
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Bold.eot differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Bold.ttf b/static/katex/fonts/KaTeX_SansSerif-Bold.ttf
new file mode 100644
index 00000000..dbeb7b92
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Bold.ttf differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Bold.woff b/static/katex/fonts/KaTeX_SansSerif-Bold.woff
new file mode 100644
index 00000000..8f144a8b
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Bold.woff differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Bold.woff2 b/static/katex/fonts/KaTeX_SansSerif-Bold.woff2
new file mode 100644
index 00000000..329e8555
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Bold.woff2 differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Italic.eot b/static/katex/fonts/KaTeX_SansSerif-Italic.eot
new file mode 100644
index 00000000..289ae3ff
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Italic.eot differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Italic.ttf b/static/katex/fonts/KaTeX_SansSerif-Italic.ttf
new file mode 100644
index 00000000..b3a2f38f
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Italic.ttf differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Italic.woff b/static/katex/fonts/KaTeX_SansSerif-Italic.woff
new file mode 100644
index 00000000..bddf7ea6
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Italic.woff differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Italic.woff2 b/static/katex/fonts/KaTeX_SansSerif-Italic.woff2
new file mode 100644
index 00000000..5fa767bd
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Italic.woff2 differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Regular.eot b/static/katex/fonts/KaTeX_SansSerif-Regular.eot
new file mode 100644
index 00000000..1b38b98a
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Regular.ttf b/static/katex/fonts/KaTeX_SansSerif-Regular.ttf
new file mode 100644
index 00000000..e4712f84
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Regular.woff b/static/katex/fonts/KaTeX_SansSerif-Regular.woff
new file mode 100644
index 00000000..33be3680
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_SansSerif-Regular.woff2 b/static/katex/fonts/KaTeX_SansSerif-Regular.woff2
new file mode 100644
index 00000000..4fcb2e29
Binary files /dev/null and b/static/katex/fonts/KaTeX_SansSerif-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Script-Regular.eot b/static/katex/fonts/KaTeX_Script-Regular.eot
new file mode 100644
index 00000000..7870d7f3
Binary files /dev/null and b/static/katex/fonts/KaTeX_Script-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Script-Regular.ttf b/static/katex/fonts/KaTeX_Script-Regular.ttf
new file mode 100644
index 00000000..da4d1130
Binary files /dev/null and b/static/katex/fonts/KaTeX_Script-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Script-Regular.woff b/static/katex/fonts/KaTeX_Script-Regular.woff
new file mode 100644
index 00000000..d6ae79f9
Binary files /dev/null and b/static/katex/fonts/KaTeX_Script-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Script-Regular.woff2 b/static/katex/fonts/KaTeX_Script-Regular.woff2
new file mode 100644
index 00000000..1b43deb4
Binary files /dev/null and b/static/katex/fonts/KaTeX_Script-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Size1-Regular.eot b/static/katex/fonts/KaTeX_Size1-Regular.eot
new file mode 100644
index 00000000..29950f95
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size1-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Size1-Regular.ttf b/static/katex/fonts/KaTeX_Size1-Regular.ttf
new file mode 100644
index 00000000..194466a6
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size1-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Size1-Regular.woff b/static/katex/fonts/KaTeX_Size1-Regular.woff
new file mode 100644
index 00000000..237f271e
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size1-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Size1-Regular.woff2 b/static/katex/fonts/KaTeX_Size1-Regular.woff2
new file mode 100644
index 00000000..39b6f8f7
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size1-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Size2-Regular.eot b/static/katex/fonts/KaTeX_Size2-Regular.eot
new file mode 100644
index 00000000..b8b0536f
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size2-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Size2-Regular.ttf b/static/katex/fonts/KaTeX_Size2-Regular.ttf
new file mode 100644
index 00000000..b41b66a6
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size2-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Size2-Regular.woff b/static/katex/fonts/KaTeX_Size2-Regular.woff
new file mode 100644
index 00000000..4a305585
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size2-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Size2-Regular.woff2 b/static/katex/fonts/KaTeX_Size2-Regular.woff2
new file mode 100644
index 00000000..3facec1a
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size2-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Size3-Regular.eot b/static/katex/fonts/KaTeX_Size3-Regular.eot
new file mode 100644
index 00000000..576b864f
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size3-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Size3-Regular.ttf b/static/katex/fonts/KaTeX_Size3-Regular.ttf
new file mode 100644
index 00000000..790ddbbc
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size3-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Size3-Regular.woff b/static/katex/fonts/KaTeX_Size3-Regular.woff
new file mode 100644
index 00000000..3a6d062e
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size3-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Size3-Regular.woff2 b/static/katex/fonts/KaTeX_Size3-Regular.woff2
new file mode 100644
index 00000000..2cffafe5
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size3-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Size4-Regular.eot b/static/katex/fonts/KaTeX_Size4-Regular.eot
new file mode 100644
index 00000000..c2b045fc
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size4-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Size4-Regular.ttf b/static/katex/fonts/KaTeX_Size4-Regular.ttf
new file mode 100644
index 00000000..ce660aa7
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size4-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Size4-Regular.woff b/static/katex/fonts/KaTeX_Size4-Regular.woff
new file mode 100644
index 00000000..7826c6c9
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size4-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Size4-Regular.woff2 b/static/katex/fonts/KaTeX_Size4-Regular.woff2
new file mode 100644
index 00000000..c9218981
Binary files /dev/null and b/static/katex/fonts/KaTeX_Size4-Regular.woff2 differ
diff --git a/static/katex/fonts/KaTeX_Typewriter-Regular.eot b/static/katex/fonts/KaTeX_Typewriter-Regular.eot
new file mode 100644
index 00000000..4c178f48
Binary files /dev/null and b/static/katex/fonts/KaTeX_Typewriter-Regular.eot differ
diff --git a/static/katex/fonts/KaTeX_Typewriter-Regular.ttf b/static/katex/fonts/KaTeX_Typewriter-Regular.ttf
new file mode 100644
index 00000000..b0427ad0
Binary files /dev/null and b/static/katex/fonts/KaTeX_Typewriter-Regular.ttf differ
diff --git a/static/katex/fonts/KaTeX_Typewriter-Regular.woff b/static/katex/fonts/KaTeX_Typewriter-Regular.woff
new file mode 100644
index 00000000..78e99048
Binary files /dev/null and b/static/katex/fonts/KaTeX_Typewriter-Regular.woff differ
diff --git a/static/katex/fonts/KaTeX_Typewriter-Regular.woff2 b/static/katex/fonts/KaTeX_Typewriter-Regular.woff2
new file mode 100644
index 00000000..618de99d
Binary files /dev/null and b/static/katex/fonts/KaTeX_Typewriter-Regular.woff2 differ
diff --git a/static/katex/katex.css b/static/katex/katex.css
new file mode 100644
index 00000000..ff028dd2
--- /dev/null
+++ b/static/katex/katex.css
@@ -0,0 +1,1074 @@
+@font-face {
+ font-family: 'KaTeX_AMS';
+ src: url('fonts/KaTeX_AMS-Regular.eot');
+ src: url('fonts/KaTeX_AMS-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_AMS-Regular.woff2') format('woff2'), url('fonts/KaTeX_AMS-Regular.woff') format('woff'), url('fonts/KaTeX_AMS-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Caligraphic';
+ src: url('fonts/KaTeX_Caligraphic-Bold.eot');
+ src: url('fonts/KaTeX_Caligraphic-Bold.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Caligraphic-Bold.woff2') format('woff2'), url('fonts/KaTeX_Caligraphic-Bold.woff') format('woff'), url('fonts/KaTeX_Caligraphic-Bold.ttf') format('truetype');
+ font-weight: bold;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Caligraphic';
+ src: url('fonts/KaTeX_Caligraphic-Regular.eot');
+ src: url('fonts/KaTeX_Caligraphic-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Caligraphic-Regular.woff2') format('woff2'), url('fonts/KaTeX_Caligraphic-Regular.woff') format('woff'), url('fonts/KaTeX_Caligraphic-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Fraktur';
+ src: url('fonts/KaTeX_Fraktur-Bold.eot');
+ src: url('fonts/KaTeX_Fraktur-Bold.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Fraktur-Bold.woff2') format('woff2'), url('fonts/KaTeX_Fraktur-Bold.woff') format('woff'), url('fonts/KaTeX_Fraktur-Bold.ttf') format('truetype');
+ font-weight: bold;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Fraktur';
+ src: url('fonts/KaTeX_Fraktur-Regular.eot');
+ src: url('fonts/KaTeX_Fraktur-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Fraktur-Regular.woff2') format('woff2'), url('fonts/KaTeX_Fraktur-Regular.woff') format('woff'), url('fonts/KaTeX_Fraktur-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Main';
+ src: url('fonts/KaTeX_Main-Bold.eot');
+ src: url('fonts/KaTeX_Main-Bold.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Main-Bold.woff2') format('woff2'), url('fonts/KaTeX_Main-Bold.woff') format('woff'), url('fonts/KaTeX_Main-Bold.ttf') format('truetype');
+ font-weight: bold;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Main';
+ src: url('fonts/KaTeX_Main-Italic.eot');
+ src: url('fonts/KaTeX_Main-Italic.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Main-Italic.woff2') format('woff2'), url('fonts/KaTeX_Main-Italic.woff') format('woff'), url('fonts/KaTeX_Main-Italic.ttf') format('truetype');
+ font-weight: normal;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'KaTeX_Main';
+ src: url('fonts/KaTeX_Main-Regular.eot');
+ src: url('fonts/KaTeX_Main-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Main-Regular.woff2') format('woff2'), url('fonts/KaTeX_Main-Regular.woff') format('woff'), url('fonts/KaTeX_Main-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Math';
+ src: url('fonts/KaTeX_Math-Italic.eot');
+ src: url('fonts/KaTeX_Math-Italic.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Math-Italic.woff2') format('woff2'), url('fonts/KaTeX_Math-Italic.woff') format('woff'), url('fonts/KaTeX_Math-Italic.ttf') format('truetype');
+ font-weight: normal;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'KaTeX_SansSerif';
+ src: url('fonts/KaTeX_SansSerif-Regular.eot');
+ src: url('fonts/KaTeX_SansSerif-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_SansSerif-Regular.woff2') format('woff2'), url('fonts/KaTeX_SansSerif-Regular.woff') format('woff'), url('fonts/KaTeX_SansSerif-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Script';
+ src: url('fonts/KaTeX_Script-Regular.eot');
+ src: url('fonts/KaTeX_Script-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Script-Regular.woff2') format('woff2'), url('fonts/KaTeX_Script-Regular.woff') format('woff'), url('fonts/KaTeX_Script-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Size1';
+ src: url('fonts/KaTeX_Size1-Regular.eot');
+ src: url('fonts/KaTeX_Size1-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Size1-Regular.woff2') format('woff2'), url('fonts/KaTeX_Size1-Regular.woff') format('woff'), url('fonts/KaTeX_Size1-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Size2';
+ src: url('fonts/KaTeX_Size2-Regular.eot');
+ src: url('fonts/KaTeX_Size2-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Size2-Regular.woff2') format('woff2'), url('fonts/KaTeX_Size2-Regular.woff') format('woff'), url('fonts/KaTeX_Size2-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Size3';
+ src: url('fonts/KaTeX_Size3-Regular.eot');
+ src: url('fonts/KaTeX_Size3-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Size3-Regular.woff2') format('woff2'), url('fonts/KaTeX_Size3-Regular.woff') format('woff'), url('fonts/KaTeX_Size3-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Size4';
+ src: url('fonts/KaTeX_Size4-Regular.eot');
+ src: url('fonts/KaTeX_Size4-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Size4-Regular.woff2') format('woff2'), url('fonts/KaTeX_Size4-Regular.woff') format('woff'), url('fonts/KaTeX_Size4-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'KaTeX_Typewriter';
+ src: url('fonts/KaTeX_Typewriter-Regular.eot');
+ src: url('fonts/KaTeX_Typewriter-Regular.eot#iefix') format('embedded-opentype'), url('fonts/KaTeX_Typewriter-Regular.woff2') format('woff2'), url('fonts/KaTeX_Typewriter-Regular.woff') format('woff'), url('fonts/KaTeX_Typewriter-Regular.ttf') format('truetype');
+ font-weight: normal;
+ font-style: normal;
+}
+.katex-display {
+ display: block;
+ margin: 1em 0;
+ text-align: center;
+}
+.katex-display > .katex {
+ display: inline-block;
+ text-align: initial;
+}
+.katex {
+ font: normal 1.21em KaTeX_Main, Times New Roman, serif;
+ line-height: 1.2;
+ white-space: nowrap;
+ text-indent: 0;
+ text-rendering: auto;
+}
+.katex * {
+ -ms-high-contrast-adjust: none !important;
+}
+.katex .katex-html {
+ display: inline-block;
+}
+.katex .katex-mathml {
+ position: absolute;
+ clip: rect(1px, 1px, 1px, 1px);
+ padding: 0;
+ border: 0;
+ height: 1px;
+ width: 1px;
+ overflow: hidden;
+}
+.katex .base {
+ position: relative;
+ display: inline-block;
+}
+.katex .strut {
+ display: inline-block;
+}
+.katex .mathrm {
+ font-style: normal;
+}
+.katex .textit {
+ font-style: italic;
+}
+.katex .mathit {
+ font-family: KaTeX_Math;
+ font-style: italic;
+}
+.katex .mathbf {
+ font-family: KaTeX_Main;
+ font-weight: bold;
+}
+.katex .amsrm {
+ font-family: KaTeX_AMS;
+}
+.katex .mathbb {
+ font-family: KaTeX_AMS;
+}
+.katex .mathcal {
+ font-family: KaTeX_Caligraphic;
+}
+.katex .mathfrak {
+ font-family: KaTeX_Fraktur;
+}
+.katex .mathtt {
+ font-family: KaTeX_Typewriter;
+}
+.katex .mathscr {
+ font-family: KaTeX_Script;
+}
+.katex .mathsf {
+ font-family: KaTeX_SansSerif;
+}
+.katex .mainit {
+ font-family: KaTeX_Main;
+ font-style: italic;
+}
+.katex .mainrm {
+ font-family: KaTeX_Main;
+ font-style: normal;
+}
+.katex .mord + .mop {
+ margin-left: 0.16667em;
+}
+.katex .mord + .mbin {
+ margin-left: 0.22222em;
+}
+.katex .mord + .mrel {
+ margin-left: 0.27778em;
+}
+.katex .mord + .minner {
+ margin-left: 0.16667em;
+}
+.katex .mop + .mord {
+ margin-left: 0.16667em;
+}
+.katex .mop + .mop {
+ margin-left: 0.16667em;
+}
+.katex .mop + .mrel {
+ margin-left: 0.27778em;
+}
+.katex .mop + .minner {
+ margin-left: 0.16667em;
+}
+.katex .mbin + .mord {
+ margin-left: 0.22222em;
+}
+.katex .mbin + .mop {
+ margin-left: 0.22222em;
+}
+.katex .mbin + .mopen {
+ margin-left: 0.22222em;
+}
+.katex .mbin + .minner {
+ margin-left: 0.22222em;
+}
+.katex .mrel + .mord {
+ margin-left: 0.27778em;
+}
+.katex .mrel + .mop {
+ margin-left: 0.27778em;
+}
+.katex .mrel + .mopen {
+ margin-left: 0.27778em;
+}
+.katex .mrel + .minner {
+ margin-left: 0.27778em;
+}
+.katex .mclose + .mop {
+ margin-left: 0.16667em;
+}
+.katex .mclose + .mbin {
+ margin-left: 0.22222em;
+}
+.katex .mclose + .mrel {
+ margin-left: 0.27778em;
+}
+.katex .mclose + .minner {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .mord {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .mop {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .mrel {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .mopen {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .mclose {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .mpunct {
+ margin-left: 0.16667em;
+}
+.katex .mpunct + .minner {
+ margin-left: 0.16667em;
+}
+.katex .minner + .mord {
+ margin-left: 0.16667em;
+}
+.katex .minner + .mop {
+ margin-left: 0.16667em;
+}
+.katex .minner + .mbin {
+ margin-left: 0.22222em;
+}
+.katex .minner + .mrel {
+ margin-left: 0.27778em;
+}
+.katex .minner + .mopen {
+ margin-left: 0.16667em;
+}
+.katex .minner + .mpunct {
+ margin-left: 0.16667em;
+}
+.katex .minner + .minner {
+ margin-left: 0.16667em;
+}
+.katex .mord.mtight {
+ margin-left: 0;
+}
+.katex .mop.mtight {
+ margin-left: 0;
+}
+.katex .mbin.mtight {
+ margin-left: 0;
+}
+.katex .mrel.mtight {
+ margin-left: 0;
+}
+.katex .mopen.mtight {
+ margin-left: 0;
+}
+.katex .mclose.mtight {
+ margin-left: 0;
+}
+.katex .mpunct.mtight {
+ margin-left: 0;
+}
+.katex .minner.mtight {
+ margin-left: 0;
+}
+.katex .mord + .mop.mtight {
+ margin-left: 0.16667em;
+}
+.katex .mop + .mord.mtight {
+ margin-left: 0.16667em;
+}
+.katex .mop + .mop.mtight {
+ margin-left: 0.16667em;
+}
+.katex .mclose + .mop.mtight {
+ margin-left: 0.16667em;
+}
+.katex .minner + .mop.mtight {
+ margin-left: 0.16667em;
+}
+.katex .vlist-t {
+ display: inline-table;
+ table-layout: fixed;
+}
+.katex .vlist-r {
+ display: table-row;
+}
+.katex .vlist {
+ display: table-cell;
+ vertical-align: bottom;
+ position: relative;
+}
+.katex .vlist > span {
+ display: block;
+ height: 0;
+ position: relative;
+}
+.katex .vlist > span > span {
+ display: inline-block;
+}
+.katex .vlist > span > .pstrut {
+ overflow: hidden;
+ width: 0;
+}
+.katex .vlist-t2 {
+ margin-right: -2px;
+}
+.katex .vlist-s {
+ display: table-cell;
+ vertical-align: bottom;
+ font-size: 1px;
+ width: 2px;
+}
+.katex .msupsub {
+ text-align: left;
+}
+.katex .mfrac > span > span {
+ text-align: center;
+}
+.katex .mfrac .frac-line {
+ display: inline-block;
+ width: 100%;
+ border-bottom-style: solid;
+}
+.katex .mspace {
+ display: inline-block;
+}
+.katex .mspace.negativethinspace {
+ margin-left: -0.16667em;
+}
+.katex .mspace.thinspace {
+ width: 0.16667em;
+}
+.katex .mspace.negativemediumspace {
+ margin-left: -0.22222em;
+}
+.katex .mspace.mediumspace {
+ width: 0.22222em;
+}
+.katex .mspace.thickspace {
+ width: 0.27778em;
+}
+.katex .mspace.sixmuspace {
+ width: 0.333333em;
+}
+.katex .mspace.eightmuspace {
+ width: 0.444444em;
+}
+.katex .mspace.enspace {
+ width: 0.5em;
+}
+.katex .mspace.twelvemuspace {
+ width: 0.666667em;
+}
+.katex .mspace.quad {
+ width: 1em;
+}
+.katex .mspace.qquad {
+ width: 2em;
+}
+.katex .llap,
+.katex .rlap {
+ width: 0;
+ position: relative;
+}
+.katex .llap > .inner,
+.katex .rlap > .inner {
+ position: absolute;
+}
+.katex .llap > .fix,
+.katex .rlap > .fix {
+ display: inline-block;
+}
+.katex .llap > .inner {
+ right: 0;
+}
+.katex .rlap > .inner {
+ left: 0;
+}
+.katex .katex-logo .a {
+ font-size: 0.75em;
+ margin-left: -0.32em;
+ position: relative;
+ top: -0.2em;
+}
+.katex .katex-logo .t {
+ margin-left: -0.23em;
+}
+.katex .katex-logo .e {
+ margin-left: -0.1667em;
+ position: relative;
+ top: 0.2155em;
+}
+.katex .katex-logo .x {
+ margin-left: -0.125em;
+}
+.katex .rule {
+ display: inline-block;
+ border: solid 0;
+ position: relative;
+}
+.katex .overline .overline-line,
+.katex .underline .underline-line {
+ display: inline-block;
+ width: 100%;
+ border-bottom-style: solid;
+}
+.katex .sqrt > .root {
+ margin-left: 0.27777778em;
+ margin-right: -0.55555556em;
+}
+.katex .sizing,
+.katex .fontsize-ensurer {
+ display: inline-block;
+}
+.katex .sizing.reset-size1.size1,
+.katex .fontsize-ensurer.reset-size1.size1 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size1.size2,
+.katex .fontsize-ensurer.reset-size1.size2 {
+ font-size: 1.2em;
+}
+.katex .sizing.reset-size1.size3,
+.katex .fontsize-ensurer.reset-size1.size3 {
+ font-size: 1.4em;
+}
+.katex .sizing.reset-size1.size4,
+.katex .fontsize-ensurer.reset-size1.size4 {
+ font-size: 1.6em;
+}
+.katex .sizing.reset-size1.size5,
+.katex .fontsize-ensurer.reset-size1.size5 {
+ font-size: 1.8em;
+}
+.katex .sizing.reset-size1.size6,
+.katex .fontsize-ensurer.reset-size1.size6 {
+ font-size: 2em;
+}
+.katex .sizing.reset-size1.size7,
+.katex .fontsize-ensurer.reset-size1.size7 {
+ font-size: 2.4em;
+}
+.katex .sizing.reset-size1.size8,
+.katex .fontsize-ensurer.reset-size1.size8 {
+ font-size: 2.88em;
+}
+.katex .sizing.reset-size1.size9,
+.katex .fontsize-ensurer.reset-size1.size9 {
+ font-size: 3.456em;
+}
+.katex .sizing.reset-size1.size10,
+.katex .fontsize-ensurer.reset-size1.size10 {
+ font-size: 4.148em;
+}
+.katex .sizing.reset-size1.size11,
+.katex .fontsize-ensurer.reset-size1.size11 {
+ font-size: 4.976em;
+}
+.katex .sizing.reset-size2.size1,
+.katex .fontsize-ensurer.reset-size2.size1 {
+ font-size: 0.83333333em;
+}
+.katex .sizing.reset-size2.size2,
+.katex .fontsize-ensurer.reset-size2.size2 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size2.size3,
+.katex .fontsize-ensurer.reset-size2.size3 {
+ font-size: 1.16666667em;
+}
+.katex .sizing.reset-size2.size4,
+.katex .fontsize-ensurer.reset-size2.size4 {
+ font-size: 1.33333333em;
+}
+.katex .sizing.reset-size2.size5,
+.katex .fontsize-ensurer.reset-size2.size5 {
+ font-size: 1.5em;
+}
+.katex .sizing.reset-size2.size6,
+.katex .fontsize-ensurer.reset-size2.size6 {
+ font-size: 1.66666667em;
+}
+.katex .sizing.reset-size2.size7,
+.katex .fontsize-ensurer.reset-size2.size7 {
+ font-size: 2em;
+}
+.katex .sizing.reset-size2.size8,
+.katex .fontsize-ensurer.reset-size2.size8 {
+ font-size: 2.4em;
+}
+.katex .sizing.reset-size2.size9,
+.katex .fontsize-ensurer.reset-size2.size9 {
+ font-size: 2.88em;
+}
+.katex .sizing.reset-size2.size10,
+.katex .fontsize-ensurer.reset-size2.size10 {
+ font-size: 3.45666667em;
+}
+.katex .sizing.reset-size2.size11,
+.katex .fontsize-ensurer.reset-size2.size11 {
+ font-size: 4.14666667em;
+}
+.katex .sizing.reset-size3.size1,
+.katex .fontsize-ensurer.reset-size3.size1 {
+ font-size: 0.71428571em;
+}
+.katex .sizing.reset-size3.size2,
+.katex .fontsize-ensurer.reset-size3.size2 {
+ font-size: 0.85714286em;
+}
+.katex .sizing.reset-size3.size3,
+.katex .fontsize-ensurer.reset-size3.size3 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size3.size4,
+.katex .fontsize-ensurer.reset-size3.size4 {
+ font-size: 1.14285714em;
+}
+.katex .sizing.reset-size3.size5,
+.katex .fontsize-ensurer.reset-size3.size5 {
+ font-size: 1.28571429em;
+}
+.katex .sizing.reset-size3.size6,
+.katex .fontsize-ensurer.reset-size3.size6 {
+ font-size: 1.42857143em;
+}
+.katex .sizing.reset-size3.size7,
+.katex .fontsize-ensurer.reset-size3.size7 {
+ font-size: 1.71428571em;
+}
+.katex .sizing.reset-size3.size8,
+.katex .fontsize-ensurer.reset-size3.size8 {
+ font-size: 2.05714286em;
+}
+.katex .sizing.reset-size3.size9,
+.katex .fontsize-ensurer.reset-size3.size9 {
+ font-size: 2.46857143em;
+}
+.katex .sizing.reset-size3.size10,
+.katex .fontsize-ensurer.reset-size3.size10 {
+ font-size: 2.96285714em;
+}
+.katex .sizing.reset-size3.size11,
+.katex .fontsize-ensurer.reset-size3.size11 {
+ font-size: 3.55428571em;
+}
+.katex .sizing.reset-size4.size1,
+.katex .fontsize-ensurer.reset-size4.size1 {
+ font-size: 0.625em;
+}
+.katex .sizing.reset-size4.size2,
+.katex .fontsize-ensurer.reset-size4.size2 {
+ font-size: 0.75em;
+}
+.katex .sizing.reset-size4.size3,
+.katex .fontsize-ensurer.reset-size4.size3 {
+ font-size: 0.875em;
+}
+.katex .sizing.reset-size4.size4,
+.katex .fontsize-ensurer.reset-size4.size4 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size4.size5,
+.katex .fontsize-ensurer.reset-size4.size5 {
+ font-size: 1.125em;
+}
+.katex .sizing.reset-size4.size6,
+.katex .fontsize-ensurer.reset-size4.size6 {
+ font-size: 1.25em;
+}
+.katex .sizing.reset-size4.size7,
+.katex .fontsize-ensurer.reset-size4.size7 {
+ font-size: 1.5em;
+}
+.katex .sizing.reset-size4.size8,
+.katex .fontsize-ensurer.reset-size4.size8 {
+ font-size: 1.8em;
+}
+.katex .sizing.reset-size4.size9,
+.katex .fontsize-ensurer.reset-size4.size9 {
+ font-size: 2.16em;
+}
+.katex .sizing.reset-size4.size10,
+.katex .fontsize-ensurer.reset-size4.size10 {
+ font-size: 2.5925em;
+}
+.katex .sizing.reset-size4.size11,
+.katex .fontsize-ensurer.reset-size4.size11 {
+ font-size: 3.11em;
+}
+.katex .sizing.reset-size5.size1,
+.katex .fontsize-ensurer.reset-size5.size1 {
+ font-size: 0.55555556em;
+}
+.katex .sizing.reset-size5.size2,
+.katex .fontsize-ensurer.reset-size5.size2 {
+ font-size: 0.66666667em;
+}
+.katex .sizing.reset-size5.size3,
+.katex .fontsize-ensurer.reset-size5.size3 {
+ font-size: 0.77777778em;
+}
+.katex .sizing.reset-size5.size4,
+.katex .fontsize-ensurer.reset-size5.size4 {
+ font-size: 0.88888889em;
+}
+.katex .sizing.reset-size5.size5,
+.katex .fontsize-ensurer.reset-size5.size5 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size5.size6,
+.katex .fontsize-ensurer.reset-size5.size6 {
+ font-size: 1.11111111em;
+}
+.katex .sizing.reset-size5.size7,
+.katex .fontsize-ensurer.reset-size5.size7 {
+ font-size: 1.33333333em;
+}
+.katex .sizing.reset-size5.size8,
+.katex .fontsize-ensurer.reset-size5.size8 {
+ font-size: 1.6em;
+}
+.katex .sizing.reset-size5.size9,
+.katex .fontsize-ensurer.reset-size5.size9 {
+ font-size: 1.92em;
+}
+.katex .sizing.reset-size5.size10,
+.katex .fontsize-ensurer.reset-size5.size10 {
+ font-size: 2.30444444em;
+}
+.katex .sizing.reset-size5.size11,
+.katex .fontsize-ensurer.reset-size5.size11 {
+ font-size: 2.76444444em;
+}
+.katex .sizing.reset-size6.size1,
+.katex .fontsize-ensurer.reset-size6.size1 {
+ font-size: 0.5em;
+}
+.katex .sizing.reset-size6.size2,
+.katex .fontsize-ensurer.reset-size6.size2 {
+ font-size: 0.6em;
+}
+.katex .sizing.reset-size6.size3,
+.katex .fontsize-ensurer.reset-size6.size3 {
+ font-size: 0.7em;
+}
+.katex .sizing.reset-size6.size4,
+.katex .fontsize-ensurer.reset-size6.size4 {
+ font-size: 0.8em;
+}
+.katex .sizing.reset-size6.size5,
+.katex .fontsize-ensurer.reset-size6.size5 {
+ font-size: 0.9em;
+}
+.katex .sizing.reset-size6.size6,
+.katex .fontsize-ensurer.reset-size6.size6 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size6.size7,
+.katex .fontsize-ensurer.reset-size6.size7 {
+ font-size: 1.2em;
+}
+.katex .sizing.reset-size6.size8,
+.katex .fontsize-ensurer.reset-size6.size8 {
+ font-size: 1.44em;
+}
+.katex .sizing.reset-size6.size9,
+.katex .fontsize-ensurer.reset-size6.size9 {
+ font-size: 1.728em;
+}
+.katex .sizing.reset-size6.size10,
+.katex .fontsize-ensurer.reset-size6.size10 {
+ font-size: 2.074em;
+}
+.katex .sizing.reset-size6.size11,
+.katex .fontsize-ensurer.reset-size6.size11 {
+ font-size: 2.488em;
+}
+.katex .sizing.reset-size7.size1,
+.katex .fontsize-ensurer.reset-size7.size1 {
+ font-size: 0.41666667em;
+}
+.katex .sizing.reset-size7.size2,
+.katex .fontsize-ensurer.reset-size7.size2 {
+ font-size: 0.5em;
+}
+.katex .sizing.reset-size7.size3,
+.katex .fontsize-ensurer.reset-size7.size3 {
+ font-size: 0.58333333em;
+}
+.katex .sizing.reset-size7.size4,
+.katex .fontsize-ensurer.reset-size7.size4 {
+ font-size: 0.66666667em;
+}
+.katex .sizing.reset-size7.size5,
+.katex .fontsize-ensurer.reset-size7.size5 {
+ font-size: 0.75em;
+}
+.katex .sizing.reset-size7.size6,
+.katex .fontsize-ensurer.reset-size7.size6 {
+ font-size: 0.83333333em;
+}
+.katex .sizing.reset-size7.size7,
+.katex .fontsize-ensurer.reset-size7.size7 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size7.size8,
+.katex .fontsize-ensurer.reset-size7.size8 {
+ font-size: 1.2em;
+}
+.katex .sizing.reset-size7.size9,
+.katex .fontsize-ensurer.reset-size7.size9 {
+ font-size: 1.44em;
+}
+.katex .sizing.reset-size7.size10,
+.katex .fontsize-ensurer.reset-size7.size10 {
+ font-size: 1.72833333em;
+}
+.katex .sizing.reset-size7.size11,
+.katex .fontsize-ensurer.reset-size7.size11 {
+ font-size: 2.07333333em;
+}
+.katex .sizing.reset-size8.size1,
+.katex .fontsize-ensurer.reset-size8.size1 {
+ font-size: 0.34722222em;
+}
+.katex .sizing.reset-size8.size2,
+.katex .fontsize-ensurer.reset-size8.size2 {
+ font-size: 0.41666667em;
+}
+.katex .sizing.reset-size8.size3,
+.katex .fontsize-ensurer.reset-size8.size3 {
+ font-size: 0.48611111em;
+}
+.katex .sizing.reset-size8.size4,
+.katex .fontsize-ensurer.reset-size8.size4 {
+ font-size: 0.55555556em;
+}
+.katex .sizing.reset-size8.size5,
+.katex .fontsize-ensurer.reset-size8.size5 {
+ font-size: 0.625em;
+}
+.katex .sizing.reset-size8.size6,
+.katex .fontsize-ensurer.reset-size8.size6 {
+ font-size: 0.69444444em;
+}
+.katex .sizing.reset-size8.size7,
+.katex .fontsize-ensurer.reset-size8.size7 {
+ font-size: 0.83333333em;
+}
+.katex .sizing.reset-size8.size8,
+.katex .fontsize-ensurer.reset-size8.size8 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size8.size9,
+.katex .fontsize-ensurer.reset-size8.size9 {
+ font-size: 1.2em;
+}
+.katex .sizing.reset-size8.size10,
+.katex .fontsize-ensurer.reset-size8.size10 {
+ font-size: 1.44027778em;
+}
+.katex .sizing.reset-size8.size11,
+.katex .fontsize-ensurer.reset-size8.size11 {
+ font-size: 1.72777778em;
+}
+.katex .sizing.reset-size9.size1,
+.katex .fontsize-ensurer.reset-size9.size1 {
+ font-size: 0.28935185em;
+}
+.katex .sizing.reset-size9.size2,
+.katex .fontsize-ensurer.reset-size9.size2 {
+ font-size: 0.34722222em;
+}
+.katex .sizing.reset-size9.size3,
+.katex .fontsize-ensurer.reset-size9.size3 {
+ font-size: 0.40509259em;
+}
+.katex .sizing.reset-size9.size4,
+.katex .fontsize-ensurer.reset-size9.size4 {
+ font-size: 0.46296296em;
+}
+.katex .sizing.reset-size9.size5,
+.katex .fontsize-ensurer.reset-size9.size5 {
+ font-size: 0.52083333em;
+}
+.katex .sizing.reset-size9.size6,
+.katex .fontsize-ensurer.reset-size9.size6 {
+ font-size: 0.5787037em;
+}
+.katex .sizing.reset-size9.size7,
+.katex .fontsize-ensurer.reset-size9.size7 {
+ font-size: 0.69444444em;
+}
+.katex .sizing.reset-size9.size8,
+.katex .fontsize-ensurer.reset-size9.size8 {
+ font-size: 0.83333333em;
+}
+.katex .sizing.reset-size9.size9,
+.katex .fontsize-ensurer.reset-size9.size9 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size9.size10,
+.katex .fontsize-ensurer.reset-size9.size10 {
+ font-size: 1.20023148em;
+}
+.katex .sizing.reset-size9.size11,
+.katex .fontsize-ensurer.reset-size9.size11 {
+ font-size: 1.43981481em;
+}
+.katex .sizing.reset-size10.size1,
+.katex .fontsize-ensurer.reset-size10.size1 {
+ font-size: 0.24108004em;
+}
+.katex .sizing.reset-size10.size2,
+.katex .fontsize-ensurer.reset-size10.size2 {
+ font-size: 0.28929605em;
+}
+.katex .sizing.reset-size10.size3,
+.katex .fontsize-ensurer.reset-size10.size3 {
+ font-size: 0.33751205em;
+}
+.katex .sizing.reset-size10.size4,
+.katex .fontsize-ensurer.reset-size10.size4 {
+ font-size: 0.38572806em;
+}
+.katex .sizing.reset-size10.size5,
+.katex .fontsize-ensurer.reset-size10.size5 {
+ font-size: 0.43394407em;
+}
+.katex .sizing.reset-size10.size6,
+.katex .fontsize-ensurer.reset-size10.size6 {
+ font-size: 0.48216008em;
+}
+.katex .sizing.reset-size10.size7,
+.katex .fontsize-ensurer.reset-size10.size7 {
+ font-size: 0.57859209em;
+}
+.katex .sizing.reset-size10.size8,
+.katex .fontsize-ensurer.reset-size10.size8 {
+ font-size: 0.69431051em;
+}
+.katex .sizing.reset-size10.size9,
+.katex .fontsize-ensurer.reset-size10.size9 {
+ font-size: 0.83317261em;
+}
+.katex .sizing.reset-size10.size10,
+.katex .fontsize-ensurer.reset-size10.size10 {
+ font-size: 1em;
+}
+.katex .sizing.reset-size10.size11,
+.katex .fontsize-ensurer.reset-size10.size11 {
+ font-size: 1.19961427em;
+}
+.katex .sizing.reset-size11.size1,
+.katex .fontsize-ensurer.reset-size11.size1 {
+ font-size: 0.20096463em;
+}
+.katex .sizing.reset-size11.size2,
+.katex .fontsize-ensurer.reset-size11.size2 {
+ font-size: 0.24115756em;
+}
+.katex .sizing.reset-size11.size3,
+.katex .fontsize-ensurer.reset-size11.size3 {
+ font-size: 0.28135048em;
+}
+.katex .sizing.reset-size11.size4,
+.katex .fontsize-ensurer.reset-size11.size4 {
+ font-size: 0.32154341em;
+}
+.katex .sizing.reset-size11.size5,
+.katex .fontsize-ensurer.reset-size11.size5 {
+ font-size: 0.36173633em;
+}
+.katex .sizing.reset-size11.size6,
+.katex .fontsize-ensurer.reset-size11.size6 {
+ font-size: 0.40192926em;
+}
+.katex .sizing.reset-size11.size7,
+.katex .fontsize-ensurer.reset-size11.size7 {
+ font-size: 0.48231511em;
+}
+.katex .sizing.reset-size11.size8,
+.katex .fontsize-ensurer.reset-size11.size8 {
+ font-size: 0.57877814em;
+}
+.katex .sizing.reset-size11.size9,
+.katex .fontsize-ensurer.reset-size11.size9 {
+ font-size: 0.69453376em;
+}
+.katex .sizing.reset-size11.size10,
+.katex .fontsize-ensurer.reset-size11.size10 {
+ font-size: 0.83360129em;
+}
+.katex .sizing.reset-size11.size11,
+.katex .fontsize-ensurer.reset-size11.size11 {
+ font-size: 1em;
+}
+.katex .delimsizing.size1 {
+ font-family: KaTeX_Size1;
+}
+.katex .delimsizing.size2 {
+ font-family: KaTeX_Size2;
+}
+.katex .delimsizing.size3 {
+ font-family: KaTeX_Size3;
+}
+.katex .delimsizing.size4 {
+ font-family: KaTeX_Size4;
+}
+.katex .delimsizing.mult .delim-size1 > span {
+ font-family: KaTeX_Size1;
+}
+.katex .delimsizing.mult .delim-size4 > span {
+ font-family: KaTeX_Size4;
+}
+.katex .nulldelimiter {
+ display: inline-block;
+ width: 0.12em;
+}
+.katex .delimcenter {
+ position: relative;
+}
+.katex .op-symbol {
+ position: relative;
+}
+.katex .op-symbol.small-op {
+ font-family: KaTeX_Size1;
+}
+.katex .op-symbol.large-op {
+ font-family: KaTeX_Size2;
+}
+.katex .op-limits > .vlist-t {
+ text-align: center;
+}
+.katex .accent > .vlist-t {
+ text-align: center;
+}
+.katex .accent .accent-body > span {
+ width: 0;
+}
+.katex .accent .accent-body.accent-vec > span {
+ position: relative;
+ left: 0.326em;
+}
+.katex .accent .accent-body.accent-hungarian > span {
+ position: relative;
+ left: 0.250em;
+}
+.katex .mtable .vertical-separator {
+ display: inline-block;
+ margin: 0 -0.025em;
+ border-right: 0.05em solid black;
+}
+.katex .mtable .arraycolsep {
+ display: inline-block;
+}
+.katex .mtable .col-align-c > .vlist-t {
+ text-align: center;
+}
+.katex .mtable .col-align-l > .vlist-t {
+ text-align: left;
+}
+.katex .mtable .col-align-r > .vlist-t {
+ text-align: right;
+}
+.katex .svg-align {
+ text-align: left;
+}
+.katex svg {
+ display: block;
+ position: absolute;
+ width: 100%;
+}
+.katex svg path {
+ fill: currentColor;
+}
+.katex svg line {
+ stroke: currentColor;
+}
+.katex .stretchy {
+ width: 100%;
+ display: block;
+}
+.katex .stretchy:before,
+.katex .stretchy:after {
+ content: "";
+}
+.katex .x-arrow-pad {
+ padding: 0 0.5em;
+}
+.katex .x-arrow,
+.katex .mover,
+.katex .munder {
+ text-align: center;
+}
+.katex .boxpad {
+ padding: 0 0.3em 0 0.3em;
+}
+.katex .fbox {
+ box-sizing: border-box;
+ border: 0.04em solid black;
+}
+.katex .cancel-pad {
+ padding: 0 0.2em 0 0.2em;
+}
+.katex .mord + .cancel-lap,
+.katex .mbin + .cancel-lap {
+ margin-left: -0.2em;
+}
+.katex .cancel-lap + .mord,
+.katex .cancel-lap + .mbin,
+.katex .cancel-lap + .msupsub {
+ margin-left: -0.2em;
+}
+.katex .sout {
+ border-bottom-style: solid;
+ border-bottom-width: 0.08em;
+}
diff --git a/static/katex/katex.js b/static/katex/katex.js
new file mode 100644
index 00000000..7e018746
--- /dev/null
+++ b/static/katex/katex.js
@@ -0,0 +1,10788 @@
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.katex = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0; --i) {
+ tok = expansion[i];
+ if (tok.text === "#") {
+ if (i === 0) {
+ throw new _ParseError2.default("Incomplete placeholder at end of macro body", tok);
+ }
+ tok = expansion[--i]; // next token on stack
+ if (tok.text === "#") {
+ // ## → #
+ expansion.splice(i + 1, 1); // drop first #
+ } else if (/^[1-9]$/.test(tok.text)) {
+ // expansion.splice(i, 2, arg[0], arg[1], …)
+ // to replace placeholder with the indicated argument.
+ // TODO: use spread once we move to ES2015
+ expansion.splice.apply(expansion, [i, 2].concat(args[tok.text - 1]));
+ } else {
+ throw new _ParseError2.default("Not a valid argument number", tok);
+ }
+ }
+ }
+ }
+ this.stack = this.stack.concat(expansion);
+ }
+ }
+ }, {
+ key: "get",
+ value: function get(ignoreSpace) {
+ this.discardedWhiteSpace = [];
+ var token = this.nextToken();
+ if (ignoreSpace) {
+ while (token.text === " ") {
+ this.discardedWhiteSpace.push(token);
+ token = this.nextToken();
+ }
+ }
+ return token;
+ }
+
+ /**
+ * Undo the effect of the preceding call to the get method.
+ * A call to this method MUST be immediately preceded and immediately followed
+ * by a call to get. Only used during mode switching, i.e. after one token
+ * was got in the old mode but should get got again in a new mode
+ * with possibly different whitespace handling.
+ */
+
+ }, {
+ key: "unget",
+ value: function unget(token) {
+ this.stack.push(token);
+ while (this.discardedWhiteSpace.length !== 0) {
+ this.stack.push(this.discardedWhiteSpace.pop());
+ }
+ }
+ }]);
+ return MacroExpander;
+}();
+
+module.exports = MacroExpander;
+
+},{"./Lexer":26,"./ParseError":29,"./macros":44,"babel-runtime/helpers/classCallCheck":4,"babel-runtime/helpers/createClass":5,"object-assign":25}],28:[function(require,module,exports){
+"use strict";
+
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
+var _createClass2 = require("babel-runtime/helpers/createClass");
+
+var _createClass3 = _interopRequireDefault(_createClass2);
+
+var _fontMetrics2 = require("./fontMetrics");
+
+var _fontMetrics3 = _interopRequireDefault(_fontMetrics2);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+var BASESIZE = 6; /**
+ * This file contains information about the options that the Parser carries
+ * around with it while parsing. Data is held in an `Options` object, and when
+ * recursing, a new `Options` object can be created with the `.with*` and
+ * `.reset` functions.
+ */
+
+var sizeStyleMap = [
+// Each element contains [textsize, scriptsize, scriptscriptsize].
+// The size mappings are taken from TeX with \normalsize=10pt.
+[1, 1, 1], // size1: [5, 5, 5] \tiny
+[2, 1, 1], // size2: [6, 5, 5]
+[3, 1, 1], // size3: [7, 5, 5] \scriptsize
+[4, 2, 1], // size4: [8, 6, 5] \footnotesize
+[5, 2, 1], // size5: [9, 6, 5] \small
+[6, 3, 1], // size6: [10, 7, 5] \normalsize
+[7, 4, 2], // size7: [12, 8, 6] \large
+[8, 6, 3], // size8: [14.4, 10, 7] \Large
+[9, 7, 6], // size9: [17.28, 12, 10] \LARGE
+[10, 8, 7], // size10: [20.74, 14.4, 12] \huge
+[11, 10, 9]];
+
+var sizeMultipliers = [
+// fontMetrics.js:getFontMetrics also uses size indexes, so if
+// you change size indexes, change that function.
+0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.44, 1.728, 2.074, 2.488];
+
+var sizeAtStyle = function sizeAtStyle(size, style) {
+ return style.size < 2 ? size : sizeStyleMap[size - 1][style.size - 1];
+};
+
+/**
+ * This is the main options class. It contains the current style, size, color,
+ * and font.
+ *
+ * Options objects should not be modified. To create a new Options with
+ * different properties, call a `.having*` method.
+ */
+
+var Options = function () {
+ function Options(data) {
+ (0, _classCallCheck3.default)(this, Options);
+
+ this.style = data.style;
+ this.color = data.color;
+ this.size = data.size || BASESIZE;
+ this.textSize = data.textSize || this.size;
+ this.phantom = data.phantom;
+ this.font = data.font;
+ this.sizeMultiplier = sizeMultipliers[this.size - 1];
+ this._fontMetrics = null;
+ }
+
+ /**
+ * Returns a new options object with the same properties as "this". Properties
+ * from "extension" will be copied to the new options object.
+ */
+
+
+ (0, _createClass3.default)(Options, [{
+ key: "extend",
+ value: function extend(extension) {
+ var data = {
+ style: this.style,
+ size: this.size,
+ textSize: this.textSize,
+ color: this.color,
+ phantom: this.phantom,
+ font: this.font
+ };
+
+ for (var key in extension) {
+ if (extension.hasOwnProperty(key)) {
+ data[key] = extension[key];
+ }
+ }
+
+ return new Options(data);
+ }
+
+ /**
+ * Return an options object with the given style. If `this.style === style`,
+ * returns `this`.
+ */
+
+ }, {
+ key: "havingStyle",
+ value: function havingStyle(style) {
+ if (this.style === style) {
+ return this;
+ } else {
+ return this.extend({
+ style: style,
+ size: sizeAtStyle(this.textSize, style)
+ });
+ }
+ }
+
+ /**
+ * Return an options object with a cramped version of the current style. If
+ * the current style is cramped, returns `this`.
+ */
+
+ }, {
+ key: "havingCrampedStyle",
+ value: function havingCrampedStyle() {
+ return this.havingStyle(this.style.cramp());
+ }
+
+ /**
+ * Return an options object with the given size and in at least `\textstyle`.
+ * Returns `this` if appropriate.
+ */
+
+ }, {
+ key: "havingSize",
+ value: function havingSize(size) {
+ if (this.size === size && this.textSize === size) {
+ return this;
+ } else {
+ return this.extend({
+ style: this.style.text(),
+ size: size,
+ textSize: size
+ });
+ }
+ }
+
+ /**
+ * Like `this.havingSize(BASESIZE).havingStyle(style)`. If `style` is omitted,
+ * changes to at least `\textstyle`.
+ */
+
+ }, {
+ key: "havingBaseStyle",
+ value: function havingBaseStyle(style) {
+ style = style || this.style.text();
+ var wantSize = sizeAtStyle(BASESIZE, style);
+ if (this.size === wantSize && this.textSize === BASESIZE && this.style === style) {
+ return this;
+ } else {
+ return this.extend({
+ style: style,
+ size: wantSize,
+ baseSize: BASESIZE
+ });
+ }
+ }
+
+ /**
+ * Create a new options object with the given color.
+ */
+
+ }, {
+ key: "withColor",
+ value: function withColor(color) {
+ return this.extend({
+ color: color
+ });
+ }
+
+ /**
+ * Create a new options object with "phantom" set to true.
+ */
+
+ }, {
+ key: "withPhantom",
+ value: function withPhantom() {
+ return this.extend({
+ phantom: true
+ });
+ }
+
+ /**
+ * Create a new options objects with the give font.
+ */
+
+ }, {
+ key: "withFont",
+ value: function withFont(font) {
+ return this.extend({
+ font: font || this.font
+ });
+ }
+
+ /**
+ * Return the CSS sizing classes required to switch from enclosing options
+ * `oldOptions` to `this`. Returns an array of classes.
+ */
+
+ }, {
+ key: "sizingClasses",
+ value: function sizingClasses(oldOptions) {
+ if (oldOptions.size !== this.size) {
+ return ["sizing", "reset-size" + oldOptions.size, "size" + this.size];
+ } else {
+ return [];
+ }
+ }
+
+ /**
+ * Return the CSS sizing classes required to switch to the base size. Like
+ * `this.havingSize(BASESIZE).sizingClasses(this)`.
+ */
+
+ }, {
+ key: "baseSizingClasses",
+ value: function baseSizingClasses() {
+ if (this.size !== BASESIZE) {
+ return ["sizing", "reset-size" + this.size, "size" + BASESIZE];
+ } else {
+ return [];
+ }
+ }
+
+ /**
+ * Return the font metrics for this size.
+ */
+
+ }, {
+ key: "fontMetrics",
+ value: function fontMetrics() {
+ if (!this._fontMetrics) {
+ this._fontMetrics = _fontMetrics3.default.getFontMetrics(this.size);
+ }
+ return this._fontMetrics;
+ }
+
+ /**
+ * A map of color names to CSS colors.
+ * TODO(emily): Remove this when we have real macros
+ */
+
+ }, {
+ key: "getColor",
+
+
+ /**
+ * Gets the CSS color of the current options object, accounting for the
+ * `colorMap`.
+ */
+ value: function getColor() {
+ if (this.phantom) {
+ return "transparent";
+ } else {
+ return Options.colorMap[this.color] || this.color;
+ }
+ }
+ }]);
+ return Options;
+}();
+
+/**
+ * The base size index.
+ */
+
+
+Options.colorMap = {
+ "katex-blue": "#6495ed",
+ "katex-orange": "#ffa500",
+ "katex-pink": "#ff00af",
+ "katex-red": "#df0030",
+ "katex-green": "#28ae7b",
+ "katex-gray": "gray",
+ "katex-purple": "#9d38bd",
+ "katex-blueA": "#ccfaff",
+ "katex-blueB": "#80f6ff",
+ "katex-blueC": "#63d9ea",
+ "katex-blueD": "#11accd",
+ "katex-blueE": "#0c7f99",
+ "katex-tealA": "#94fff5",
+ "katex-tealB": "#26edd5",
+ "katex-tealC": "#01d1c1",
+ "katex-tealD": "#01a995",
+ "katex-tealE": "#208170",
+ "katex-greenA": "#b6ffb0",
+ "katex-greenB": "#8af281",
+ "katex-greenC": "#74cf70",
+ "katex-greenD": "#1fab54",
+ "katex-greenE": "#0d923f",
+ "katex-goldA": "#ffd0a9",
+ "katex-goldB": "#ffbb71",
+ "katex-goldC": "#ff9c39",
+ "katex-goldD": "#e07d10",
+ "katex-goldE": "#a75a05",
+ "katex-redA": "#fca9a9",
+ "katex-redB": "#ff8482",
+ "katex-redC": "#f9685d",
+ "katex-redD": "#e84d39",
+ "katex-redE": "#bc2612",
+ "katex-maroonA": "#ffbde0",
+ "katex-maroonB": "#ff92c6",
+ "katex-maroonC": "#ed5fa6",
+ "katex-maroonD": "#ca337c",
+ "katex-maroonE": "#9e034e",
+ "katex-purpleA": "#ddd7ff",
+ "katex-purpleB": "#c6b9fc",
+ "katex-purpleC": "#aa87ff",
+ "katex-purpleD": "#7854ab",
+ "katex-purpleE": "#543b78",
+ "katex-mintA": "#f5f9e8",
+ "katex-mintB": "#edf2df",
+ "katex-mintC": "#e0e5cc",
+ "katex-grayA": "#f6f7f7",
+ "katex-grayB": "#f0f1f2",
+ "katex-grayC": "#e3e5e6",
+ "katex-grayD": "#d6d8da",
+ "katex-grayE": "#babec2",
+ "katex-grayF": "#888d93",
+ "katex-grayG": "#626569",
+ "katex-grayH": "#3b3e40",
+ "katex-grayI": "#21242c",
+ "katex-kaBlue": "#314453",
+ "katex-kaGreen": "#71B307"
+};
+Options.BASESIZE = BASESIZE;
+
+module.exports = Options;
+
+},{"./fontMetrics":41,"babel-runtime/helpers/classCallCheck":4,"babel-runtime/helpers/createClass":5}],29:[function(require,module,exports){
+"use strict";
+
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * This is the ParseError class, which is the main error thrown by KaTeX
+ * functions when something has gone wrong. This is used to distinguish internal
+ * errors from errors in the expression that the user provided.
+ *
+ * If possible, a caller should provide a Token or ParseNode with information
+ * about where in the source string the problem occurred.
+ *
+ * @param {string} message The error message
+ * @param {(Token|ParseNode)=} token An object providing position information
+ */
+var ParseError = function ParseError(message, token) {
+ (0, _classCallCheck3.default)(this, ParseError);
+
+ var error = "KaTeX parse error: " + message;
+ var start = void 0;
+ var end = void 0;
+
+ if (token && token.lexer && token.start <= token.end) {
+ // If we have the input and a position, make the error a bit fancier
+
+ // Get the input
+ var input = token.lexer.input;
+
+ // Prepend some information
+ start = token.start;
+ end = token.end;
+ if (start === input.length) {
+ error += " at end of input: ";
+ } else {
+ error += " at position " + (start + 1) + ": ";
+ }
+
+ // Underline token in question using combining underscores
+ var underlined = input.slice(start, end).replace(/[^]/g, "$&\u0332");
+
+ // Extract some context from the input and add it to the error
+ var left = void 0;
+ if (start > 15) {
+ left = "…" + input.slice(start - 15, start);
+ } else {
+ left = input.slice(0, start);
+ }
+ var right = void 0;
+ if (end + 15 < input.length) {
+ right = input.slice(end, end + 15) + "…";
+ } else {
+ right = input.slice(end);
+ }
+ error += left + underlined + right;
+ }
+
+ // Some hackery to make ParseError a prototype of Error
+ // See http://stackoverflow.com/a/8460753
+ var self = new Error(error);
+ self.name = "ParseError";
+ self.__proto__ = ParseError.prototype;
+
+ self.position = start;
+ return self;
+};
+
+// More hackery
+
+
+ParseError.prototype.__proto__ = Error.prototype;
+
+module.exports = ParseError;
+
+},{"babel-runtime/helpers/classCallCheck":4}],30:[function(require,module,exports){
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * The resulting parse tree nodes of the parse tree.
+ *
+ * It is possible to provide position information, so that a ParseNode can
+ * fulfil a role similar to a Token in error reporting.
+ * For details on the corresponding properties see Token constructor.
+ * Providing such information can lead to better error reporting.
+ *
+ * @param {string} type type of node, like e.g. "ordgroup"
+ * @param {?object} value type-specific representation of the node
+ * @param {string} mode parse mode in action for this node,
+ * "math" or "text"
+ * @param {Token=} firstToken first token of the input for this node,
+ * will omit position information if unset
+ * @param {Token=} lastToken last token of the input for this node,
+ * will default to firstToken if unset
+ */
+var ParseNode = function ParseNode(type, value, mode, firstToken, lastToken) {
+ (0, _classCallCheck3.default)(this, ParseNode);
+
+ this.type = type;
+ this.value = value;
+ this.mode = mode;
+ if (firstToken && (!lastToken || lastToken.lexer === firstToken.lexer)) {
+ this.lexer = firstToken.lexer;
+ this.start = firstToken.start;
+ this.end = (lastToken || firstToken).end;
+ }
+};
+
+exports.default = ParseNode;
+
+},{"babel-runtime/helpers/classCallCheck":4}],31:[function(require,module,exports){
+"use strict";
+
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
+var _createClass2 = require("babel-runtime/helpers/createClass");
+
+var _createClass3 = _interopRequireDefault(_createClass2);
+
+var _functions = require("./functions");
+
+var _functions2 = _interopRequireDefault(_functions);
+
+var _environments = require("./environments");
+
+var _environments2 = _interopRequireDefault(_environments);
+
+var _MacroExpander = require("./MacroExpander");
+
+var _MacroExpander2 = _interopRequireDefault(_MacroExpander);
+
+var _symbols = require("./symbols");
+
+var _symbols2 = _interopRequireDefault(_symbols);
+
+var _utils = require("./utils");
+
+var _utils2 = _interopRequireDefault(_utils);
+
+var _units = require("./units");
+
+var _units2 = _interopRequireDefault(_units);
+
+var _unicodeRegexes = require("./unicodeRegexes");
+
+var _ParseNode = require("./ParseNode");
+
+var _ParseNode2 = _interopRequireDefault(_ParseNode);
+
+var _ParseError = require("./ParseError");
+
+var _ParseError2 = _interopRequireDefault(_ParseError);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * This file contains the parser used to parse out a TeX expression from the
+ * input. Since TeX isn't context-free, standard parsers don't work particularly
+ * well.
+ *
+ * The strategy of this parser is as such:
+ *
+ * The main functions (the `.parse...` ones) take a position in the current
+ * parse string to parse tokens from. The lexer (found in Lexer.js, stored at
+ * this.lexer) also supports pulling out tokens at arbitrary places. When
+ * individual tokens are needed at a position, the lexer is called to pull out a
+ * token, which is then used.
+ *
+ * The parser has a property called "mode" indicating the mode that
+ * the parser is currently in. Currently it has to be one of "math" or
+ * "text", which denotes whether the current environment is a math-y
+ * one or a text-y one (e.g. inside \text). Currently, this serves to
+ * limit the functions which can be used in text mode.
+ *
+ * The main functions then return an object which contains the useful data that
+ * was parsed at its given point, and a new position at the end of the parsed
+ * data. The main functions can call each other and continue the parsing by
+ * using the returned position as a new starting point.
+ *
+ * There are also extra `.handle...` functions, which pull out some reused
+ * functionality into self-contained functions.
+ *
+ * The earlier functions return ParseNodes.
+ * The later functions (which are called deeper in the parse) sometimes return
+ * ParseFuncOrArgument, which contain a ParseNode as well as some data about
+ * whether the parsed object is a function which is missing some arguments, or a
+ * standalone object which can be used as an argument to another function.
+ */
+
+/**
+ * An initial function (without its arguments), or an argument to a function.
+ * The `result` argument should be a ParseNode.
+ */
+function ParseFuncOrArgument(result, isFunction, token) {
+ this.result = result;
+ // Is this a function (i.e. is it something defined in functions.js)?
+ this.isFunction = isFunction;
+ this.token = token;
+} /* eslint no-constant-condition:0 */
+
+var Parser = function () {
+ function Parser(input, settings) {
+ (0, _classCallCheck3.default)(this, Parser);
+
+ // Create a new macro expander (gullet) and (indirectly via that) also a
+ // new lexer (mouth) for this parser (stomach, in the language of TeX)
+ this.gullet = new _MacroExpander2.default(input, settings.macros);
+ // Use old \color behavior (same as LaTeX's \textcolor) if requested.
+ // We do this after the macros object has been copied by MacroExpander.
+ if (settings.colorIsTextColor) {
+ this.gullet.macros["\\color"] = "\\textcolor";
+ }
+ // Store the settings for use in parsing
+ this.settings = settings;
+ // Count leftright depth (for \middle errors)
+ this.leftrightDepth = 0;
+ }
+
+ /**
+ * Checks a result to make sure it has the right type, and throws an
+ * appropriate error otherwise.
+ *
+ * @param {boolean=} consume whether to consume the expected token,
+ * defaults to true
+ */
+
+
+ (0, _createClass3.default)(Parser, [{
+ key: "expect",
+ value: function expect(text, consume) {
+ if (this.nextToken.text !== text) {
+ throw new _ParseError2.default("Expected '" + text + "', got '" + this.nextToken.text + "'", this.nextToken);
+ }
+ if (consume !== false) {
+ this.consume();
+ }
+ }
+
+ /**
+ * Considers the current look ahead token as consumed,
+ * and fetches the one after that as the new look ahead.
+ */
+
+ }, {
+ key: "consume",
+ value: function consume() {
+ this.nextToken = this.gullet.get(this.mode === "math");
+ }
+ }, {
+ key: "switchMode",
+ value: function switchMode(newMode) {
+ this.gullet.unget(this.nextToken);
+ this.mode = newMode;
+ this.consume();
+ }
+
+ /**
+ * Main parsing function, which parses an entire input.
+ *
+ * @return {?Array.}
+ */
+
+ }, {
+ key: "parse",
+ value: function parse() {
+ // Try to parse the input
+ this.mode = "math";
+ this.consume();
+ var parse = this.parseInput();
+ return parse;
+ }
+
+ /**
+ * Parses an entire input tree.
+ */
+
+ }, {
+ key: "parseInput",
+ value: function parseInput() {
+ // Parse an expression
+ var expression = this.parseExpression(false);
+ // If we succeeded, make sure there's an EOF at the end
+ this.expect("EOF", false);
+ return expression;
+ }
+ }, {
+ key: "parseExpression",
+
+
+ /**
+ * Parses an "expression", which is a list of atoms.
+ *
+ * @param {boolean} breakOnInfix Should the parsing stop when we hit infix
+ * nodes? This happens when functions have higher precendence
+ * than infix nodes in implicit parses.
+ *
+ * @param {?string} breakOnTokenText The text of the token that the expression
+ * should end with, or `null` if something else should end the
+ * expression.
+ *
+ * @return {ParseNode}
+ */
+ value: function parseExpression(breakOnInfix, breakOnTokenText) {
+ var body = [];
+ // Keep adding atoms to the body until we can't parse any more atoms (either
+ // we reached the end, a }, or a \right)
+ while (true) {
+ var lex = this.nextToken;
+ if (Parser.endOfExpression.indexOf(lex.text) !== -1) {
+ break;
+ }
+ if (breakOnTokenText && lex.text === breakOnTokenText) {
+ break;
+ }
+ if (breakOnInfix && _functions2.default[lex.text] && _functions2.default[lex.text].infix) {
+ break;
+ }
+ var atom = this.parseAtom();
+ if (!atom) {
+ if (!this.settings.throwOnError && lex.text[0] === "\\") {
+ var errorNode = this.handleUnsupportedCmd();
+ body.push(errorNode);
+ continue;
+ }
+
+ break;
+ }
+ body.push(atom);
+ }
+ return this.handleInfixNodes(body);
+ }
+
+ /**
+ * Rewrites infix operators such as \over with corresponding commands such
+ * as \frac.
+ *
+ * There can only be one infix operator per group. If there's more than one
+ * then the expression is ambiguous. This can be resolved by adding {}.
+ *
+ * @returns {Array}
+ */
+
+ }, {
+ key: "handleInfixNodes",
+ value: function handleInfixNodes(body) {
+ var overIndex = -1;
+ var funcName = void 0;
+
+ for (var i = 0; i < body.length; i++) {
+ var node = body[i];
+ if (node.type === "infix") {
+ if (overIndex !== -1) {
+ throw new _ParseError2.default("only one infix operator per group", node.value.token);
+ }
+ overIndex = i;
+ funcName = node.value.replaceWith;
+ }
+ }
+
+ if (overIndex !== -1) {
+ var numerNode = void 0;
+ var denomNode = void 0;
+
+ var numerBody = body.slice(0, overIndex);
+ var denomBody = body.slice(overIndex + 1);
+
+ if (numerBody.length === 1 && numerBody[0].type === "ordgroup") {
+ numerNode = numerBody[0];
+ } else {
+ numerNode = new _ParseNode2.default("ordgroup", numerBody, this.mode);
+ }
+
+ if (denomBody.length === 1 && denomBody[0].type === "ordgroup") {
+ denomNode = denomBody[0];
+ } else {
+ denomNode = new _ParseNode2.default("ordgroup", denomBody, this.mode);
+ }
+
+ var value = this.callFunction(funcName, [numerNode, denomNode], null);
+ return [new _ParseNode2.default(value.type, value, this.mode)];
+ } else {
+ return body;
+ }
+ }
+
+ // The greediness of a superscript or subscript
+
+ }, {
+ key: "handleSupSubscript",
+
+
+ /**
+ * Handle a subscript or superscript with nice errors.
+ */
+ value: function handleSupSubscript(name) {
+ var symbolToken = this.nextToken;
+ var symbol = symbolToken.text;
+ this.consume();
+ var group = this.parseGroup();
+
+ if (!group) {
+ if (!this.settings.throwOnError && this.nextToken.text[0] === "\\") {
+ return this.handleUnsupportedCmd();
+ } else {
+ throw new _ParseError2.default("Expected group after '" + symbol + "'", symbolToken);
+ }
+ } else if (group.isFunction) {
+ // ^ and _ have a greediness, so handle interactions with functions'
+ // greediness
+ var funcGreediness = _functions2.default[group.result].greediness;
+ if (funcGreediness > Parser.SUPSUB_GREEDINESS) {
+ return this.parseFunction(group);
+ } else {
+ throw new _ParseError2.default("Got function '" + group.result + "' with no arguments " + "as " + name, symbolToken);
+ }
+ } else {
+ return group.result;
+ }
+ }
+
+ /**
+ * Converts the textual input of an unsupported command into a text node
+ * contained within a color node whose color is determined by errorColor
+ */
+
+ }, {
+ key: "handleUnsupportedCmd",
+ value: function handleUnsupportedCmd() {
+ var text = this.nextToken.text;
+ var textordArray = [];
+
+ for (var i = 0; i < text.length; i++) {
+ textordArray.push(new _ParseNode2.default("textord", text[i], "text"));
+ }
+
+ var textNode = new _ParseNode2.default("text", {
+ body: textordArray,
+ type: "text"
+ }, this.mode);
+
+ var colorNode = new _ParseNode2.default("color", {
+ color: this.settings.errorColor,
+ value: [textNode],
+ type: "color"
+ }, this.mode);
+
+ this.consume();
+ return colorNode;
+ }
+
+ /**
+ * Parses a group with optional super/subscripts.
+ *
+ * @return {?ParseNode}
+ */
+
+ }, {
+ key: "parseAtom",
+ value: function parseAtom() {
+ // The body of an atom is an implicit group, so that things like
+ // \left(x\right)^2 work correctly.
+ var base = this.parseImplicitGroup();
+
+ // In text mode, we don't have superscripts or subscripts
+ if (this.mode === "text") {
+ return base;
+ }
+
+ // Note that base may be empty (i.e. null) at this point.
+
+ var superscript = void 0;
+ var subscript = void 0;
+ while (true) {
+ // Lex the first token
+ var lex = this.nextToken;
+
+ if (lex.text === "\\limits" || lex.text === "\\nolimits") {
+ // We got a limit control
+ if (!base || base.type !== "op") {
+ throw new _ParseError2.default("Limit controls must follow a math operator", lex);
+ } else {
+ var limits = lex.text === "\\limits";
+ base.value.limits = limits;
+ base.value.alwaysHandleSupSub = true;
+ }
+ this.consume();
+ } else if (lex.text === "^") {
+ // We got a superscript start
+ if (superscript) {
+ throw new _ParseError2.default("Double superscript", lex);
+ }
+ superscript = this.handleSupSubscript("superscript");
+ } else if (lex.text === "_") {
+ // We got a subscript start
+ if (subscript) {
+ throw new _ParseError2.default("Double subscript", lex);
+ }
+ subscript = this.handleSupSubscript("subscript");
+ } else if (lex.text === "'") {
+ // We got a prime
+ if (superscript) {
+ throw new _ParseError2.default("Double superscript", lex);
+ }
+ var prime = new _ParseNode2.default("textord", "\\prime", this.mode);
+
+ // Many primes can be grouped together, so we handle this here
+ var primes = [prime];
+ this.consume();
+ // Keep lexing tokens until we get something that's not a prime
+ while (this.nextToken.text === "'") {
+ // For each one, add another prime to the list
+ primes.push(prime);
+ this.consume();
+ }
+ // If there's a superscript following the primes, combine that
+ // superscript in with the primes.
+ if (this.nextToken.text === "^") {
+ primes.push(this.handleSupSubscript("superscript"));
+ }
+ // Put everything into an ordgroup as the superscript
+ superscript = new _ParseNode2.default("ordgroup", primes, this.mode);
+ } else {
+ // If it wasn't ^, _, or ', stop parsing super/subscripts
+ break;
+ }
+ }
+
+ if (superscript || subscript) {
+ // If we got either a superscript or subscript, create a supsub
+ return new _ParseNode2.default("supsub", {
+ base: base,
+ sup: superscript,
+ sub: subscript
+ }, this.mode);
+ } else {
+ // Otherwise return the original body
+ return base;
+ }
+ }
+
+ // A list of the size-changing functions, for use in parseImplicitGroup
+
+
+ // A list of the style-changing functions, for use in parseImplicitGroup
+
+
+ // Old font functions
+
+ }, {
+ key: "parseImplicitGroup",
+
+
+ /**
+ * Parses an implicit group, which is a group that starts at the end of a
+ * specified, and ends right before a higher explicit group ends, or at EOL. It
+ * is used for functions that appear to affect the current style, like \Large or
+ * \textrm, where instead of keeping a style we just pretend that there is an
+ * implicit grouping after it until the end of the group. E.g.
+ * small text {\Large large text} small text again
+ * It is also used for \left and \right to get the correct grouping.
+ *
+ * @return {?ParseNode}
+ */
+ value: function parseImplicitGroup() {
+ var start = this.parseSymbol();
+
+ if (start == null) {
+ // If we didn't get anything we handle, fall back to parseFunction
+ return this.parseFunction();
+ }
+
+ var func = start.result;
+
+ if (func === "\\left") {
+ // If we see a left:
+ // Parse the entire left function (including the delimiter)
+ var left = this.parseFunction(start);
+ // Parse out the implicit body
+ ++this.leftrightDepth;
+ var body = this.parseExpression(false);
+ --this.leftrightDepth;
+ // Check the next token
+ this.expect("\\right", false);
+ var right = this.parseFunction();
+ return new _ParseNode2.default("leftright", {
+ body: body,
+ left: left.value.value,
+ right: right.value.value
+ }, this.mode);
+ } else if (func === "\\begin") {
+ // begin...end is similar to left...right
+ var begin = this.parseFunction(start);
+ var envName = begin.value.name;
+ if (!_environments2.default.hasOwnProperty(envName)) {
+ throw new _ParseError2.default("No such environment: " + envName, begin.value.nameGroup);
+ }
+ // Build the environment object. Arguments and other information will
+ // be made available to the begin and end methods using properties.
+ var env = _environments2.default[envName];
+ var args = this.parseArguments("\\begin{" + envName + "}", env);
+ var context = {
+ mode: this.mode,
+ envName: envName,
+ parser: this,
+ positions: args.pop()
+ };
+ var result = env.handler(context, args);
+ this.expect("\\end", false);
+ var endNameToken = this.nextToken;
+ var end = this.parseFunction();
+ if (end.value.name !== envName) {
+ throw new _ParseError2.default("Mismatch: \\begin{" + envName + "} matched " + "by \\end{" + end.value.name + "}", endNameToken);
+ }
+ result.position = end.position;
+ return result;
+ } else if (_utils2.default.contains(Parser.sizeFuncs, func)) {
+ // If we see a sizing function, parse out the implicit body
+ this.consumeSpaces();
+ var _body = this.parseExpression(false);
+ return new _ParseNode2.default("sizing", {
+ // Figure out what size to use based on the list of functions above
+ size: _utils2.default.indexOf(Parser.sizeFuncs, func) + 1,
+ value: _body
+ }, this.mode);
+ } else if (_utils2.default.contains(Parser.styleFuncs, func)) {
+ // If we see a styling function, parse out the implicit body
+ this.consumeSpaces();
+ var _body2 = this.parseExpression(true);
+ return new _ParseNode2.default("styling", {
+ // Figure out what style to use by pulling out the style from
+ // the function name
+ style: func.slice(1, func.length - 5),
+ value: _body2
+ }, this.mode);
+ } else if (func in Parser.oldFontFuncs) {
+ var style = Parser.oldFontFuncs[func];
+ // If we see an old font function, parse out the implicit body
+ this.consumeSpaces();
+ var _body3 = this.parseExpression(true);
+ if (style.slice(0, 4) === 'text') {
+ return new _ParseNode2.default("text", {
+ style: style,
+ body: new _ParseNode2.default("ordgroup", _body3, this.mode)
+ }, this.mode);
+ } else {
+ return new _ParseNode2.default("font", {
+ font: style,
+ body: new _ParseNode2.default("ordgroup", _body3, this.mode)
+ }, this.mode);
+ }
+ } else if (func === "\\color") {
+ // If we see a styling function, parse out the implicit body
+ var color = this.parseColorGroup(false);
+ if (!color) {
+ throw new _ParseError2.default("\\color not followed by color");
+ }
+ var _body4 = this.parseExpression(true);
+ return new _ParseNode2.default("color", {
+ type: "color",
+ color: color.result.value,
+ value: _body4
+ }, this.mode);
+ } else if (func === "$") {
+ if (this.mode === "math") {
+ throw new _ParseError2.default("$ within math mode");
+ }
+ this.consume();
+ var outerMode = this.mode;
+ this.switchMode("math");
+ var _body5 = this.parseExpression(false, "$");
+ this.expect("$", true);
+ this.switchMode(outerMode);
+ return new _ParseNode2.default("styling", {
+ style: "text",
+ value: _body5
+ }, "math");
+ } else {
+ // Defer to parseFunction if it's not a function we handle
+ return this.parseFunction(start);
+ }
+ }
+
+ /**
+ * Parses an entire function, including its base and all of its arguments.
+ * The base might either have been parsed already, in which case
+ * it is provided as an argument, or it's the next group in the input.
+ *
+ * @param {ParseFuncOrArgument=} baseGroup optional as described above
+ * @return {?ParseNode}
+ */
+
+ }, {
+ key: "parseFunction",
+ value: function parseFunction(baseGroup) {
+ if (!baseGroup) {
+ baseGroup = this.parseGroup();
+ }
+
+ if (baseGroup) {
+ if (baseGroup.isFunction) {
+ var func = baseGroup.result;
+ var funcData = _functions2.default[func];
+ if (this.mode === "text" && !funcData.allowedInText) {
+ throw new _ParseError2.default("Can't use function '" + func + "' in text mode", baseGroup.token);
+ } else if (this.mode === "math" && funcData.allowedInMath === false) {
+ throw new _ParseError2.default("Can't use function '" + func + "' in math mode", baseGroup.token);
+ }
+
+ var args = this.parseArguments(func, funcData);
+ var token = baseGroup.token;
+ var result = this.callFunction(func, args, args.pop(), token);
+ return new _ParseNode2.default(result.type, result, this.mode);
+ } else {
+ return baseGroup.result;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Call a function handler with a suitable context and arguments.
+ */
+
+ }, {
+ key: "callFunction",
+ value: function callFunction(name, args, positions, token) {
+ var context = {
+ funcName: name,
+ parser: this,
+ positions: positions,
+ token: token
+ };
+ return _functions2.default[name].handler(context, args);
+ }
+
+ /**
+ * Parses the arguments of a function or environment
+ *
+ * @param {string} func "\name" or "\begin{name}"
+ * @param {{numArgs:number,numOptionalArgs:number|undefined}} funcData
+ * @return the array of arguments, with the list of positions as last element
+ */
+
+ }, {
+ key: "parseArguments",
+ value: function parseArguments(func, funcData) {
+ var totalArgs = funcData.numArgs + funcData.numOptionalArgs;
+ if (totalArgs === 0) {
+ return [[this.pos]];
+ }
+
+ var baseGreediness = funcData.greediness;
+ var positions = [this.pos];
+ var args = [];
+
+ for (var i = 0; i < totalArgs; i++) {
+ var nextToken = this.nextToken;
+ var argType = funcData.argTypes && funcData.argTypes[i];
+ var arg = void 0;
+ if (i < funcData.numOptionalArgs) {
+ if (argType) {
+ arg = this.parseGroupOfType(argType, true);
+ } else {
+ arg = this.parseGroup(true);
+ }
+ if (!arg) {
+ args.push(null);
+ positions.push(this.pos);
+ continue;
+ }
+ } else {
+ if (argType) {
+ arg = this.parseGroupOfType(argType);
+ } else {
+ arg = this.parseGroup();
+ }
+ if (!arg) {
+ if (!this.settings.throwOnError && this.nextToken.text[0] === "\\") {
+ arg = new ParseFuncOrArgument(this.handleUnsupportedCmd(this.nextToken.text), false);
+ } else {
+ throw new _ParseError2.default("Expected group after '" + func + "'", nextToken);
+ }
+ }
+ }
+ var argNode = void 0;
+ if (arg.isFunction) {
+ var argGreediness = _functions2.default[arg.result].greediness;
+ if (argGreediness > baseGreediness) {
+ argNode = this.parseFunction(arg);
+ } else {
+ throw new _ParseError2.default("Got function '" + arg.result + "' as " + "argument to '" + func + "'", nextToken);
+ }
+ } else {
+ argNode = arg.result;
+ }
+ args.push(argNode);
+ positions.push(this.pos);
+ }
+
+ args.push(positions);
+
+ return args;
+ }
+
+ /**
+ * Parses a group when the mode is changing.
+ *
+ * @return {?ParseFuncOrArgument}
+ */
+
+ }, {
+ key: "parseGroupOfType",
+ value: function parseGroupOfType(innerMode, optional) {
+ var outerMode = this.mode;
+ // Handle `original` argTypes
+ if (innerMode === "original") {
+ innerMode = outerMode;
+ }
+
+ if (innerMode === "color") {
+ return this.parseColorGroup(optional);
+ }
+ if (innerMode === "size") {
+ return this.parseSizeGroup(optional);
+ }
+
+ this.switchMode(innerMode);
+ if (innerMode === "text") {
+ // text mode is special because it should ignore the whitespace before
+ // it
+ this.consumeSpaces();
+ }
+ // By the time we get here, innerMode is one of "text" or "math".
+ // We switch the mode of the parser, recurse, then restore the old mode.
+ var res = this.parseGroup(optional);
+ this.switchMode(outerMode);
+ return res;
+ }
+ }, {
+ key: "consumeSpaces",
+ value: function consumeSpaces() {
+ while (this.nextToken.text === " ") {
+ this.consume();
+ }
+ }
+
+ /**
+ * Parses a group, essentially returning the string formed by the
+ * brace-enclosed tokens plus some position information.
+ *
+ * @param {string} modeName Used to describe the mode in error messages
+ * @param {boolean=} optional Whether the group is optional or required
+ */
+
+ }, {
+ key: "parseStringGroup",
+ value: function parseStringGroup(modeName, optional) {
+ if (optional && this.nextToken.text !== "[") {
+ return null;
+ }
+ var outerMode = this.mode;
+ this.mode = "text";
+ this.expect(optional ? "[" : "{");
+ var str = "";
+ var firstToken = this.nextToken;
+ var lastToken = firstToken;
+ while (this.nextToken.text !== (optional ? "]" : "}")) {
+ if (this.nextToken.text === "EOF") {
+ throw new _ParseError2.default("Unexpected end of input in " + modeName, firstToken.range(this.nextToken, str));
+ }
+ lastToken = this.nextToken;
+ str += lastToken.text;
+ this.consume();
+ }
+ this.mode = outerMode;
+ this.expect(optional ? "]" : "}");
+ return firstToken.range(lastToken, str);
+ }
+
+ /**
+ * Parses a regex-delimited group: the largest sequence of tokens
+ * whose concatenated strings match `regex`. Returns the string
+ * formed by the tokens plus some position information.
+ *
+ * @param {RegExp} regex
+ * @param {string} modeName Used to describe the mode in error messages
+ */
+
+ }, {
+ key: "parseRegexGroup",
+ value: function parseRegexGroup(regex, modeName) {
+ var outerMode = this.mode;
+ this.mode = "text";
+ var firstToken = this.nextToken;
+ var lastToken = firstToken;
+ var str = "";
+ while (this.nextToken.text !== "EOF" && regex.test(str + this.nextToken.text)) {
+ lastToken = this.nextToken;
+ str += lastToken.text;
+ this.consume();
+ }
+ if (str === "") {
+ throw new _ParseError2.default("Invalid " + modeName + ": '" + firstToken.text + "'", firstToken);
+ }
+ this.mode = outerMode;
+ return firstToken.range(lastToken, str);
+ }
+
+ /**
+ * Parses a color description.
+ */
+
+ }, {
+ key: "parseColorGroup",
+ value: function parseColorGroup(optional) {
+ var res = this.parseStringGroup("color", optional);
+ if (!res) {
+ return null;
+ }
+ var match = /^(#[a-z0-9]+|[a-z]+)$/i.exec(res.text);
+ if (!match) {
+ throw new _ParseError2.default("Invalid color: '" + res.text + "'", res);
+ }
+ return new ParseFuncOrArgument(new _ParseNode2.default("color", match[0], this.mode), false);
+ }
+
+ /**
+ * Parses a size specification, consisting of magnitude and unit.
+ */
+
+ }, {
+ key: "parseSizeGroup",
+ value: function parseSizeGroup(optional) {
+ var res = void 0;
+ if (!optional && this.nextToken.text !== "{") {
+ res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
+ } else {
+ res = this.parseStringGroup("size", optional);
+ }
+ if (!res) {
+ return null;
+ }
+ var match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
+ if (!match) {
+ throw new _ParseError2.default("Invalid size: '" + res.text + "'", res);
+ }
+ var data = {
+ number: +(match[1] + match[2]), // sign + magnitude, cast to number
+ unit: match[3]
+ };
+ if (!_units2.default.validUnit(data)) {
+ throw new _ParseError2.default("Invalid unit: '" + data.unit + "'", res);
+ }
+ return new ParseFuncOrArgument(new _ParseNode2.default("size", data, this.mode), false);
+ }
+
+ /**
+ * If the argument is false or absent, this parses an ordinary group,
+ * which is either a single nucleus (like "x") or an expression
+ * in braces (like "{x+y}").
+ * If the argument is true, it parses either a bracket-delimited expression
+ * (like "[x+y]") or returns null to indicate the absence of a
+ * bracket-enclosed group.
+ *
+ * @param {boolean=} optional Whether the group is optional or required
+ * @return {?ParseFuncOrArgument}
+ */
+
+ }, {
+ key: "parseGroup",
+ value: function parseGroup(optional) {
+ var firstToken = this.nextToken;
+ // Try to parse an open brace
+ if (this.nextToken.text === (optional ? "[" : "{")) {
+ // If we get a brace, parse an expression
+ this.consume();
+ var expression = this.parseExpression(false, optional ? "]" : null);
+ var lastToken = this.nextToken;
+ // Make sure we get a close brace
+ this.expect(optional ? "]" : "}");
+ if (this.mode === "text") {
+ this.formLigatures(expression);
+ }
+ return new ParseFuncOrArgument(new _ParseNode2.default("ordgroup", expression, this.mode, firstToken, lastToken), false);
+ } else {
+ // Otherwise, just return a nucleus, or nothing for an optional group
+ return optional ? null : this.parseSymbol();
+ }
+ }
+
+ /**
+ * Form ligature-like combinations of characters for text mode.
+ * This includes inputs like "--", "---", "``" and "''".
+ * The result will simply replace multiple textord nodes with a single
+ * character in each value by a single textord node having multiple
+ * characters in its value. The representation is still ASCII source.
+ *
+ * @param {Array.} group the nodes of this group,
+ * list will be moified in place
+ */
+
+ }, {
+ key: "formLigatures",
+ value: function formLigatures(group) {
+ var n = group.length - 1;
+ for (var i = 0; i < n; ++i) {
+ var a = group[i];
+ var v = a.value;
+ if (v === "-" && group[i + 1].value === "-") {
+ if (i + 1 < n && group[i + 2].value === "-") {
+ group.splice(i, 3, new _ParseNode2.default("textord", "---", "text", a, group[i + 2]));
+ n -= 2;
+ } else {
+ group.splice(i, 2, new _ParseNode2.default("textord", "--", "text", a, group[i + 1]));
+ n -= 1;
+ }
+ }
+ if ((v === "'" || v === "`") && group[i + 1].value === v) {
+ group.splice(i, 2, new _ParseNode2.default("textord", v + v, "text", a, group[i + 1]));
+ n -= 1;
+ }
+ }
+ }
+
+ /**
+ * Parse a single symbol out of the string. Here, we handle both the functions
+ * we have defined, as well as the single character symbols
+ *
+ * @return {?ParseFuncOrArgument}
+ */
+
+ }, {
+ key: "parseSymbol",
+ value: function parseSymbol() {
+ var nucleus = this.nextToken;
+
+ if (_functions2.default[nucleus.text]) {
+ this.consume();
+ // If there exists a function with this name, we return the function and
+ // say that it is a function.
+ return new ParseFuncOrArgument(nucleus.text, true, nucleus);
+ } else if (_symbols2.default[this.mode][nucleus.text]) {
+ this.consume();
+ // Otherwise if this is a no-argument function, find the type it
+ // corresponds to in the symbols map
+ return new ParseFuncOrArgument(new _ParseNode2.default(_symbols2.default[this.mode][nucleus.text].group, nucleus.text, this.mode, nucleus), false, nucleus);
+ } else if (this.mode === "text" && _unicodeRegexes.cjkRegex.test(nucleus.text)) {
+ this.consume();
+ return new ParseFuncOrArgument(new _ParseNode2.default("textord", nucleus.text, this.mode, nucleus), false, nucleus);
+ } else if (nucleus.text === "$") {
+ return new ParseFuncOrArgument(nucleus.text, false, nucleus);
+ } else {
+ return null;
+ }
+ }
+ }]);
+ return Parser;
+}();
+
+Parser.endOfExpression = ["}", "\\end", "\\right", "&", "\\\\", "\\cr"];
+Parser.SUPSUB_GREEDINESS = 1;
+Parser.sizeFuncs = ["\\tiny", "\\sixptsize", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"];
+Parser.styleFuncs = ["\\displaystyle", "\\textstyle", "\\scriptstyle", "\\scriptscriptstyle"];
+Parser.oldFontFuncs = {
+ "\\rm": "mathrm",
+ "\\sf": "mathsf",
+ "\\tt": "mathtt",
+ "\\bf": "mathbf",
+ "\\it": "mathit"
+};
+
+
+Parser.prototype.ParseNode = _ParseNode2.default;
+
+module.exports = Parser;
+
+},{"./MacroExpander":27,"./ParseError":29,"./ParseNode":30,"./environments":40,"./functions":43,"./symbols":48,"./unicodeRegexes":49,"./units":50,"./utils":51,"babel-runtime/helpers/classCallCheck":4,"babel-runtime/helpers/createClass":5}],32:[function(require,module,exports){
+"use strict";
+
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
+var _utils = require("./utils");
+
+var _utils2 = _interopRequireDefault(_utils);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * The main Settings object
+ *
+ * The current options stored are:
+ * - displayMode: Whether the expression should be typeset as inline math
+ * (false, the default), meaning that the math starts in
+ * \textstyle and is placed in an inline-block); or as display
+ * math (true), meaning that the math starts in \displaystyle
+ * and is placed in a block with vertical margin.
+ */
+var Settings = function Settings(options) {
+ (0, _classCallCheck3.default)(this, Settings);
+
+ // allow null options
+ options = options || {};
+ this.displayMode = _utils2.default.deflt(options.displayMode, false);
+ this.throwOnError = _utils2.default.deflt(options.throwOnError, true);
+ this.errorColor = _utils2.default.deflt(options.errorColor, "#cc0000");
+ this.macros = options.macros || {};
+ this.colorIsTextColor = _utils2.default.deflt(options.colorIsTextColor, false);
+}; /**
+ * This is a module for storing settings passed into KaTeX. It correctly handles
+ * default settings.
+ */
+
+module.exports = Settings;
+
+},{"./utils":51,"babel-runtime/helpers/classCallCheck":4}],33:[function(require,module,exports){
+"use strict";
+
+var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
+
+var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
+
+var _createClass2 = require("babel-runtime/helpers/createClass");
+
+var _createClass3 = _interopRequireDefault(_createClass2);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * This file contains information and classes for the various kinds of styles
+ * used in TeX. It provides a generic `Style` class, which holds information
+ * about a specific style. It then provides instances of all the different kinds
+ * of styles possible, and provides functions to move between them and get
+ * information about them.
+ */
+
+/**
+ * The main style class. Contains a unique id for the style, a size (which is
+ * the same for cramped and uncramped version of a style), and a cramped flag.
+ */
+var Style = function () {
+ function Style(id, size, cramped) {
+ (0, _classCallCheck3.default)(this, Style);
+
+ this.id = id;
+ this.size = size;
+ this.cramped = cramped;
+ }
+
+ /**
+ * Get the style of a superscript given a base in the current style.
+ */
+
+
+ (0, _createClass3.default)(Style, [{
+ key: "sup",
+ value: function sup() {
+ return styles[_sup[this.id]];
+ }
+
+ /**
+ * Get the style of a subscript given a base in the current style.
+ */
+
+ }, {
+ key: "sub",
+ value: function sub() {
+ return styles[_sub[this.id]];
+ }
+
+ /**
+ * Get the style of a fraction numerator given the fraction in the current
+ * style.
+ */
+
+ }, {
+ key: "fracNum",
+ value: function fracNum() {
+ return styles[_fracNum[this.id]];
+ }
+
+ /**
+ * Get the style of a fraction denominator given the fraction in the current
+ * style.
+ */
+
+ }, {
+ key: "fracDen",
+ value: function fracDen() {
+ return styles[_fracDen[this.id]];
+ }
+
+ /**
+ * Get the cramped version of a style (in particular, cramping a cramped style
+ * doesn't change the style).
+ */
+
+ }, {
+ key: "cramp",
+ value: function cramp() {
+ return styles[_cramp[this.id]];
+ }
+
+ /**
+ * Get a text or display version of this style.
+ */
+
+ }, {
+ key: "text",
+ value: function text() {
+ return styles[_text[this.id]];
+ }
+
+ /**
+ * Return if this style is tightly spaced (scriptstyle/scriptscriptstyle)
+ */
+
+ }, {
+ key: "isTight",
+ value: function isTight() {
+ return this.size >= 2;
+ }
+ }]);
+ return Style;
+}();
+
+// IDs of the different styles
+
+
+var D = 0;
+var Dc = 1;
+var T = 2;
+var Tc = 3;
+var S = 4;
+var Sc = 5;
+var SS = 6;
+var SSc = 7;
+
+// Instances of the different styles
+var styles = [new Style(D, 0, false), new Style(Dc, 0, true), new Style(T, 1, false), new Style(Tc, 1, true), new Style(S, 2, false), new Style(Sc, 2, true), new Style(SS, 3, false), new Style(SSc, 3, true)];
+
+// Lookup tables for switching from one style to another
+var _sup = [S, Sc, S, Sc, SS, SSc, SS, SSc];
+var _sub = [Sc, Sc, Sc, Sc, SSc, SSc, SSc, SSc];
+var _fracNum = [T, Tc, S, Sc, SS, SSc, SS, SSc];
+var _fracDen = [Tc, Tc, Sc, Sc, SSc, SSc, SSc, SSc];
+var _cramp = [Dc, Dc, Tc, Tc, Sc, Sc, SSc, SSc];
+var _text = [D, Dc, T, Tc, T, Tc, T, Tc];
+
+// We only export some of the styles. Also, we don't export the `Style` class so
+// no more styles can be generated.
+module.exports = {
+ DISPLAY: styles[D],
+ TEXT: styles[T],
+ SCRIPT: styles[S],
+ SCRIPTSCRIPT: styles[SS]
+};
+
+},{"babel-runtime/helpers/classCallCheck":4,"babel-runtime/helpers/createClass":5}],34:[function(require,module,exports){
+"use strict";
+
+var _domTree = require("./domTree");
+
+var _domTree2 = _interopRequireDefault(_domTree);
+
+var _fontMetrics = require("./fontMetrics");
+
+var _fontMetrics2 = _interopRequireDefault(_fontMetrics);
+
+var _symbols = require("./symbols");
+
+var _symbols2 = _interopRequireDefault(_symbols);
+
+var _utils = require("./utils");
+
+var _utils2 = _interopRequireDefault(_utils);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+// The following have to be loaded from Main-Italic font, using class mainit
+/* eslint no-console:0 */
+/**
+ * This module contains general functions that can be used for building
+ * different kinds of domTree nodes in a consistent manner.
+ */
+
+var mainitLetters = ["\\imath", // dotless i
+"\\jmath", // dotless j
+"\\pounds"];
+
+/**
+ * Looks up the given symbol in fontMetrics, after applying any symbol
+ * replacements defined in symbol.js
+ */
+var lookupSymbol = function lookupSymbol(value, fontFamily, mode) {
+ // Replace the value with its replaced value from symbol.js
+ if (_symbols2.default[mode][value] && _symbols2.default[mode][value].replace) {
+ value = _symbols2.default[mode][value].replace;
+ }
+ return {
+ value: value,
+ metrics: _fontMetrics2.default.getCharacterMetrics(value, fontFamily)
+ };
+};
+
+/**
+ * Makes a symbolNode after translation via the list of symbols in symbols.js.
+ * Correctly pulls out metrics for the character, and optionally takes a list of
+ * classes to be attached to the node.
+ *
+ * TODO: make argument order closer to makeSpan
+ * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
+ * should if present come first in `classes`.
+ */
+var makeSymbol = function makeSymbol(value, fontFamily, mode, options, classes) {
+ var lookup = lookupSymbol(value, fontFamily, mode);
+ var metrics = lookup.metrics;
+ value = lookup.value;
+
+ var symbolNode = void 0;
+ if (metrics) {
+ var italic = metrics.italic;
+ if (mode === "text") {
+ italic = 0;
+ }
+ symbolNode = new _domTree2.default.symbolNode(value, metrics.height, metrics.depth, italic, metrics.skew, classes);
+ } else {
+ // TODO(emily): Figure out a good way to only print this in development
+ typeof console !== "undefined" && console.warn("No character metrics for '" + value + "' in style '" + fontFamily + "'");
+ symbolNode = new _domTree2.default.symbolNode(value, 0, 0, 0, 0, classes);
+ }
+
+ if (options) {
+ symbolNode.maxFontSize = options.sizeMultiplier;
+ if (options.style.isTight()) {
+ symbolNode.classes.push("mtight");
+ }
+ if (options.getColor()) {
+ symbolNode.style.color = options.getColor();
+ }
+ }
+
+ return symbolNode;
+};
+
+/**
+ * Makes a symbol in Main-Regular or AMS-Regular.
+ * Used for rel, bin, open, close, inner, and punct.
+ */
+var mathsym = function mathsym(value, mode, options, classes) {
+ // Decide what font to render the symbol in by its entry in the symbols
+ // table.
+ // Have a special case for when the value = \ because the \ is used as a
+ // textord in unsupported command errors but cannot be parsed as a regular
+ // text ordinal and is therefore not present as a symbol in the symbols
+ // table for text
+ if (value === "\\" || _symbols2.default[mode][value].font === "main") {
+ return makeSymbol(value, "Main-Regular", mode, options, classes);
+ } else {
+ return makeSymbol(value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
+ }
+};
+
+/**
+ * Makes a symbol in the default font for mathords and textords.
+ */
+var mathDefault = function mathDefault(value, mode, options, classes, type) {
+ if (type === "mathord") {
+ var fontLookup = mathit(value, mode, options, classes);
+ return makeSymbol(value, fontLookup.fontName, mode, options, classes.concat([fontLookup.fontClass]));
+ } else if (type === "textord") {
+ var font = _symbols2.default[mode][value] && _symbols2.default[mode][value].font;
+ if (font === "ams") {
+ return makeSymbol(value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
+ } else {
+ // if (font === "main") {
+ return makeSymbol(value, "Main-Regular", mode, options, classes.concat(["mathrm"]));
+ }
+ } else {
+ throw new Error("unexpected type: " + type + " in mathDefault");
+ }
+};
+
+/**
+ * Determines which of the two font names (Main-Italic and Math-Italic) and
+ * corresponding style tags (mainit or mathit) to use for font "mathit",
+ * depending on the symbol. Use this function instead of fontMap for font
+ * "mathit".
+ */
+var mathit = function mathit(value, mode, options, classes) {
+ if (/[0-9]/.test(value.charAt(0)) ||
+ // glyphs for \imath and \jmath do not exist in Math-Italic so we
+ // need to use Main-Italic instead
+ _utils2.default.contains(mainitLetters, value)) {
+ return {
+ fontName: "Main-Italic",
+ fontClass: "mainit"
+ };
+ } else {
+ return {
+ fontName: "Math-Italic",
+ fontClass: "mathit"
+ };
+ }
+};
+
+/**
+ * Makes either a mathord or textord in the correct font and color.
+ */
+var makeOrd = function makeOrd(group, options, type) {
+ var mode = group.mode;
+ var value = group.value;
+
+ var classes = ["mord"];
+
+ var font = options.font;
+ if (font) {
+ var fontLookup = void 0;
+ if (font === "mathit" || _utils2.default.contains(mainitLetters, value)) {
+ fontLookup = mathit(value, mode, options, classes);
+ } else {
+ fontLookup = fontMap[font];
+ }
+ if (lookupSymbol(value, fontLookup.fontName, mode).metrics) {
+ return makeSymbol(value, fontLookup.fontName, mode, options, classes.concat([fontLookup.fontClass || font]));
+ } else {
+ return mathDefault(value, mode, options, classes, type);
+ }
+ } else {
+ return mathDefault(value, mode, options, classes, type);
+ }
+};
+
+/**
+ * Calculate the height, depth, and maxFontSize of an element based on its
+ * children.
+ */
+var sizeElementFromChildren = function sizeElementFromChildren(elem) {
+ var height = 0;
+ var depth = 0;
+ var maxFontSize = 0;
+
+ if (elem.children) {
+ for (var i = 0; i < elem.children.length; i++) {
+ if (elem.children[i].height > height) {
+ height = elem.children[i].height;
+ }
+ if (elem.children[i].depth > depth) {
+ depth = elem.children[i].depth;
+ }
+ if (elem.children[i].maxFontSize > maxFontSize) {
+ maxFontSize = elem.children[i].maxFontSize;
+ }
+ }
+ }
+
+ elem.height = height;
+ elem.depth = depth;
+ elem.maxFontSize = maxFontSize;
+};
+
+/**
+ * Makes a span with the given list of classes, list of children, and options.
+ *
+ * TODO: Ensure that `options` is always provided (currently some call sites
+ * don't pass it).
+ * TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
+ * should if present come first in `classes`.
+ */
+var makeSpan = function makeSpan(classes, children, options) {
+ var span = new _domTree2.default.span(classes, children, options);
+
+ sizeElementFromChildren(span);
+
+ return span;
+};
+
+/**
+ * Prepends the given children to the given span, updating height, depth, and
+ * maxFontSize.
+ */
+var prependChildren = function prependChildren(span, children) {
+ span.children = children.concat(span.children);
+
+ sizeElementFromChildren(span);
+};
+
+/**
+ * Makes a document fragment with the given list of children.
+ */
+var makeFragment = function makeFragment(children) {
+ var fragment = new _domTree2.default.documentFragment(children);
+
+ sizeElementFromChildren(fragment);
+
+ return fragment;
+};
+
+/**
+ * Makes a vertical list by stacking elements and kerns on top of each other.
+ * Allows for many different ways of specifying the positioning method.
+ *
+ * Arguments:
+ * - children: A list of child or kern nodes to be stacked on top of each other
+ * (i.e. the first element will be at the bottom, and the last at
+ * the top). Element nodes are specified as
+ * {type: "elem", elem: node}
+ * while kern nodes are specified as
+ * {type: "kern", size: size}
+ * - positionType: The method by which the vlist should be positioned. Valid
+ * values are:
+ * - "individualShift": The children list only contains elem
+ * nodes, and each node contains an extra
+ * "shift" value of how much it should be
+ * shifted (note that shifting is always
+ * moving downwards). positionData is
+ * ignored.
+ * - "top": The positionData specifies the topmost point of
+ * the vlist (note this is expected to be a height,
+ * so positive values move up)
+ * - "bottom": The positionData specifies the bottommost point
+ * of the vlist (note this is expected to be a
+ * depth, so positive values move down
+ * - "shift": The vlist will be positioned such that its
+ * baseline is positionData away from the baseline
+ * of the first child. Positive values move
+ * downwards.
+ * - "firstBaseline": The vlist will be positioned such that
+ * its baseline is aligned with the
+ * baseline of the first child.
+ * positionData is ignored. (this is
+ * equivalent to "shift" with
+ * positionData=0)
+ * - positionData: Data used in different ways depending on positionType
+ * - options: An Options object
+ *
+ */
+var makeVList = function makeVList(children, positionType, positionData, options) {
+ var depth = void 0;
+ var currPos = void 0;
+ var i = void 0;
+ if (positionType === "individualShift") {
+ var oldChildren = children;
+ children = [oldChildren[0]];
+
+ // Add in kerns to the list of children to get each element to be
+ // shifted to the correct specified shift
+ depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
+ currPos = depth;
+ for (i = 1; i < oldChildren.length; i++) {
+ var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
+ var size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
+
+ currPos = currPos + diff;
+
+ children.push({ type: "kern", size: size });
+ children.push(oldChildren[i]);
+ }
+ } else if (positionType === "top") {
+ // We always start at the bottom, so calculate the bottom by adding up
+ // all the sizes
+ var bottom = positionData;
+ for (i = 0; i < children.length; i++) {
+ if (children[i].type === "kern") {
+ bottom -= children[i].size;
+ } else {
+ bottom -= children[i].elem.height + children[i].elem.depth;
+ }
+ }
+ depth = bottom;
+ } else if (positionType === "bottom") {
+ depth = -positionData;
+ } else if (positionType === "shift") {
+ depth = -children[0].elem.depth - positionData;
+ } else if (positionType === "firstBaseline") {
+ depth = -children[0].elem.depth;
+ } else {
+ depth = 0;
+ }
+
+ // Create a strut that is taller than any list item. The strut is added to
+ // each item, where it will determine the item's baseline. Since it has
+ // `overflow:hidden`, the strut's top edge will sit on the item's line box's
+ // top edge and the strut's bottom edge will sit on the item's baseline,
+ // with no additional line-height spacing. This allows the item baseline to
+ // be positioned precisely without worrying about font ascent and
+ // line-height.
+ var pstrutSize = 0;
+ for (i = 0; i < children.length; i++) {
+ if (children[i].type === "elem") {
+ var child = children[i].elem;
+ pstrutSize = Math.max(pstrutSize, child.maxFontSize, child.height);
+ }
+ }
+ pstrutSize += 2;
+ var pstrut = makeSpan(["pstrut"], []);
+ pstrut.style.height = pstrutSize + "em";
+
+ // Create a new list of actual children at the correct offsets
+ var realChildren = [];
+ var minPos = depth;
+ var maxPos = depth;
+ currPos = depth;
+ for (i = 0; i < children.length; i++) {
+ if (children[i].type === "kern") {
+ currPos += children[i].size;
+ } else {
+ var _child = children[i].elem;
+
+ var childWrap = makeSpan([], [pstrut, _child]);
+ childWrap.style.top = -pstrutSize - currPos - _child.depth + "em";
+ if (children[i].marginLeft) {
+ childWrap.style.marginLeft = children[i].marginLeft;
+ }
+ if (children[i].marginRight) {
+ childWrap.style.marginRight = children[i].marginRight;
+ }
+
+ realChildren.push(childWrap);
+ currPos += _child.height + _child.depth;
+ }
+ minPos = Math.min(minPos, currPos);
+ maxPos = Math.max(maxPos, currPos);
+ }
+
+ // The vlist contents go in a table-cell with `vertical-align:bottom`.
+ // This cell's bottom edge will determine the containing table's baseline
+ // without overly expanding the containing line-box.
+ var vlist = makeSpan(["vlist"], realChildren);
+ vlist.style.height = maxPos + "em";
+
+ // A second row is used if necessary to represent the vlist's depth.
+ var rows = void 0;
+ if (minPos < 0) {
+ var depthStrut = makeSpan(["vlist"], []);
+ depthStrut.style.height = -minPos + "em";
+
+ // Safari wants the first row to have inline content; otherwise it
+ // puts the bottom of the *second* row on the baseline.
+ var topStrut = makeSpan(["vlist-s"], [new _domTree2.default.symbolNode("\u200B")]);
+
+ rows = [makeSpan(["vlist-r"], [vlist, topStrut]), makeSpan(["vlist-r"], [depthStrut])];
+ } else {
+ rows = [makeSpan(["vlist-r"], [vlist])];
+ }
+
+ var vtable = makeSpan(["vlist-t"], rows);
+ if (rows.length === 2) {
+ vtable.classes.push("vlist-t2");
+ }
+ vtable.height = maxPos;
+ vtable.depth = -minPos;
+ return vtable;
+};
+
+// A map of spacing functions to their attributes, like size and corresponding
+// CSS class
+var spacingFunctions = {
+ "\\qquad": {
+ size: "2em",
+ className: "qquad"
+ },
+ "\\quad": {
+ size: "1em",
+ className: "quad"
+ },
+ "\\enspace": {
+ size: "0.5em",
+ className: "enspace"
+ },
+ "\\;": {
+ size: "0.277778em",
+ className: "thickspace"
+ },
+ "\\:": {
+ size: "0.22222em",
+ className: "mediumspace"
+ },
+ "\\,": {
+ size: "0.16667em",
+ className: "thinspace"
+ },
+ "\\!": {
+ size: "-0.16667em",
+ className: "negativethinspace"
+ }
+};
+
+/**
+ * Maps TeX font commands to objects containing:
+ * - variant: string used for "mathvariant" attribute in buildMathML.js
+ * - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
+ */
+// A map between tex font commands an MathML mathvariant attribute values
+var fontMap = {
+ // styles
+ "mathbf": {
+ variant: "bold",
+ fontName: "Main-Bold"
+ },
+ "mathrm": {
+ variant: "normal",
+ fontName: "Main-Regular"
+ },
+ "textit": {
+ variant: "italic",
+ fontName: "Main-Italic"
+ },
+
+ // "mathit" is missing because it requires the use of two fonts: Main-Italic
+ // and Math-Italic. This is handled by a special case in makeOrd which ends
+ // up calling mathit.
+
+ // families
+ "mathbb": {
+ variant: "double-struck",
+ fontName: "AMS-Regular"
+ },
+ "mathcal": {
+ variant: "script",
+ fontName: "Caligraphic-Regular"
+ },
+ "mathfrak": {
+ variant: "fraktur",
+ fontName: "Fraktur-Regular"
+ },
+ "mathscr": {
+ variant: "script",
+ fontName: "Script-Regular"
+ },
+ "mathsf": {
+ variant: "sans-serif",
+ fontName: "SansSerif-Regular"
+ },
+ "mathtt": {
+ variant: "monospace",
+ fontName: "Typewriter-Regular"
+ }
+};
+
+module.exports = {
+ fontMap: fontMap,
+ makeSymbol: makeSymbol,
+ mathsym: mathsym,
+ makeSpan: makeSpan,
+ makeFragment: makeFragment,
+ makeVList: makeVList,
+ makeOrd: makeOrd,
+ prependChildren: prependChildren,
+ spacingFunctions: spacingFunctions
+};
+
+},{"./domTree":39,"./fontMetrics":41,"./symbols":48,"./utils":51}],35:[function(require,module,exports){
+"use strict";
+
+var _stringify = require("babel-runtime/core-js/json/stringify");
+
+var _stringify2 = _interopRequireDefault(_stringify);
+
+var _ParseError = require("./ParseError");
+
+var _ParseError2 = _interopRequireDefault(_ParseError);
+
+var _Style = require("./Style");
+
+var _Style2 = _interopRequireDefault(_Style);
+
+var _buildCommon = require("./buildCommon");
+
+var _buildCommon2 = _interopRequireDefault(_buildCommon);
+
+var _delimiter = require("./delimiter");
+
+var _delimiter2 = _interopRequireDefault(_delimiter);
+
+var _domTree = require("./domTree");
+
+var _domTree2 = _interopRequireDefault(_domTree);
+
+var _units = require("./units");
+
+var _units2 = _interopRequireDefault(_units);
+
+var _utils = require("./utils");
+
+var _utils2 = _interopRequireDefault(_utils);
+
+var _stretchy = require("./stretchy");
+
+var _stretchy2 = _interopRequireDefault(_stretchy);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/* eslint no-console:0 */
+/**
+ * This file does the main work of building a domTree structure from a parse
+ * tree. The entry point is the `buildHTML` function, which takes a parse tree.
+ * Then, the buildExpression, buildGroup, and various groupTypes functions are
+ * called, to produce a final HTML tree.
+ */
+
+var isSpace = function isSpace(node) {
+ return node instanceof _domTree2.default.span && node.classes[0] === "mspace";
+};
+
+// Binary atoms (first class `mbin`) change into ordinary atoms (`mord`)
+// depending on their surroundings. See TeXbook pg. 442-446, Rules 5 and 6,
+// and the text before Rule 19.
+var isBin = function isBin(node) {
+ return node && node.classes[0] === "mbin";
+};
+
+var isBinLeftCanceller = function isBinLeftCanceller(node, isRealGroup) {
+ // TODO: This code assumes that a node's math class is the first element
+ // of its `classes` array. A later cleanup should ensure this, for
+ // instance by changing the signature of `makeSpan`.
+ if (node) {
+ return _utils2.default.contains(["mbin", "mopen", "mrel", "mop", "mpunct"], node.classes[0]);
+ } else {
+ return isRealGroup;
+ }
+};
+
+var isBinRightCanceller = function isBinRightCanceller(node, isRealGroup) {
+ if (node) {
+ return _utils2.default.contains(["mrel", "mclose", "mpunct"], node.classes[0]);
+ } else {
+ return isRealGroup;
+ }
+};
+
+/**
+ * Splice out any spaces from `children` starting at position `i`, and return
+ * the spliced-out array. Returns null if `children[i]` does not exist or is not
+ * a space.
+ */
+var spliceSpaces = function spliceSpaces(children, i) {
+ var j = i;
+ while (j < children.length && isSpace(children[j])) {
+ j++;
+ }
+ if (j === i) {
+ return null;
+ } else {
+ return children.splice(i, j - i);
+ }
+};
+
+/**
+ * Take a list of nodes, build them in order, and return a list of the built
+ * nodes. documentFragments are flattened into their contents, so the
+ * returned list contains no fragments. `isRealGroup` is true if `expression`
+ * is a real group (no atoms will be added on either side), as opposed to
+ * a partial group (e.g. one created by \color).
+ */
+var buildExpression = function buildExpression(expression, options, isRealGroup) {
+ // Parse expressions into `groups`.
+ var groups = [];
+ for (var i = 0; i < expression.length; i++) {
+ var group = expression[i];
+ var output = buildGroup(group, options);
+ if (output instanceof _domTree2.default.documentFragment) {
+ Array.prototype.push.apply(groups, output.children);
+ } else {
+ groups.push(output);
+ }
+ }
+ // At this point `groups` consists entirely of `symbolNode`s and `span`s.
+
+ // Explicit spaces (e.g., \;, \,) should be ignored with respect to atom
+ // spacing (e.g., "add thick space between mord and mrel"). Since CSS
+ // adjacency rules implement atom spacing, spaces should be invisible to
+ // CSS. So we splice them out of `groups` and into the atoms themselves.
+ for (var _i = 0; _i < groups.length; _i++) {
+ var spaces = spliceSpaces(groups, _i);
+ if (spaces) {
+ // Splicing of spaces may have removed all remaining groups.
+ if (_i < groups.length) {
+ // If there is a following group, move space within it.
+ if (groups[_i] instanceof _domTree2.default.symbolNode) {
+ groups[_i] = (0, _buildCommon.makeSpan)([].concat(groups[_i].classes), [groups[_i]]);
+ }
+ _buildCommon2.default.prependChildren(groups[_i], spaces);
+ } else {
+ // Otherwise, put any spaces back at the end of the groups.
+ Array.prototype.push.apply(groups, spaces);
+ break;
+ }
+ }
+ }
+
+ // Binary operators change to ordinary symbols in some contexts.
+ for (var _i2 = 0; _i2 < groups.length; _i2++) {
+ if (isBin(groups[_i2]) && (isBinLeftCanceller(groups[_i2 - 1], isRealGroup) || isBinRightCanceller(groups[_i2 + 1], isRealGroup))) {
+ groups[_i2].classes[0] = "mord";
+ }
+ }
+
+ // Process \\not commands within the group.
+ // TODO(kevinb): Handle multiple \\not commands in a row.
+ // TODO(kevinb): Handle \\not{abc} correctly. The \\not should appear over
+ // the 'a' instead of the 'c'.
+ for (var _i3 = 0; _i3 < groups.length; _i3++) {
+ if (groups[_i3].value === "\u0338" && _i3 + 1 < groups.length) {
+ var children = groups.slice(_i3, _i3 + 2);
+
+ children[0].classes = ["mainrm"];
+ // \u0338 is a combining glyph so we could reorder the children so
+ // that it comes after the other glyph. This works correctly on
+ // most browsers except for Safari. Instead we absolutely position
+ // the glyph and set its right side to match that of the other
+ // glyph which is visually equivalent.
+ children[0].style.position = "absolute";
+ children[0].style.right = "0";
+
+ // Copy the classes from the second glyph to the new container.
+ // This is so it behaves the same as though there was no \\not.
+ var classes = groups[_i3 + 1].classes;
+ var container = (0, _buildCommon.makeSpan)(classes, children);
+
+ // LaTeX adds a space between ords separated by a \\not.
+ if (classes.indexOf("mord") !== -1) {
+ // \glue(\thickmuskip) 2.77771 plus 2.77771
+ container.style.paddingLeft = "0.277771em";
+ }
+
+ // Ensure that the \u0338 is positioned relative to the container.
+ container.style.position = "relative";
+ groups.splice(_i3, 2, container);
+ }
+ }
+
+ return groups;
+};
+
+// Return math atom class (mclass) of a domTree.
+var getTypeOfDomTree = function getTypeOfDomTree(node) {
+ if (node instanceof _domTree2.default.documentFragment) {
+ if (node.children.length) {
+ return getTypeOfDomTree(node.children[node.children.length - 1]);
+ }
+ } else {
+ if (_utils2.default.contains(["mord", "mop", "mbin", "mrel", "mopen", "mclose", "mpunct", "minner"], node.classes[0])) {
+ return node.classes[0];
+ }
+ }
+ return null;
+};
+
+/**
+ * Sometimes, groups perform special rules when they have superscripts or
+ * subscripts attached to them. This function lets the `supsub` group know that
+ * its inner element should handle the superscripts and subscripts instead of
+ * handling them itself.
+ */
+var shouldHandleSupSub = function shouldHandleSupSub(group, options) {
+ if (!group.value.base) {
+ return false;
+ } else {
+ var base = group.value.base;
+ if (base.type === "op") {
+ // Operators handle supsubs differently when they have limits
+ // (e.g. `\displaystyle\sum_2^3`)
+ return base.value.limits && (options.style.size === _Style2.default.DISPLAY.size || base.value.alwaysHandleSupSub);
+ } else if (base.type === "accent") {
+ return isCharacterBox(base.value.base);
+ } else if (base.type === "horizBrace") {
+ var isSup = group.value.sub ? false : true;
+ return isSup === base.value.isOver;
+ } else {
+ return null;
+ }
+ }
+};
+
+/**
+ * Sometimes we want to pull out the innermost element of a group. In most
+ * cases, this will just be the group itself, but when ordgroups and colors have
+ * a single element, we want to pull that out.
+ */
+var getBaseElem = function getBaseElem(group) {
+ if (!group) {
+ return false;
+ } else if (group.type === "ordgroup") {
+ if (group.value.length === 1) {
+ return getBaseElem(group.value[0]);
+ } else {
+ return group;
+ }
+ } else if (group.type === "color") {
+ if (group.value.value.length === 1) {
+ return getBaseElem(group.value.value[0]);
+ } else {
+ return group;
+ }
+ } else if (group.type === "font") {
+ return getBaseElem(group.value.body);
+ } else {
+ return group;
+ }
+};
+
+/**
+ * TeXbook algorithms often reference "character boxes", which are simply groups
+ * with a single character in them. To decide if something is a character box,
+ * we find its innermost group, and see if it is a single character.
+ */
+var isCharacterBox = function isCharacterBox(group) {
+ var baseElem = getBaseElem(group);
+
+ // These are all they types of groups which hold single characters
+ return baseElem.type === "mathord" || baseElem.type === "textord" || baseElem.type === "bin" || baseElem.type === "rel" || baseElem.type === "inner" || baseElem.type === "open" || baseElem.type === "close" || baseElem.type === "punct";
+};
+
+var makeNullDelimiter = function makeNullDelimiter(options, classes) {
+ var moreClasses = ["nulldelimiter"].concat(options.baseSizingClasses());
+ return (0, _buildCommon.makeSpan)(classes.concat(moreClasses));
+};
+
+/**
+ * This is a map of group types to the function used to handle that type.
+ * Simpler types come at the beginning, while complicated types come afterwards.
+ */
+var groupTypes = {};
+
+groupTypes.mathord = function (group, options) {
+ return _buildCommon2.default.makeOrd(group, options, "mathord");
+};
+
+groupTypes.textord = function (group, options) {
+ return _buildCommon2.default.makeOrd(group, options, "textord");
+};
+
+groupTypes.bin = function (group, options) {
+ return _buildCommon2.default.mathsym(group.value, group.mode, options, ["mbin"]);
+};
+
+groupTypes.rel = function (group, options) {
+ return _buildCommon2.default.mathsym(group.value, group.mode, options, ["mrel"]);
+};
+
+groupTypes.open = function (group, options) {
+ return _buildCommon2.default.mathsym(group.value, group.mode, options, ["mopen"]);
+};
+
+groupTypes.close = function (group, options) {
+ return _buildCommon2.default.mathsym(group.value, group.mode, options, ["mclose"]);
+};
+
+groupTypes.inner = function (group, options) {
+ return _buildCommon2.default.mathsym(group.value, group.mode, options, ["minner"]);
+};
+
+groupTypes.punct = function (group, options) {
+ return _buildCommon2.default.mathsym(group.value, group.mode, options, ["mpunct"]);
+};
+
+groupTypes.ordgroup = function (group, options) {
+ return (0, _buildCommon.makeSpan)(["mord"], buildExpression(group.value, options, true), options);
+};
+
+groupTypes.text = function (group, options) {
+ var newOptions = options.withFont(group.value.style);
+ var inner = buildExpression(group.value.body, newOptions, true);
+ for (var i = 0; i < inner.length - 1; i++) {
+ if (inner[i].tryCombine(inner[i + 1])) {
+ inner.splice(i + 1, 1);
+ i--;
+ }
+ }
+ return (0, _buildCommon.makeSpan)(["mord", "text"], inner, newOptions);
+};
+
+groupTypes.color = function (group, options) {
+ var elements = buildExpression(group.value.value, options.withColor(group.value.color), false);
+
+ // \color isn't supposed to affect the type of the elements it contains.
+ // To accomplish this, we wrap the results in a fragment, so the inner
+ // elements will be able to directly interact with their neighbors. For
+ // example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
+ return new _buildCommon2.default.makeFragment(elements);
+};
+
+groupTypes.supsub = function (group, options) {
+ // Superscript and subscripts are handled in the TeXbook on page
+ // 445-446, rules 18(a-f).
+
+ // Here is where we defer to the inner group if it should handle
+ // superscripts and subscripts itself.
+ if (shouldHandleSupSub(group, options)) {
+ return groupTypes[group.value.base.type](group, options);
+ }
+
+ var base = buildGroup(group.value.base, options);
+ var supm = void 0;
+ var subm = void 0;
+
+ var metrics = options.fontMetrics();
+ var newOptions = void 0;
+
+ // Rule 18a
+ var supShift = 0;
+ var subShift = 0;
+
+ if (group.value.sup) {
+ newOptions = options.havingStyle(options.style.sup());
+ supm = buildGroup(group.value.sup, newOptions, options);
+ if (!isCharacterBox(group.value.base)) {
+ supShift = base.height - newOptions.fontMetrics().supDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
+ }
+ }
+
+ if (group.value.sub) {
+ newOptions = options.havingStyle(options.style.sub());
+ subm = buildGroup(group.value.sub, newOptions, options);
+ if (!isCharacterBox(group.value.base)) {
+ subShift = base.depth + newOptions.fontMetrics().subDrop * newOptions.sizeMultiplier / options.sizeMultiplier;
+ }
+ }
+
+ // Rule 18c
+ var minSupShift = void 0;
+ if (options.style === _Style2.default.DISPLAY) {
+ minSupShift = metrics.sup1;
+ } else if (options.style.cramped) {
+ minSupShift = metrics.sup3;
+ } else {
+ minSupShift = metrics.sup2;
+ }
+
+ // scriptspace is a font-size-independent size, so scale it
+ // appropriately
+ var multiplier = options.sizeMultiplier;
+ var scriptspace = 0.5 / metrics.ptPerEm / multiplier + "em";
+
+ var supsub = void 0;
+ if (!group.value.sup) {
+ // Rule 18b
+ subShift = Math.max(subShift, metrics.sub1, subm.height - 0.8 * metrics.xHeight);
+
+ var vlistElem = [{ type: "elem", elem: subm, marginRight: scriptspace }];
+ // Subscripts shouldn't be shifted by the base's italic correction.
+ // Account for that by shifting the subscript back the appropriate
+ // amount. Note we only do this when the base is a single symbol.
+ if (base instanceof _domTree2.default.symbolNode) {
+ vlistElem[0].marginLeft = -base.italic + "em";
+ }
+
+ supsub = _buildCommon2.default.makeVList(vlistElem, "shift", subShift, options);
+ } else if (!group.value.sub) {
+ // Rule 18c, d
+ supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
+
+ supsub = _buildCommon2.default.makeVList([{ type: "elem", elem: supm, marginRight: scriptspace }], "shift", -supShift, options);
+ } else {
+ supShift = Math.max(supShift, minSupShift, supm.depth + 0.25 * metrics.xHeight);
+ subShift = Math.max(subShift, metrics.sub2);
+
+ var ruleWidth = metrics.defaultRuleThickness;
+
+ // Rule 18e
+ if (supShift - supm.depth - (subm.height - subShift) < 4 * ruleWidth) {
+ subShift = 4 * ruleWidth - (supShift - supm.depth) + subm.height;
+ var psi = 0.8 * metrics.xHeight - (supShift - supm.depth);
+ if (psi > 0) {
+ supShift += psi;
+ subShift -= psi;
+ }
+ }
+
+ var _vlistElem = [{ type: "elem", elem: subm, shift: subShift, marginRight: scriptspace }, { type: "elem", elem: supm, shift: -supShift, marginRight: scriptspace }];
+ // See comment above about subscripts not being shifted
+ if (base instanceof _domTree2.default.symbolNode) {
+ _vlistElem[0].marginLeft = -base.italic + "em";
+ }
+
+ supsub = _buildCommon2.default.makeVList(_vlistElem, "individualShift", null, options);
+ }
+
+ // We ensure to wrap the supsub vlist in a span.msupsub to reset text-align
+ var mclass = getTypeOfDomTree(base) || "mord";
+ return (0, _buildCommon.makeSpan)([mclass], [base, (0, _buildCommon.makeSpan)(["msupsub"], [supsub])], options);
+};
+
+groupTypes.genfrac = function (group, options) {
+ // Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
+ // Figure out what style this fraction should be in based on the
+ // function used
+ var style = options.style;
+ if (group.value.size === "display") {
+ style = _Style2.default.DISPLAY;
+ } else if (group.value.size === "text") {
+ style = _Style2.default.TEXT;
+ }
+
+ var nstyle = style.fracNum();
+ var dstyle = style.fracDen();
+ var newOptions = void 0;
+
+ newOptions = options.havingStyle(nstyle);
+ var numerm = buildGroup(group.value.numer, newOptions, options);
+
+ newOptions = options.havingStyle(dstyle);
+ var denomm = buildGroup(group.value.denom, newOptions, options);
+
+ var rule = void 0;
+ var ruleWidth = void 0;
+ var ruleSpacing = void 0;
+ if (group.value.hasBarLine) {
+ rule = makeLineSpan("frac-line", options);
+ ruleWidth = rule.height;
+ ruleSpacing = rule.height;
+ } else {
+ rule = null;
+ ruleWidth = 0;
+ ruleSpacing = options.fontMetrics().defaultRuleThickness;
+ }
+
+ // Rule 15b
+ var numShift = void 0;
+ var clearance = void 0;
+ var denomShift = void 0;
+ if (style.size === _Style2.default.DISPLAY.size) {
+ numShift = options.fontMetrics().num1;
+ if (ruleWidth > 0) {
+ clearance = 3 * ruleSpacing;
+ } else {
+ clearance = 7 * ruleSpacing;
+ }
+ denomShift = options.fontMetrics().denom1;
+ } else {
+ if (ruleWidth > 0) {
+ numShift = options.fontMetrics().num2;
+ clearance = ruleSpacing;
+ } else {
+ numShift = options.fontMetrics().num3;
+ clearance = 3 * ruleSpacing;
+ }
+ denomShift = options.fontMetrics().denom2;
+ }
+
+ var frac = void 0;
+ if (ruleWidth === 0) {
+ // Rule 15c
+ var candidateClearance = numShift - numerm.depth - (denomm.height - denomShift);
+ if (candidateClearance < clearance) {
+ numShift += 0.5 * (clearance - candidateClearance);
+ denomShift += 0.5 * (clearance - candidateClearance);
+ }
+
+ frac = _buildCommon2.default.makeVList([{ type: "elem", elem: denomm, shift: denomShift }, { type: "elem", elem: numerm, shift: -numShift }], "individualShift", null, options);
+ } else {
+ // Rule 15d
+ var axisHeight = options.fontMetrics().axisHeight;
+
+ if (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth) < clearance) {
+ numShift += clearance - (numShift - numerm.depth - (axisHeight + 0.5 * ruleWidth));
+ }
+
+ if (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift) < clearance) {
+ denomShift += clearance - (axisHeight - 0.5 * ruleWidth - (denomm.height - denomShift));
+ }
+
+ var midShift = -(axisHeight - 0.5 * ruleWidth);
+
+ frac = _buildCommon2.default.makeVList([{ type: "elem", elem: denomm, shift: denomShift }, { type: "elem", elem: rule, shift: midShift }, { type: "elem", elem: numerm, shift: -numShift }], "individualShift", null, options);
+ }
+
+ // Since we manually change the style sometimes (with \dfrac or \tfrac),
+ // account for the possible size change here.
+ newOptions = options.havingStyle(style);
+ frac.height *= newOptions.sizeMultiplier / options.sizeMultiplier;
+ frac.depth *= newOptions.sizeMultiplier / options.sizeMultiplier;
+
+ // Rule 15e
+ var delimSize = void 0;
+ if (style.size === _Style2.default.DISPLAY.size) {
+ delimSize = options.fontMetrics().delim1;
+ } else {
+ delimSize = options.fontMetrics().delim2;
+ }
+
+ var leftDelim = void 0;
+ var rightDelim = void 0;
+ if (group.value.leftDelim == null) {
+ leftDelim = makeNullDelimiter(options, ["mopen"]);
+ } else {
+ leftDelim = _delimiter2.default.customSizedDelim(group.value.leftDelim, delimSize, true, options.havingStyle(style), group.mode, ["mopen"]);
+ }
+ if (group.value.rightDelim == null) {
+ rightDelim = makeNullDelimiter(options, ["mclose"]);
+ } else {
+ rightDelim = _delimiter2.default.customSizedDelim(group.value.rightDelim, delimSize, true, options.havingStyle(style), group.mode, ["mclose"]);
+ }
+
+ return (0, _buildCommon.makeSpan)(["mord"].concat(newOptions.sizingClasses(options)), [leftDelim, (0, _buildCommon.makeSpan)(["mfrac"], [frac]), rightDelim], options);
+};
+
+groupTypes.array = function (group, options) {
+ var r = void 0;
+ var c = void 0;
+ var nr = group.value.body.length;
+ var nc = 0;
+ var body = new Array(nr);
+
+ // Horizontal spacing
+ var pt = 1 / options.fontMetrics().ptPerEm;
+ var arraycolsep = 5 * pt; // \arraycolsep in article.cls
+
+ // Vertical spacing
+ var baselineskip = 12 * pt; // see size10.clo
+ // Default \jot from ltmath.dtx
+ // TODO(edemaine): allow overriding \jot via \setlength (#687)
+ var jot = 3 * pt;
+ // Default \arraystretch from lttab.dtx
+ // TODO(gagern): may get redefined once we have user-defined macros
+ var arraystretch = _utils2.default.deflt(group.value.arraystretch, 1);
+ var arrayskip = arraystretch * baselineskip;
+ var arstrutHeight = 0.7 * arrayskip; // \strutbox in ltfsstrc.dtx and
+ var arstrutDepth = 0.3 * arrayskip; // \@arstrutbox in lttab.dtx
+
+ var totalHeight = 0;
+ for (r = 0; r < group.value.body.length; ++r) {
+ var inrow = group.value.body[r];
+ var height = arstrutHeight; // \@array adds an \@arstrut
+ var depth = arstrutDepth; // to each tow (via the template)
+
+ if (nc < inrow.length) {
+ nc = inrow.length;
+ }
+
+ var outrow = new Array(inrow.length);
+ for (c = 0; c < inrow.length; ++c) {
+ var elt = buildGroup(inrow[c], options);
+ if (depth < elt.depth) {
+ depth = elt.depth;
+ }
+ if (height < elt.height) {
+ height = elt.height;
+ }
+ outrow[c] = elt;
+ }
+
+ var gap = 0;
+ if (group.value.rowGaps[r]) {
+ gap = _units2.default.calculateSize(group.value.rowGaps[r].value, options);
+ if (gap > 0) {
+ // \@argarraycr
+ gap += arstrutDepth;
+ if (depth < gap) {
+ depth = gap; // \@xargarraycr
+ }
+ gap = 0;
+ }
+ }
+ // In AMS multiline environments such as aligned and gathered, rows
+ // correspond to lines that have additional \jot added to the
+ // \baselineskip via \openup.
+ if (group.value.addJot) {
+ depth += jot;
+ }
+
+ outrow.height = height;
+ outrow.depth = depth;
+ totalHeight += height;
+ outrow.pos = totalHeight;
+ totalHeight += depth + gap; // \@yargarraycr
+ body[r] = outrow;
+ }
+
+ var offset = totalHeight / 2 + options.fontMetrics().axisHeight;
+ var colDescriptions = group.value.cols || [];
+ var cols = [];
+ var colSep = void 0;
+ var colDescrNum = void 0;
+ for (c = 0, colDescrNum = 0;
+ // Continue while either there are more columns or more column
+ // descriptions, so trailing separators don't get lost.
+ c < nc || colDescrNum < colDescriptions.length; ++c, ++colDescrNum) {
+
+ var colDescr = colDescriptions[colDescrNum] || {};
+
+ var firstSeparator = true;
+ while (colDescr.type === "separator") {
+ // If there is more than one separator in a row, add a space
+ // between them.
+ if (!firstSeparator) {
+ colSep = (0, _buildCommon.makeSpan)(["arraycolsep"], []);
+ colSep.style.width = options.fontMetrics().doubleRuleSep + "em";
+ cols.push(colSep);
+ }
+
+ if (colDescr.separator === "|") {
+ var separator = (0, _buildCommon.makeSpan)(["vertical-separator"], []);
+ separator.style.height = totalHeight + "em";
+ separator.style.verticalAlign = -(totalHeight - offset) + "em";
+
+ cols.push(separator);
+ } else {
+ throw new _ParseError2.default("Invalid separator type: " + colDescr.separator);
+ }
+
+ colDescrNum++;
+ colDescr = colDescriptions[colDescrNum] || {};
+ firstSeparator = false;
+ }
+
+ if (c >= nc) {
+ continue;
+ }
+
+ var sepwidth = void 0;
+ if (c > 0 || group.value.hskipBeforeAndAfter) {
+ sepwidth = _utils2.default.deflt(colDescr.pregap, arraycolsep);
+ if (sepwidth !== 0) {
+ colSep = (0, _buildCommon.makeSpan)(["arraycolsep"], []);
+ colSep.style.width = sepwidth + "em";
+ cols.push(colSep);
+ }
+ }
+
+ var col = [];
+ for (r = 0; r < nr; ++r) {
+ var row = body[r];
+ var elem = row[c];
+ if (!elem) {
+ continue;
+ }
+ var shift = row.pos - offset;
+ elem.depth = row.depth;
+ elem.height = row.height;
+ col.push({ type: "elem", elem: elem, shift: shift });
+ }
+
+ col = _buildCommon2.default.makeVList(col, "individualShift", null, options);
+ col = (0, _buildCommon.makeSpan)(["col-align-" + (colDescr.align || "c")], [col]);
+ cols.push(col);
+
+ if (c < nc - 1 || group.value.hskipBeforeAndAfter) {
+ sepwidth = _utils2.default.deflt(colDescr.postgap, arraycolsep);
+ if (sepwidth !== 0) {
+ colSep = (0, _buildCommon.makeSpan)(["arraycolsep"], []);
+ colSep.style.width = sepwidth + "em";
+ cols.push(colSep);
+ }
+ }
+ }
+ body = (0, _buildCommon.makeSpan)(["mtable"], cols);
+ return (0, _buildCommon.makeSpan)(["mord"], [body], options);
+};
+
+groupTypes.spacing = function (group, options) {
+ if (group.value === "\\ " || group.value === "\\space" || group.value === " " || group.value === "~") {
+ // Spaces are generated by adding an actual space. Each of these
+ // things has an entry in the symbols table, so these will be turned
+ // into appropriate outputs.
+ if (group.mode === "text") {
+ return _buildCommon2.default.makeOrd(group, options, "textord");
+ } else {
+ return (0, _buildCommon.makeSpan)(["mspace"], [_buildCommon2.default.mathsym(group.value, group.mode, options)], options);
+ }
+ } else {
+ // Other kinds of spaces are of arbitrary width. We use CSS to
+ // generate these.
+ return (0, _buildCommon.makeSpan)(["mspace", _buildCommon2.default.spacingFunctions[group.value].className], [], options);
+ }
+};
+
+groupTypes.llap = function (group, options) {
+ var inner = (0, _buildCommon.makeSpan)(["inner"], [buildGroup(group.value.body, options)]);
+ var fix = (0, _buildCommon.makeSpan)(["fix"], []);
+ return (0, _buildCommon.makeSpan)(["mord", "llap"], [inner, fix], options);
+};
+
+groupTypes.rlap = function (group, options) {
+ var inner = (0, _buildCommon.makeSpan)(["inner"], [buildGroup(group.value.body, options)]);
+ var fix = (0, _buildCommon.makeSpan)(["fix"], []);
+ return (0, _buildCommon.makeSpan)(["mord", "rlap"], [inner, fix], options);
+};
+
+groupTypes.op = function (group, options) {
+ // Operators are handled in the TeXbook pg. 443-444, rule 13(a).
+ var supGroup = void 0;
+ var subGroup = void 0;
+ var hasLimits = false;
+ if (group.type === "supsub") {
+ // If we have limits, supsub will pass us its group to handle. Pull
+ // out the superscript and subscript and set the group to the op in
+ // its base.
+ supGroup = group.value.sup;
+ subGroup = group.value.sub;
+ group = group.value.base;
+ hasLimits = true;
+ }
+
+ var style = options.style;
+
+ // Most operators have a large successor symbol, but these don't.
+ var noSuccessor = ["\\smallint"];
+
+ var large = false;
+ if (style.size === _Style2.default.DISPLAY.size && group.value.symbol && !_utils2.default.contains(noSuccessor, group.value.body)) {
+
+ // Most symbol operators get larger in displaystyle (rule 13)
+ large = true;
+ }
+
+ var base = void 0;
+ if (group.value.symbol) {
+ // If this is a symbol, create the symbol.
+ var fontName = large ? "Size2-Regular" : "Size1-Regular";
+ base = _buildCommon2.default.makeSymbol(group.value.body, fontName, "math", options, ["mop", "op-symbol", large ? "large-op" : "small-op"]);
+ } else if (group.value.value) {
+ // If this is a list, compose that list.
+ var inner = buildExpression(group.value.value, options, true);
+ if (inner.length === 1 && inner[0] instanceof _domTree2.default.symbolNode) {
+ base = inner[0];
+ base.classes[0] = "mop"; // replace old mclass
+ } else {
+ base = (0, _buildCommon.makeSpan)(["mop"], inner, options);
+ }
+ } else {
+ // Otherwise, this is a text operator. Build the text from the
+ // operator's name.
+ // TODO(emily): Add a space in the middle of some of these
+ // operators, like \limsup
+ var output = [];
+ for (var i = 1; i < group.value.body.length; i++) {
+ output.push(_buildCommon2.default.mathsym(group.value.body[i], group.mode));
+ }
+ base = (0, _buildCommon.makeSpan)(["mop"], output, options);
+ }
+
+ // If content of op is a single symbol, shift it vertically.
+ var baseShift = 0;
+ var slant = 0;
+ if (base instanceof _domTree2.default.symbolNode) {
+ // Shift the symbol so its center lies on the axis (rule 13). It
+ // appears that our fonts have the centers of the symbols already
+ // almost on the axis, so these numbers are very small. Note we
+ // don't actually apply this here, but instead it is used either in
+ // the vlist creation or separately when there are no limits.
+ baseShift = (base.height - base.depth) / 2 - options.fontMetrics().axisHeight;
+
+ // The slant of the symbol is just its italic correction.
+ slant = base.italic;
+ }
+
+ if (hasLimits) {
+ // IE 8 clips \int if it is in a display: inline-block. We wrap it
+ // in a new span so it is an inline, and works.
+ base = (0, _buildCommon.makeSpan)([], [base]);
+
+ var supm = void 0;
+ var supKern = void 0;
+ var subm = void 0;
+ var subKern = void 0;
+ var newOptions = void 0;
+ // We manually have to handle the superscripts and subscripts. This,
+ // aside from the kern calculations, is copied from supsub.
+ if (supGroup) {
+ newOptions = options.havingStyle(style.sup());
+ supm = buildGroup(supGroup, newOptions, options);
+
+ supKern = Math.max(options.fontMetrics().bigOpSpacing1, options.fontMetrics().bigOpSpacing3 - supm.depth);
+ }
+
+ if (subGroup) {
+ newOptions = options.havingStyle(style.sub());
+ subm = buildGroup(subGroup, newOptions, options);
+
+ subKern = Math.max(options.fontMetrics().bigOpSpacing2, options.fontMetrics().bigOpSpacing4 - subm.height);
+ }
+
+ // Build the final group as a vlist of the possible subscript, base,
+ // and possible superscript.
+ var finalGroup = void 0;
+ var top = void 0;
+ var bottom = void 0;
+ if (!supGroup) {
+ top = base.height - baseShift;
+
+ // Shift the limits by the slant of the symbol. Note
+ // that we are supposed to shift the limits by 1/2 of the slant,
+ // but since we are centering the limits adding a full slant of
+ // margin will shift by 1/2 that.
+ finalGroup = _buildCommon2.default.makeVList([{ type: "kern", size: options.fontMetrics().bigOpSpacing5 }, { type: "elem", elem: subm, marginLeft: -slant + "em" }, { type: "kern", size: subKern }, { type: "elem", elem: base }], "top", top, options);
+ } else if (!subGroup) {
+ bottom = base.depth + baseShift;
+
+ finalGroup = _buildCommon2.default.makeVList([{ type: "elem", elem: base }, { type: "kern", size: supKern }, { type: "elem", elem: supm, marginLeft: slant + "em" }, { type: "kern", size: options.fontMetrics().bigOpSpacing5 }], "bottom", bottom, options);
+ } else if (!supGroup && !subGroup) {
+ // This case probably shouldn't occur (this would mean the
+ // supsub was sending us a group with no superscript or
+ // subscript) but be safe.
+ return base;
+ } else {
+ bottom = options.fontMetrics().bigOpSpacing5 + subm.height + subm.depth + subKern + base.depth + baseShift;
+
+ finalGroup = _buildCommon2.default.makeVList([{ type: "kern", size: options.fontMetrics().bigOpSpacing5 }, { type: "elem", elem: subm, marginLeft: -slant + "em" }, { type: "kern", size: subKern }, { type: "elem", elem: base }, { type: "kern", size: supKern }, { type: "elem", elem: supm, marginLeft: slant + "em" }, { type: "kern", size: options.fontMetrics().bigOpSpacing5 }], "bottom", bottom, options);
+ }
+
+ return (0, _buildCommon.makeSpan)(["mop", "op-limits"], [finalGroup], options);
+ } else {
+ if (baseShift) {
+ base.style.position = "relative";
+ base.style.top = baseShift + "em";
+ }
+
+ return base;
+ }
+};
+
+groupTypes.mod = function (group, options) {
+ var inner = [];
+
+ if (group.value.modType === "bmod") {
+ // “\nonscript\mskip-\medmuskip\mkern5mu”
+ if (!options.style.isTight()) {
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "negativemediumspace"], [], options));
+ }
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "thickspace"], [], options));
+ } else if (options.style.size === _Style2.default.DISPLAY.size) {
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "quad"], [], options));
+ } else if (group.value.modType === "mod") {
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "twelvemuspace"], [], options));
+ } else {
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "eightmuspace"], [], options));
+ }
+
+ if (group.value.modType === "pod" || group.value.modType === "pmod") {
+ inner.push(_buildCommon2.default.mathsym("(", group.mode));
+ }
+
+ if (group.value.modType !== "pod") {
+ var modInner = [_buildCommon2.default.mathsym("m", group.mode), _buildCommon2.default.mathsym("o", group.mode), _buildCommon2.default.mathsym("d", group.mode)];
+ if (group.value.modType === "bmod") {
+ inner.push((0, _buildCommon.makeSpan)(["mbin"], modInner, options));
+ // “\mkern5mu\nonscript\mskip-\medmuskip”
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "thickspace"], [], options));
+ if (!options.style.isTight()) {
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "negativemediumspace"], [], options));
+ }
+ } else {
+ Array.prototype.push.apply(inner, modInner);
+ inner.push((0, _buildCommon.makeSpan)(["mspace", "sixmuspace"], [], options));
+ }
+ }
+
+ if (group.value.value) {
+ Array.prototype.push.apply(inner, buildExpression(group.value.value, options, false));
+ }
+
+ if (group.value.modType === "pod" || group.value.modType === "pmod") {
+ inner.push(_buildCommon2.default.mathsym(")", group.mode));
+ }
+
+ return _buildCommon2.default.makeFragment(inner);
+};
+
+groupTypes.katex = function (group, options) {
+ // The KaTeX logo. The offsets for the K and a were chosen to look
+ // good, but the offsets for the T, E, and X were taken from the
+ // definition of \TeX in TeX (see TeXbook pg. 356)
+ var k = (0, _buildCommon.makeSpan)(["k"], [_buildCommon2.default.mathsym("K", group.mode)], options);
+ var a = (0, _buildCommon.makeSpan)(["a"], [_buildCommon2.default.mathsym("A", group.mode)], options);
+
+ a.height = (a.height + 0.2) * 0.75;
+ a.depth = (a.height - 0.2) * 0.75;
+
+ var t = (0, _buildCommon.makeSpan)(["t"], [_buildCommon2.default.mathsym("T", group.mode)], options);
+ var e = (0, _buildCommon.makeSpan)(["e"], [_buildCommon2.default.mathsym("E", group.mode)], options);
+
+ e.height = e.height - 0.2155;
+ e.depth = e.depth + 0.2155;
+
+ var x = (0, _buildCommon.makeSpan)(["x"], [_buildCommon2.default.mathsym("X", group.mode)], options);
+
+ return (0, _buildCommon.makeSpan)(["mord", "katex-logo"], [k, a, t, e, x], options);
+};
+
+var makeLineSpan = function makeLineSpan(className, options, thickness) {
+ var line = (0, _buildCommon.makeSpan)([className], [], options);
+ line.height = thickness || options.fontMetrics().defaultRuleThickness;
+ line.style.borderBottomWidth = line.height + "em";
+ line.maxFontSize = 1.0;
+ return line;
+};
+
+groupTypes.overline = function (group, options) {
+ // Overlines are handled in the TeXbook pg 443, Rule 9.
+
+ // Build the inner group in the cramped style.
+ var innerGroup = buildGroup(group.value.body, options.havingCrampedStyle());
+
+ // Create the line above the body
+ var line = makeLineSpan("overline-line", options);
+
+ // Generate the vlist, with the appropriate kerns
+ var vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: innerGroup }, { type: "kern", size: 3 * line.height }, { type: "elem", elem: line }, { type: "kern", size: line.height }], "firstBaseline", null, options);
+
+ return (0, _buildCommon.makeSpan)(["mord", "overline"], [vlist], options);
+};
+
+groupTypes.underline = function (group, options) {
+ // Underlines are handled in the TeXbook pg 443, Rule 10.
+ // Build the inner group.
+ var innerGroup = buildGroup(group.value.body, options);
+
+ // Create the line above the body
+ var line = makeLineSpan("underline-line", options);
+
+ // Generate the vlist, with the appropriate kerns
+ var vlist = _buildCommon2.default.makeVList([{ type: "kern", size: line.height }, { type: "elem", elem: line }, { type: "kern", size: 3 * line.height }, { type: "elem", elem: innerGroup }], "top", innerGroup.height, options);
+
+ return (0, _buildCommon.makeSpan)(["mord", "underline"], [vlist], options);
+};
+
+groupTypes.sqrt = function (group, options) {
+ // Square roots are handled in the TeXbook pg. 443, Rule 11.
+
+ // First, we do the same steps as in overline to build the inner group
+ // and line
+ var inner = buildGroup(group.value.body, options.havingCrampedStyle());
+
+ // Some groups can return document fragments. Handle those by wrapping
+ // them in a span.
+ if (inner instanceof _domTree2.default.documentFragment) {
+ inner = (0, _buildCommon.makeSpan)([], [inner], options);
+ }
+
+ // Calculate the minimum size for the \surd delimiter
+ var metrics = options.fontMetrics();
+ var theta = metrics.defaultRuleThickness;
+
+ var phi = theta;
+ if (options.style.id < _Style2.default.TEXT.id) {
+ phi = options.fontMetrics().xHeight;
+ }
+
+ // Calculate the clearance between the body and line
+ var lineClearance = theta + phi / 4;
+
+ var minDelimiterHeight = (inner.height + inner.depth + lineClearance + theta) * options.sizeMultiplier;
+
+ // Create a sqrt SVG of the required minimum size
+ var img = _delimiter2.default.customSizedDelim("\\surd", minDelimiterHeight, false, options, group.mode);
+
+ // Calculate the actual line width.
+ // This actually should depend on the chosen font -- e.g. \boldmath
+ // should use the thicker surd symbols from e.g. KaTeX_Main-Bold, and
+ // have thicker rules.
+ var ruleWidth = options.fontMetrics().sqrtRuleThickness * img.sizeMultiplier;
+
+ var delimDepth = img.height - ruleWidth;
+
+ // Adjust the clearance based on the delimiter size
+ if (delimDepth > inner.height + inner.depth + lineClearance) {
+ lineClearance = (lineClearance + delimDepth - inner.height - inner.depth) / 2;
+ }
+
+ // Shift the sqrt image
+ var imgShift = img.height - inner.height - lineClearance - ruleWidth;
+
+ // We add a special case here, because even when `inner` is empty, we
+ // still get a line. So, we use a simple heuristic to decide if we
+ // should omit the body entirely. (note this doesn't work for something
+ // like `\sqrt{\rlap{x}}`, but if someone is doing that they deserve for
+ // it not to work.
+ var body = void 0;
+ if (inner.height === 0 && inner.depth === 0) {
+ body = (0, _buildCommon.makeSpan)();
+ } else {
+ inner.style.paddingLeft = img.surdWidth + "em";
+
+ // Overlay the image and the argument.
+ body = _buildCommon2.default.makeVList([{ type: "elem", elem: inner }, { type: "kern", size: -(inner.height + imgShift) }, { type: "elem", elem: img }, { type: "kern", size: ruleWidth }], "firstBaseline", null, options);
+ body.children[0].children[0].classes.push("svg-align");
+ }
+
+ if (!group.value.index) {
+ return (0, _buildCommon.makeSpan)(["mord", "sqrt"], [body], options);
+ } else {
+ // Handle the optional root index
+
+ // The index is always in scriptscript style
+ var newOptions = options.havingStyle(_Style2.default.SCRIPTSCRIPT);
+ var rootm = buildGroup(group.value.index, newOptions, options);
+
+ // The amount the index is shifted by. This is taken from the TeX
+ // source, in the definition of `\r@@t`.
+ var toShift = 0.6 * (body.height - body.depth);
+
+ // Build a VList with the superscript shifted up correctly
+ var rootVList = _buildCommon2.default.makeVList([{ type: "elem", elem: rootm }], "shift", -toShift, options);
+ // Add a class surrounding it so we can add on the appropriate
+ // kerning
+ var rootVListWrap = (0, _buildCommon.makeSpan)(["root"], [rootVList]);
+
+ return (0, _buildCommon.makeSpan)(["mord", "sqrt"], [rootVListWrap, body], options);
+ }
+};
+
+function sizingGroup(value, options, baseOptions) {
+ var inner = buildExpression(value, options, false);
+ var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
+
+ // Add size-resetting classes to the inner list and set maxFontSize
+ // manually. Handle nested size changes.
+ for (var i = 0; i < inner.length; i++) {
+ var pos = _utils2.default.indexOf(inner[i].classes, "sizing");
+ if (pos < 0) {
+ Array.prototype.push.apply(inner[i].classes, options.sizingClasses(baseOptions));
+ } else if (inner[i].classes[pos + 1] === "reset-size" + options.size) {
+ // This is a nested size change: e.g., inner[i] is the "b" in
+ // `\Huge a \small b`. Override the old size (the `reset-` class)
+ // but not the new size.
+ inner[i].classes[pos + 1] = "reset-size" + baseOptions.size;
+ }
+
+ inner[i].height *= multiplier;
+ inner[i].depth *= multiplier;
+ }
+
+ return _buildCommon2.default.makeFragment(inner);
+}
+
+groupTypes.sizing = function (group, options) {
+ // Handle sizing operators like \Huge. Real TeX doesn't actually allow
+ // these functions inside of math expressions, so we do some special
+ // handling.
+ var newOptions = options.havingSize(group.value.size);
+ return sizingGroup(group.value.value, newOptions, options);
+};
+
+groupTypes.styling = function (group, options) {
+ // Style changes are handled in the TeXbook on pg. 442, Rule 3.
+
+ // Figure out what style we're changing to.
+ var styleMap = {
+ "display": _Style2.default.DISPLAY,
+ "text": _Style2.default.TEXT,
+ "script": _Style2.default.SCRIPT,
+ "scriptscript": _Style2.default.SCRIPTSCRIPT
+ };
+
+ var newStyle = styleMap[group.value.style];
+ var newOptions = options.havingStyle(newStyle);
+ return sizingGroup(group.value.value, newOptions, options);
+};
+
+groupTypes.font = function (group, options) {
+ var font = group.value.font;
+ return buildGroup(group.value.body, options.withFont(font));
+};
+
+groupTypes.delimsizing = function (group, options) {
+ var delim = group.value.value;
+
+ if (delim === ".") {
+ // Empty delimiters still count as elements, even though they don't
+ // show anything.
+ return (0, _buildCommon.makeSpan)([group.value.mclass]);
+ }
+
+ // Use delimiter.sizedDelim to generate the delimiter.
+ return _delimiter2.default.sizedDelim(delim, group.value.size, options, group.mode, [group.value.mclass]);
+};
+
+groupTypes.leftright = function (group, options) {
+ // Build the inner expression
+ var inner = buildExpression(group.value.body, options, true);
+
+ var innerHeight = 0;
+ var innerDepth = 0;
+ var hadMiddle = false;
+
+ // Calculate its height and depth
+ for (var i = 0; i < inner.length; i++) {
+ if (inner[i].isMiddle) {
+ hadMiddle = true;
+ } else {
+ innerHeight = Math.max(inner[i].height, innerHeight);
+ innerDepth = Math.max(inner[i].depth, innerDepth);
+ }
+ }
+
+ // The size of delimiters is the same, regardless of what style we are
+ // in. Thus, to correctly calculate the size of delimiter we need around
+ // a group, we scale down the inner size based on the size.
+ innerHeight *= options.sizeMultiplier;
+ innerDepth *= options.sizeMultiplier;
+
+ var leftDelim = void 0;
+ if (group.value.left === ".") {
+ // Empty delimiters in \left and \right make null delimiter spaces.
+ leftDelim = makeNullDelimiter(options, ["mopen"]);
+ } else {
+ // Otherwise, use leftRightDelim to generate the correct sized
+ // delimiter.
+ leftDelim = _delimiter2.default.leftRightDelim(group.value.left, innerHeight, innerDepth, options, group.mode, ["mopen"]);
+ }
+ // Add it to the beginning of the expression
+ inner.unshift(leftDelim);
+
+ // Handle middle delimiters
+ if (hadMiddle) {
+ for (var _i4 = 1; _i4 < inner.length; _i4++) {
+ var middleDelim = inner[_i4];
+ if (middleDelim.isMiddle) {
+ // Apply the options that were active when \middle was called
+ inner[_i4] = _delimiter2.default.leftRightDelim(middleDelim.isMiddle.value, innerHeight, innerDepth, middleDelim.isMiddle.options, group.mode, []);
+ // Add back spaces shifted into the delimiter
+ var spaces = spliceSpaces(middleDelim.children, 0);
+ if (spaces) {
+ _buildCommon2.default.prependChildren(inner[_i4], spaces);
+ }
+ }
+ }
+ }
+
+ var rightDelim = void 0;
+ // Same for the right delimiter
+ if (group.value.right === ".") {
+ rightDelim = makeNullDelimiter(options, ["mclose"]);
+ } else {
+ rightDelim = _delimiter2.default.leftRightDelim(group.value.right, innerHeight, innerDepth, options, group.mode, ["mclose"]);
+ }
+ // Add it to the end of the expression.
+ inner.push(rightDelim);
+
+ return (0, _buildCommon.makeSpan)(["minner"], inner, options);
+};
+
+groupTypes.middle = function (group, options) {
+ var middleDelim = void 0;
+ if (group.value.value === ".") {
+ middleDelim = makeNullDelimiter(options, []);
+ } else {
+ middleDelim = _delimiter2.default.sizedDelim(group.value.value, 1, options, group.mode, []);
+ middleDelim.isMiddle = { value: group.value.value, options: options };
+ }
+ return middleDelim;
+};
+
+groupTypes.rule = function (group, options) {
+ // Make an empty span for the rule
+ var rule = (0, _buildCommon.makeSpan)(["mord", "rule"], [], options);
+
+ // Calculate the shift, width, and height of the rule, and account for units
+ var shift = 0;
+ if (group.value.shift) {
+ shift = _units2.default.calculateSize(group.value.shift, options);
+ }
+
+ var width = _units2.default.calculateSize(group.value.width, options);
+ var height = _units2.default.calculateSize(group.value.height, options);
+
+ // Style the rule to the right size
+ rule.style.borderRightWidth = width + "em";
+ rule.style.borderTopWidth = height + "em";
+ rule.style.bottom = shift + "em";
+
+ // Record the height and width
+ rule.width = width;
+ rule.height = height + shift;
+ rule.depth = -shift;
+ // Font size is the number large enough that the browser will
+ // reserve at least `absHeight` space above the baseline.
+ // The 1.125 factor was empirically determined
+ rule.maxFontSize = height * 1.125 * options.sizeMultiplier;
+
+ return rule;
+};
+
+groupTypes.kern = function (group, options) {
+ // Make an empty span for the rule
+ var rule = (0, _buildCommon.makeSpan)(["mord", "rule"], [], options);
+
+ if (group.value.dimension) {
+ var dimension = _units2.default.calculateSize(group.value.dimension, options);
+ rule.style.marginLeft = dimension + "em";
+ }
+
+ return rule;
+};
+
+groupTypes.accent = function (group, options) {
+ // Accents are handled in the TeXbook pg. 443, rule 12.
+ var base = group.value.base;
+
+ var supsubGroup = void 0;
+ if (group.type === "supsub") {
+ // If our base is a character box, and we have superscripts and
+ // subscripts, the supsub will defer to us. In particular, we want
+ // to attach the superscripts and subscripts to the inner body (so
+ // that the position of the superscripts and subscripts won't be
+ // affected by the height of the accent). We accomplish this by
+ // sticking the base of the accent into the base of the supsub, and
+ // rendering that, while keeping track of where the accent is.
+
+ // The supsub group is the group that was passed in
+ var supsub = group;
+ // The real accent group is the base of the supsub group
+ group = supsub.value.base;
+ // The character box is the base of the accent group
+ base = group.value.base;
+ // Stick the character box into the base of the supsub group
+ supsub.value.base = base;
+
+ // Rerender the supsub group with its new base, and store that
+ // result.
+ supsubGroup = buildGroup(supsub, options);
+ }
+
+ // Build the base group
+ var body = buildGroup(base, options.havingCrampedStyle());
+
+ // Does the accent need to shift for the skew of a character?
+ var mustShift = group.value.isShifty && isCharacterBox(base);
+
+ // Calculate the skew of the accent. This is based on the line "If the
+ // nucleus is not a single character, let s = 0; otherwise set s to the
+ // kern amount for the nucleus followed by the \skewchar of its font."
+ // Note that our skew metrics are just the kern between each character
+ // and the skewchar.
+ var skew = 0;
+ if (mustShift) {
+ // If the base is a character box, then we want the skew of the
+ // innermost character. To do that, we find the innermost character:
+ var baseChar = getBaseElem(base);
+ // Then, we render its group to get the symbol inside it
+ var baseGroup = buildGroup(baseChar, options.havingCrampedStyle());
+ // Finally, we pull the skew off of the symbol.
+ skew = baseGroup.skew;
+ // Note that we now throw away baseGroup, because the layers we
+ // removed with getBaseElem might contain things like \color which
+ // we can't get rid of.
+ // TODO(emily): Find a better way to get the skew
+ }
+
+ // calculate the amount of space between the body and the accent
+ var clearance = Math.min(body.height, options.fontMetrics().xHeight);
+
+ // Build the accent
+ var accentBody = void 0;
+ if (!group.value.isStretchy) {
+ var accent = _buildCommon2.default.makeSymbol(group.value.label, "Main-Regular", group.mode, options);
+ // Remove the italic correction of the accent, because it only serves to
+ // shift the accent over to a place we don't want.
+ accent.italic = 0;
+
+ // The \vec character that the fonts use is a combining character, and
+ // thus shows up much too far to the left. To account for this, we add a
+ // specific class which shifts the accent over to where we want it.
+ // TODO(emily): Fix this in a better way, like by changing the font
+ // Similarly, text accent \H is a combining character and
+ // requires a different adjustment.
+ var accentClass = null;
+ if (group.value.label === "\\vec") {
+ accentClass = "accent-vec";
+ } else if (group.value.label === '\\H') {
+ accentClass = "accent-hungarian";
+ }
+
+ accentBody = (0, _buildCommon.makeSpan)([], [accent]);
+ accentBody = (0, _buildCommon.makeSpan)(["accent-body", accentClass], [accentBody]);
+
+ // Shift the accent over by the skew. Note we shift by twice the skew
+ // because we are centering the accent, so by adding 2*skew to the left,
+ // we shift it to the right by 1*skew.
+ accentBody.style.marginLeft = 2 * skew + "em";
+
+ accentBody = _buildCommon2.default.makeVList([{ type: "elem", elem: body }, { type: "kern", size: -clearance }, { type: "elem", elem: accentBody }], "firstBaseline", null, options);
+ } else {
+ accentBody = _stretchy2.default.svgSpan(group, options);
+
+ accentBody = _buildCommon2.default.makeVList([{ type: "elem", elem: body }, { type: "elem", elem: accentBody }], "firstBaseline", null, options);
+
+ var styleSpan = accentBody.children[0].children[0].children[1];
+ styleSpan.classes.push("svg-align"); // text-align: left;
+ if (skew > 0) {
+ // Shorten the accent and nudge it to the right.
+ styleSpan.style.width = "calc(100% - " + 2 * skew + "em)";
+ styleSpan.style.marginLeft = 2 * skew + "em";
+ }
+ }
+
+ var accentWrap = (0, _buildCommon.makeSpan)(["mord", "accent"], [accentBody], options);
+
+ if (supsubGroup) {
+ // Here, we replace the "base" child of the supsub with our newly
+ // generated accent.
+ supsubGroup.children[0] = accentWrap;
+
+ // Since we don't rerun the height calculation after replacing the
+ // accent, we manually recalculate height.
+ supsubGroup.height = Math.max(accentWrap.height, supsubGroup.height);
+
+ // Accents should always be ords, even when their innards are not.
+ supsubGroup.classes[0] = "mord";
+
+ return supsubGroup;
+ } else {
+ return accentWrap;
+ }
+};
+
+groupTypes.horizBrace = function (group, options) {
+ var style = options.style;
+
+ var hasSupSub = group.type === "supsub";
+ var supSubGroup = void 0;
+ var newOptions = void 0;
+ if (hasSupSub) {
+ // Ref: LaTeX source2e: }}}}\limits}
+ // i.e. LaTeX treats the brace similar to an op and passes it
+ // with \limits, so we need to assign supsub style.
+ if (group.value.sup) {
+ newOptions = options.havingStyle(style.sup());
+ supSubGroup = buildGroup(group.value.sup, newOptions, options);
+ } else {
+ newOptions = options.havingStyle(style.sub());
+ supSubGroup = buildGroup(group.value.sub, newOptions, options);
+ }
+ group = group.value.base;
+ }
+
+ // Build the base group
+ var body = buildGroup(group.value.base, options.havingBaseStyle(_Style2.default.DISPLAY));
+
+ // Create the stretchy element
+ var braceBody = _stretchy2.default.svgSpan(group, options);
+
+ // Generate the vlist, with the appropriate kerns ┏━━━━━━━━┓
+ // This first vlist contains the subject matter and the brace: equation
+ var vlist = void 0;
+ if (group.value.isOver) {
+ vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: body }, { type: "kern", size: 0.1 }, { type: "elem", elem: braceBody }], "firstBaseline", null, options);
+ vlist.children[0].children[0].children[1].classes.push("svg-align");
+ } else {
+ vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: braceBody }, { type: "kern", size: 0.1 }, { type: "elem", elem: body }], "bottom", body.depth + 0.1 + braceBody.height, options);
+ vlist.children[0].children[0].children[0].classes.push("svg-align");
+ }
+
+ if (hasSupSub) {
+ // In order to write the supsub, wrap the first vlist in another vlist:
+ // They can't all go in the same vlist, because the note might be wider
+ // than the equation. We want the equation to control the brace width.
+
+ // note long note long note
+ // ┏━━━━━━━━┓ or ┏━━━┓ not ┏━━━━━━━━━┓
+ // equation eqn eqn
+
+ var vSpan = (0, _buildCommon.makeSpan)(["mord", group.value.isOver ? "mover" : "munder"], [vlist], options);
+
+ if (group.value.isOver) {
+ vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: vSpan }, { type: "kern", size: 0.2 }, { type: "elem", elem: supSubGroup }], "firstBaseline", null, options);
+ } else {
+ vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: supSubGroup }, { type: "kern", size: 0.2 }, { type: "elem", elem: vSpan }], "bottom", vSpan.depth + 0.2 + supSubGroup.height, options);
+ }
+ }
+
+ return (0, _buildCommon.makeSpan)(["mord", group.value.isOver ? "mover" : "munder"], [vlist], options);
+};
+
+groupTypes.accentUnder = function (group, options) {
+ // Treat under accents much like underlines.
+ var innerGroup = buildGroup(group.value.body, options);
+
+ var accentBody = _stretchy2.default.svgSpan(group, options);
+ var kern = /tilde/.test(group.value.label) ? 0.12 : 0;
+
+ // Generate the vlist, with the appropriate kerns
+ var vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: accentBody }, { type: "kern", size: kern }, { type: "elem", elem: innerGroup }], "bottom", accentBody.height + kern, options);
+
+ vlist.children[0].children[0].children[0].classes.push("svg-align");
+
+ return (0, _buildCommon.makeSpan)(["mord", "accentunder"], [vlist], options);
+};
+
+groupTypes.enclose = function (group, options) {
+ // \cancel, \bcancel, \xcancel, \sout, \fbox
+ var inner = buildGroup(group.value.body, options);
+
+ var label = group.value.label.substr(1);
+ var scale = options.sizeMultiplier;
+ var img = void 0;
+ var pad = 0;
+ var imgShift = 0;
+
+ if (label === "sout") {
+ img = (0, _buildCommon.makeSpan)(["stretchy", "sout"]);
+ img.height = options.fontMetrics().defaultRuleThickness / scale;
+ imgShift = -0.5 * options.fontMetrics().xHeight;
+ } else {
+ // Add horizontal padding
+ inner.classes.push(label === "fbox" ? "boxpad" : "cancel-pad");
+
+ // Add vertical padding
+ var isCharBox = isCharacterBox(group.value.body);
+ // ref: LaTeX source2e: \fboxsep = 3pt; \fboxrule = .4pt
+ // ref: cancel package: \advance\totalheight2\p@ % "+2"
+ pad = label === "fbox" ? 0.34 : isCharBox ? 0.2 : 0;
+ imgShift = inner.depth + pad;
+
+ img = _stretchy2.default.encloseSpan(inner, label, pad, options);
+ }
+
+ var vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: inner, shift: 0 }, { type: "elem", elem: img, shift: imgShift }], "individualShift", null, options);
+
+ if (label !== "fbox") {
+ vlist.children[0].children[0].children[1].classes.push("svg-align");
+ }
+
+ if (/cancel/.test(label)) {
+ // cancel does not create horiz space for its line extension.
+ // That is, not when adjacent to a mord.
+ return (0, _buildCommon.makeSpan)(["mord", "cancel-lap"], [vlist], options);
+ } else {
+ return (0, _buildCommon.makeSpan)(["mord"], [vlist], options);
+ }
+};
+
+groupTypes.xArrow = function (group, options) {
+ var style = options.style;
+
+ // Build the argument groups in the appropriate style.
+ // Ref: amsmath.dtx: \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
+
+ var newOptions = options.havingStyle(style.sup());
+ var upperGroup = buildGroup(group.value.body, newOptions, options);
+ upperGroup.classes.push("x-arrow-pad");
+
+ var lowerGroup = void 0;
+ if (group.value.below) {
+ // Build the lower group
+ newOptions = options.havingStyle(style.sub());
+ lowerGroup = buildGroup(group.value.below, newOptions, options);
+ lowerGroup.classes.push("x-arrow-pad");
+ }
+
+ var arrowBody = _stretchy2.default.svgSpan(group, options);
+
+ var arrowShift = -options.fontMetrics().axisHeight + arrowBody.depth;
+ var upperShift = -options.fontMetrics().axisHeight - arrowBody.height - 0.111; // 2 mu. Ref: amsmath.dtx: #7\if0#2\else\mkern#2mu\fi
+
+ // Generate the vlist
+ var vlist = void 0;
+ if (group.value.below) {
+ var lowerShift = -options.fontMetrics().axisHeight + lowerGroup.height + arrowBody.height + 0.111;
+ vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: upperGroup, shift: upperShift }, { type: "elem", elem: arrowBody, shift: arrowShift }, { type: "elem", elem: lowerGroup, shift: lowerShift }], "individualShift", null, options);
+ } else {
+ vlist = _buildCommon2.default.makeVList([{ type: "elem", elem: upperGroup, shift: upperShift }, { type: "elem", elem: arrowBody, shift: arrowShift }], "individualShift", null, options);
+ }
+
+ vlist.children[0].children[0].children[1].classes.push("svg-align");
+
+ return (0, _buildCommon.makeSpan)(["mrel", "x-arrow"], [vlist], options);
+};
+
+groupTypes.phantom = function (group, options) {
+ var elements = buildExpression(group.value.value, options.withPhantom(), false);
+
+ // \phantom isn't supposed to affect the elements it contains.
+ // See "color" for more details.
+ return new _buildCommon2.default.makeFragment(elements);
+};
+
+groupTypes.mclass = function (group, options) {
+ var elements = buildExpression(group.value.value, options, true);
+
+ return (0, _buildCommon.makeSpan)([group.value.mclass], elements, options);
+};
+
+/**
+ * buildGroup is the function that takes a group and calls the correct groupType
+ * function for it. It also handles the interaction of size and style changes
+ * between parents and children.
+ */
+var buildGroup = function buildGroup(group, options, baseOptions) {
+ if (!group) {
+ return (0, _buildCommon.makeSpan)();
+ }
+
+ if (groupTypes[group.type]) {
+ // Call the groupTypes function
+ var groupNode = groupTypes[group.type](group, options);
+
+ // If the size changed between the parent and the current group, account
+ // for that size difference.
+ if (baseOptions && options.size !== baseOptions.size) {
+ groupNode = (0, _buildCommon.makeSpan)(options.sizingClasses(baseOptions), [groupNode], options);
+
+ var multiplier = options.sizeMultiplier / baseOptions.sizeMultiplier;
+
+ groupNode.height *= multiplier;
+ groupNode.depth *= multiplier;
+ }
+
+ return groupNode;
+ } else {
+ throw new _ParseError2.default("Got group of unknown type: '" + group.type + "'");
+ }
+};
+
+/**
+ * Take an entire parse tree, and build it into an appropriate set of HTML
+ * nodes.
+ */
+var buildHTML = function buildHTML(tree, options) {
+ // buildExpression is destructive, so we need to make a clone
+ // of the incoming tree so that it isn't accidentally changed
+ tree = JSON.parse((0, _stringify2.default)(tree));
+
+ // Build the expression contained in the tree
+ var expression = buildExpression(tree, options, true);
+ var body = (0, _buildCommon.makeSpan)(["base"], expression, options);
+
+ // Add struts, which ensure that the top of the HTML element falls at the
+ // height of the expression, and the bottom of the HTML element falls at the
+ // depth of the expression.
+ var topStrut = (0, _buildCommon.makeSpan)(["strut"]);
+ var bottomStrut = (0, _buildCommon.makeSpan)(["strut", "bottom"]);
+
+ topStrut.style.height = body.height + "em";
+ bottomStrut.style.height = body.height + body.depth + "em";
+ // We'd like to use `vertical-align: top` but in IE 9 this lowers the
+ // baseline of the box to the bottom of this strut (instead staying in the
+ // normal place) so we use an absolute value for vertical-align instead
+ bottomStrut.style.verticalAlign = -body.depth + "em";
+
+ // Wrap the struts and body together
+ var htmlNode = (0, _buildCommon.makeSpan)(["katex-html"], [topStrut, bottomStrut, body]);
+
+ htmlNode.setAttribute("aria-hidden", "true");
+
+ return htmlNode;
+};
+
+module.exports = buildHTML;
+
+},{"./ParseError":29,"./Style":33,"./buildCommon":34,"./delimiter":38,"./domTree":39,"./stretchy":47,"./units":50,"./utils":51,"babel-runtime/core-js/json/stringify":2}],36:[function(require,module,exports){
+"use strict";
+
+var _buildCommon = require("./buildCommon");
+
+var _buildCommon2 = _interopRequireDefault(_buildCommon);
+
+var _fontMetrics = require("./fontMetrics");
+
+var _fontMetrics2 = _interopRequireDefault(_fontMetrics);
+
+var _mathMLTree = require("./mathMLTree");
+
+var _mathMLTree2 = _interopRequireDefault(_mathMLTree);
+
+var _ParseError = require("./ParseError");
+
+var _ParseError2 = _interopRequireDefault(_ParseError);
+
+var _Style = require("./Style");
+
+var _Style2 = _interopRequireDefault(_Style);
+
+var _symbols = require("./symbols");
+
+var _symbols2 = _interopRequireDefault(_symbols);
+
+var _utils = require("./utils");
+
+var _utils2 = _interopRequireDefault(_utils);
+
+var _stretchy = require("./stretchy");
+
+var _stretchy2 = _interopRequireDefault(_stretchy);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+/**
+ * Takes a symbol and converts it into a MathML text node after performing
+ * optional replacement from symbols.js.
+ */
+/**
+ * This file converts a parse tree into a cooresponding MathML tree. The main
+ * entry point is the `buildMathML` function, which takes a parse tree from the
+ * parser.
+ */
+
+var makeText = function makeText(text, mode) {
+ if (_symbols2.default[mode][text] && _symbols2.default[mode][text].replace) {
+ text = _symbols2.default[mode][text].replace;
+ }
+
+ return new _mathMLTree2.default.TextNode(text);
+};
+
+/**
+ * Returns the math variant as a string or null if none is required.
+ */
+var getVariant = function getVariant(group, options) {
+ var font = options.font;
+ if (!font) {
+ return null;
+ }
+
+ var mode = group.mode;
+ if (font === "mathit") {
+ return "italic";
+ }
+
+ var value = group.value;
+ if (_utils2.default.contains(["\\imath", "\\jmath"], value)) {
+ return null;
+ }
+
+ if (_symbols2.default[mode][value] && _symbols2.default[mode][value].replace) {
+ value = _symbols2.default[mode][value].replace;
+ }
+
+ var fontName = _buildCommon.fontMap[font].fontName;
+ if (_fontMetrics2.default.getCharacterMetrics(value, fontName)) {
+ return _buildCommon.fontMap[options.font].variant;
+ }
+
+ return null;
+};
+
+/**
+ * Functions for handling the different types of groups found in the parse
+ * tree. Each function should take a parse group and return a MathML node.
+ */
+var groupTypes = {};
+
+var defaultVariant = {
+ "mi": "italic",
+ "mn": "normal",
+ "mtext": "normal"
+};
+
+groupTypes.mathord = function (group, options) {
+ var node = new _mathMLTree2.default.MathNode("mi", [makeText(group.value, group.mode)]);
+
+ var variant = getVariant(group, options) || "italic";
+ if (variant !== defaultVariant[node.type]) {
+ node.setAttribute("mathvariant", variant);
+ }
+ return node;
+};
+
+groupTypes.textord = function (group, options) {
+ var text = makeText(group.value, group.mode);
+
+ var variant = getVariant(group, options) || "normal";
+
+ var node = void 0;
+ if (group.mode === 'text') {
+ node = new _mathMLTree2.default.MathNode("mtext", [text]);
+ } else if (/[0-9]/.test(group.value)) {
+ // TODO(kevinb) merge adjacent nodes
+ // do it as a post processing step
+ node = new _mathMLTree2.default.MathNode("mn", [text]);
+ } else if (group.value === "\\prime") {
+ node = new _mathMLTree2.default.MathNode("mo", [text]);
+ } else {
+ node = new _mathMLTree2.default.MathNode("mi", [text]);
+ }
+ if (variant !== defaultVariant[node.type]) {
+ node.setAttribute("mathvariant", variant);
+ }
+
+ return node;
+};
+
+groupTypes.bin = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value, group.mode)]);
+
+ return node;
+};
+
+groupTypes.rel = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value, group.mode)]);
+
+ return node;
+};
+
+groupTypes.open = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value, group.mode)]);
+
+ return node;
+};
+
+groupTypes.close = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value, group.mode)]);
+
+ return node;
+};
+
+groupTypes.inner = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value, group.mode)]);
+
+ return node;
+};
+
+groupTypes.punct = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value, group.mode)]);
+
+ node.setAttribute("separator", "true");
+
+ return node;
+};
+
+groupTypes.ordgroup = function (group, options) {
+ var inner = buildExpression(group.value, options);
+
+ var node = new _mathMLTree2.default.MathNode("mrow", inner);
+
+ return node;
+};
+
+groupTypes.text = function (group, options) {
+ var body = group.value.body;
+
+ // Convert each element of the body into MathML, and combine consecutive
+ // outputs into a single tag. In this way, we don't
+ // nest non-text items (e.g., $nested-math$) within an .
+ var inner = [];
+ var currentText = null;
+ for (var i = 0; i < body.length; i++) {
+ var _group = buildGroup(body[i], options);
+ if (_group.type === 'mtext' && currentText != null) {
+ Array.prototype.push.apply(currentText.children, _group.children);
+ } else {
+ inner.push(_group);
+ if (_group.type === 'mtext') {
+ currentText = _group;
+ }
+ }
+ }
+
+ // If there is a single tag in the end (presumably ),
+ // just return it. Otherwise, wrap them in an .
+ if (inner.length === 1) {
+ return inner[0];
+ } else {
+ return new _mathMLTree2.default.MathNode("mrow", inner);
+ }
+};
+
+groupTypes.color = function (group, options) {
+ var inner = buildExpression(group.value.value, options);
+
+ var node = new _mathMLTree2.default.MathNode("mstyle", inner);
+
+ node.setAttribute("mathcolor", group.value.color);
+
+ return node;
+};
+
+groupTypes.supsub = function (group, options) {
+ // Is the inner group a relevant horizonal brace?
+ var isBrace = false;
+ var isOver = void 0;
+ var isSup = void 0;
+ if (group.value.base) {
+ if (group.value.base.value.type === "horizBrace") {
+ isSup = group.value.sup ? true : false;
+ if (isSup === group.value.base.value.isOver) {
+ isBrace = true;
+ isOver = group.value.base.value.isOver;
+ }
+ }
+ }
+
+ var removeUnnecessaryRow = true;
+ var children = [buildGroup(group.value.base, options, removeUnnecessaryRow)];
+
+ if (group.value.sub) {
+ children.push(buildGroup(group.value.sub, options, removeUnnecessaryRow));
+ }
+
+ if (group.value.sup) {
+ children.push(buildGroup(group.value.sup, options, removeUnnecessaryRow));
+ }
+
+ var nodeType = void 0;
+ if (isBrace) {
+ nodeType = isOver ? "mover" : "munder";
+ } else if (!group.value.sub) {
+ nodeType = "msup";
+ } else if (!group.value.sup) {
+ nodeType = "msub";
+ } else {
+ var base = group.value.base;
+ if (base && base.value.limits && options.style === _Style2.default.DISPLAY) {
+ nodeType = "munderover";
+ } else {
+ nodeType = "msubsup";
+ }
+ }
+
+ var node = new _mathMLTree2.default.MathNode(nodeType, children);
+
+ return node;
+};
+
+groupTypes.genfrac = function (group, options) {
+ var node = new _mathMLTree2.default.MathNode("mfrac", [buildGroup(group.value.numer, options), buildGroup(group.value.denom, options)]);
+
+ if (!group.value.hasBarLine) {
+ node.setAttribute("linethickness", "0px");
+ }
+
+ if (group.value.leftDelim != null || group.value.rightDelim != null) {
+ var withDelims = [];
+
+ if (group.value.leftDelim != null) {
+ var leftOp = new _mathMLTree2.default.MathNode("mo", [new _mathMLTree2.default.TextNode(group.value.leftDelim)]);
+
+ leftOp.setAttribute("fence", "true");
+
+ withDelims.push(leftOp);
+ }
+
+ withDelims.push(node);
+
+ if (group.value.rightDelim != null) {
+ var rightOp = new _mathMLTree2.default.MathNode("mo", [new _mathMLTree2.default.TextNode(group.value.rightDelim)]);
+
+ rightOp.setAttribute("fence", "true");
+
+ withDelims.push(rightOp);
+ }
+
+ var outerNode = new _mathMLTree2.default.MathNode("mrow", withDelims);
+
+ return outerNode;
+ }
+
+ return node;
+};
+
+groupTypes.array = function (group, options) {
+ return new _mathMLTree2.default.MathNode("mtable", group.value.body.map(function (row) {
+ return new _mathMLTree2.default.MathNode("mtr", row.map(function (cell) {
+ return new _mathMLTree2.default.MathNode("mtd", [buildGroup(cell, options)]);
+ }));
+ }));
+};
+
+groupTypes.sqrt = function (group, options) {
+ var node = void 0;
+ if (group.value.index) {
+ node = new _mathMLTree2.default.MathNode("mroot", [buildGroup(group.value.body, options), buildGroup(group.value.index, options)]);
+ } else {
+ node = new _mathMLTree2.default.MathNode("msqrt", [buildGroup(group.value.body, options)]);
+ }
+
+ return node;
+};
+
+groupTypes.leftright = function (group, options) {
+ var inner = buildExpression(group.value.body, options);
+
+ if (group.value.left !== ".") {
+ var leftNode = new _mathMLTree2.default.MathNode("mo", [makeText(group.value.left, group.mode)]);
+
+ leftNode.setAttribute("fence", "true");
+
+ inner.unshift(leftNode);
+ }
+
+ if (group.value.right !== ".") {
+ var rightNode = new _mathMLTree2.default.MathNode("mo", [makeText(group.value.right, group.mode)]);
+
+ rightNode.setAttribute("fence", "true");
+
+ inner.push(rightNode);
+ }
+
+ var outerNode = new _mathMLTree2.default.MathNode("mrow", inner);
+
+ return outerNode;
+};
+
+groupTypes.middle = function (group, options) {
+ var middleNode = new _mathMLTree2.default.MathNode("mo", [makeText(group.value.middle, group.mode)]);
+ middleNode.setAttribute("fence", "true");
+ return middleNode;
+};
+
+groupTypes.accent = function (group, options) {
+ var accentNode = void 0;
+ if (group.value.isStretchy) {
+ accentNode = _stretchy2.default.mathMLnode(group.value.label);
+ } else {
+ accentNode = new _mathMLTree2.default.MathNode("mo", [makeText(group.value.label, group.mode)]);
+ }
+
+ var node = new _mathMLTree2.default.MathNode("mover", [buildGroup(group.value.base, options), accentNode]);
+
+ node.setAttribute("accent", "true");
+
+ return node;
+};
+
+groupTypes.spacing = function (group) {
+ var node = void 0;
+
+ if (group.value === "\\ " || group.value === "\\space" || group.value === " " || group.value === "~") {
+ node = new _mathMLTree2.default.MathNode("mtext", [new _mathMLTree2.default.TextNode("\xA0")]);
+ } else {
+ node = new _mathMLTree2.default.MathNode("mspace");
+
+ node.setAttribute("width", _buildCommon2.default.spacingFunctions[group.value].size);
+ }
+
+ return node;
+};
+
+groupTypes.op = function (group, options) {
+ var node = void 0;
+
+ // TODO(emily): handle big operators using the `largeop` attribute
+
+ if (group.value.symbol) {
+ // This is a symbol. Just add the symbol.
+ node = new _mathMLTree2.default.MathNode("mo", [makeText(group.value.body, group.mode)]);
+ } else if (group.value.value) {
+ // This is an operator with children. Add them.
+ node = new _mathMLTree2.default.MathNode("mo", buildExpression(group.value.value, options));
+ } else {
+ // This is a text operator. Add all of the characters from the
+ // operator's name.
+ // TODO(emily): Add a space in the middle of some of these
+ // operators, like \limsup.
+ node = new _mathMLTree2.default.MathNode("mi", [new _mathMLTree2.default.TextNode(group.value.body.slice(1))]);
+ }
+
+ return node;
+};
+
+groupTypes.mod = function (group, options) {
+ var inner = [];
+
+ if (group.value.modType === "pod" || group.value.modType === "pmod") {
+ inner.push(new _mathMLTree2.default.MathNode("mo", [makeText("(", group.mode)]));
+ }
+ if (group.value.modType !== "pod") {
+ inner.push(new _mathMLTree2.default.MathNode("mo", [makeText("mod", group.mode)]));
+ }
+ if (group.value.value) {
+ var space = new _mathMLTree2.default.MathNode("mspace");
+ space.setAttribute("width", "0.333333em");
+ inner.push(space);
+ inner = inner.concat(buildExpression(group.value.value, options));
+ }
+ if (group.value.modType === "pod" || group.value.modType === "pmod") {
+ inner.push(new _mathMLTree2.default.MathNode("mo", [makeText(")", group.mode)]));
+ }
+
+ return new _mathMLTree2.default.MathNode("mo", inner);
+};
+
+groupTypes.katex = function (group) {
+ var node = new _mathMLTree2.default.MathNode("mtext", [new _mathMLTree2.default.TextNode("KaTeX")]);
+
+ return node;
+};
+
+groupTypes.font = function (group, options) {
+ var font = group.value.font;
+ return buildGroup(group.value.body, options.withFont(font));
+};
+
+groupTypes.delimsizing = function (group) {
+ var children = [];
+
+ if (group.value.value !== ".") {
+ children.push(makeText(group.value.value, group.mode));
+ }
+
+ var node = new _mathMLTree2.default.MathNode("mo", children);
+
+ if (group.value.mclass === "mopen" || group.value.mclass === "mclose") {
+ // Only some of the delimsizing functions act as fences, and they
+ // return "mopen" or "mclose" mclass.
+ node.setAttribute("fence", "true");
+ } else {
+ // Explicitly disable fencing if it's not a fence, to override the
+ // defaults.
+ node.setAttribute("fence", "false");
+ }
+
+ return node;
+};
+
+groupTypes.styling = function (group, options) {
+ // Figure out what style we're changing to.
+ // TODO(kevinb): dedupe this with buildHTML.js
+ // This will be easier of handling of styling nodes is in the same file.
+ var styleMap = {
+ "display": _Style2.default.DISPLAY,
+ "text": _Style2.default.TEXT,
+ "script": _Style2.default.SCRIPT,
+ "scriptscript": _Style2.default.SCRIPTSCRIPT
+ };
+
+ var newStyle = styleMap[group.value.style];
+ var newOptions = options.havingStyle(newStyle);
+
+ var inner = buildExpression(group.value.value, newOptions);
+
+ var node = new _mathMLTree2.default.MathNode("mstyle", inner);
+
+ var styleAttributes = {
+ "display": ["0", "true"],
+ "text": ["0", "false"],
+ "script": ["1", "false"],
+ "scriptscript": ["2", "false"]
+ };
+
+ var attr = styleAttributes[group.value.style];
+
+ node.setAttribute("scriptlevel", attr[0]);
+ node.setAttribute("displaystyle", attr[1]);
+
+ return node;
+};
+
+groupTypes.sizing = function (group, options) {
+ var newOptions = options.havingSize(group.value.size);
+ var inner = buildExpression(group.value.value, newOptions);
+
+ var node = new _mathMLTree2.default.MathNode("mstyle", inner);
+
+ // TODO(emily): This doesn't produce the correct size for nested size
+ // changes, because we don't keep state of what style we're currently
+ // in, so we can't reset the size to normal before changing it. Now
+ // that we're passing an options parameter we should be able to fix
+ // this.
+ node.setAttribute("mathsize", newOptions.sizeMultiplier + "em");
+
+ return node;
+};
+
+groupTypes.overline = function (group, options) {
+ var operator = new _mathMLTree2.default.MathNode("mo", [new _mathMLTree2.default.TextNode("\u203E")]);
+ operator.setAttribute("stretchy", "true");
+
+ var node = new _mathMLTree2.default.MathNode("mover", [buildGroup(group.value.body, options), operator]);
+ node.setAttribute("accent", "true");
+
+ return node;
+};
+
+groupTypes.underline = function (group, options) {
+ var operator = new _mathMLTree2.default.MathNode("mo", [new _mathMLTree2.default.TextNode("\u203E")]);
+ operator.setAttribute("stretchy", "true");
+
+ var node = new _mathMLTree2.default.MathNode("munder", [buildGroup(group.value.body, options), operator]);
+ node.setAttribute("accentunder", "true");
+
+ return node;
+};
+
+groupTypes.accentUnder = function (group, options) {
+ var accentNode = _stretchy2.default.mathMLnode(group.value.label);
+ var node = new _mathMLTree2.default.MathNode("munder", [buildGroup(group.value.body, options), accentNode]);
+ node.setAttribute("accentunder", "true");
+ return node;
+};
+
+groupTypes.enclose = function (group, options) {
+ var node = new _mathMLTree2.default.MathNode("menclose", [buildGroup(group.value.body, options)]);
+ var notation = "";
+ switch (group.value.label) {
+ case "\\bcancel":
+ notation = "downdiagonalstrike";
+ break;
+ case "\\sout":
+ notation = "horizontalstrike";
+ break;
+ case "\\fbox":
+ notation = "box";
+ break;
+ default:
+ notation = "updiagonalstrike";
+ }
+ node.setAttribute("notation", notation);
+ return node;
+};
+
+groupTypes.horizBrace = function (group, options) {
+ var accentNode = _stretchy2.default.mathMLnode(group.value.label);
+ return new _mathMLTree2.default.MathNode(group.value.isOver ? "mover" : "munder", [buildGroup(group.value.base, options), accentNode]);
+};
+
+groupTypes.xArrow = function (group, options) {
+ var arrowNode = _stretchy2.default.mathMLnode(group.value.label);
+ var node = void 0;
+ var lowerNode = void 0;
+
+ if (group.value.body) {
+ var upperNode = buildGroup(group.value.body, options);
+ if (group.value.below) {
+ lowerNode = buildGroup(group.value.below, options);
+ node = new _mathMLTree2.default.MathNode("munderover", [arrowNode, lowerNode, upperNode]);
+ } else {
+ node = new _mathMLTree2.default.MathNode("mover", [arrowNode, upperNode]);
+ }
+ } else if (group.value.below) {
+ lowerNode = buildGroup(group.value.below, options);
+ node = new _mathMLTree2.default.MathNode("munder", [arrowNode, lowerNode]);
+ } else {
+ node = new _mathMLTree2.default.MathNode("mover", [arrowNode]);
+ }
+ return node;
+};
+
+groupTypes.rule = function (group) {
+ // TODO(emily): Figure out if there's an actual way to draw black boxes
+ // in MathML.
+ var node = new _mathMLTree2.default.MathNode("mrow");
+
+ return node;
+};
+
+groupTypes.kern = function (group) {
+ // TODO(kevin): Figure out if there's a way to add space in MathML
+ var node = new _mathMLTree2.default.MathNode("mrow");
+
+ return node;
+};
+
+groupTypes.llap = function (group, options) {
+ var node = new _mathMLTree2.default.MathNode("mpadded", [buildGroup(group.value.body, options)]);
+
+ node.setAttribute("lspace", "-1width");
+ node.setAttribute("width", "0px");
+
+ return node;
+};
+
+groupTypes.rlap = function (group, options) {
+ var node = new _mathMLTree2.default.MathNode("mpadded", [buildGroup(group.value.body, options)]);
+
+ node.setAttribute("width", "0px");
+
+ return node;
+};
+
+groupTypes.phantom = function (group, options) {
+ var inner = buildExpression(group.value.value, options);
+ return new _mathMLTree2.default.MathNode("mphantom", inner);
+};
+
+groupTypes.mclass = function (group, options) {
+ var inner = buildExpression(group.value.value, options);
+ return new _mathMLTree2.default.MathNode("mstyle", inner);
+};
+
+/**
+ * Takes a list of nodes, builds them, and returns a list of the generated
+ * MathML nodes. A little simpler than the HTML version because we don't do any
+ * previous-node handling.
+ */
+var buildExpression = function buildExpression(expression, options) {
+ var groups = [];
+ for (var i = 0; i < expression.length; i++) {
+ var group = expression[i];
+ groups.push(buildGroup(group, options));
+ }
+
+ // TODO(kevinb): combine \\not with mrels and mords
+
+ return groups;
+};
+
+/**
+ * Takes a group from the parser and calls the appropriate groupTypes function
+ * on it to produce a MathML node.
+ */
+// TODO(kevinb): determine if removeUnnecessaryRow should always be true
+var buildGroup = function buildGroup(group, options) {
+ var removeUnnecessaryRow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
+
+ if (!group) {
+ return new _mathMLTree2.default.MathNode("mrow");
+ }
+
+ if (groupTypes[group.type]) {
+ // Call the groupTypes function
+ var result = groupTypes[group.type](group, options);
+ if (removeUnnecessaryRow) {
+ if (result.type === "mrow" && result.children.length === 1) {
+ return result.children[0];
+ }
+ }
+ return result;
+ } else {
+ throw new _ParseError2.default("Got group of unknown type: '" + group.type + "'");
+ }
+};
+
+/**
+ * Takes a full parse tree and settings and builds a MathML representation of
+ * it. In particular, we put the elements from building the parse tree into a
+ * tag so we can also include that TeX source as an annotation.
+ *
+ * Note that we actually return a domTree element with a `