tex2typst 0.3.27-beta.1 → 0.3.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +23 -24
- package/dist/index.js +338 -314
- package/dist/parser.js +23 -0
- package/dist/tex2typst.min.js +12 -12
- package/package.json +1 -1
- package/src/convert.ts +53 -2
- package/src/exposed-types.ts +23 -24
- package/src/index.ts +7 -3
- package/src/jslex.ts +1 -1
- package/src/tex-tokenizer.ts +1 -0
- package/src/tex2typst.ts +2 -4
- package/src/typst-parser.ts +9 -10
- package/src/typst-types.ts +484 -230
- package/src/typst-writer.ts +28 -274
- package/tests/cheat-sheet.test.ts +42 -0
- package/tests/cheat-sheet.toml +304 -0
- package/tests/example.ts +15 -0
- package/tests/general-symbols.test.ts +22 -0
- package/tests/general-symbols.toml +755 -0
- package/tests/integration-tex2typst.yaml +89 -0
- package/tests/struct-bidirection.yaml +179 -0
- package/tests/struct-tex2typst.yaml +443 -0
- package/tests/struct-typst2tex.yaml +412 -0
- package/tests/symbol.yml +123 -0
- package/tests/test-common.ts +26 -0
- package/tests/tex-parser.test.ts +57 -0
- package/tests/tex-to-typst.test.ts +143 -0
- package/tests/typst-parser.test.ts +134 -0
- package/tests/typst-to-tex.test.ts +76 -0
- package/tsconfig.json +4 -4
package/dist/parser.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";class M{constructor(o,n,t=[]){this.type=o,this.value=n,this.args=t}}function U(l,o){Object.defineProperty(this,"name",{enumerable:!1,writable:!1,value:"JisonParserError"}),l==null&&(l="???"),Object.defineProperty(this,"message",{enumerable:!1,writable:!0,value:l}),this.hash=o;var n;if(o&&o.exception instanceof Error){var t=o.exception;this.message=t.message||l,n=t.stack}n||(Error.hasOwnProperty("captureStackTrace")?Error.captureStackTrace(this,this.constructor):n=new Error(l).stack),n&&Object.defineProperty(this,"stack",{enumerable:!1,writable:!1,value:n})}typeof Object.setPrototypeOf=="function"?Object.setPrototypeOf(U.prototype,Error.prototype):U.prototype=Object.create(Error.prototype),U.prototype.constructor=U,U.prototype.name="JisonParserError";function V(l){for(var o=[],n=l.pop,t=l.rule,i=0,r=n.length;i<r;i++)o.push([n[i],t[i]]);return o}function z(l){for(var o=[],n=l.len,t=l.symbol,i=l.type,r=l.state,s=l.mode,e=l.goto,h=0,_=n.length;h<_;h++){for(var v=n[h],u={},d=0;d<v;d++){var a=t.shift();switch(i.shift()){case 2:u[a]=[s.shift(),e.shift()];break;case 0:u[a]=r.shift();break;default:u[a]=[3]}}o.push(u)}return o}function g(l,o,n){n=n||0;for(var t=0;t<o;t++)this.push(l),l+=n}function T(l,o){for(l=this.length-l,o+=l;l<o;l++)this.push(this[l])}function N(l){for(var o=[],n=0,t=l.length;n<t;n++){var i=l[n];typeof i=="function"?(n++,i.apply(o,l[n])):o.push(i)}return o}var I={trace:function(){},JisonParserError:U,yy:{},options:{type:"lalr",hasPartialLrUpgradeOnConflict:!0,errorRecoveryTokenDiscardCount:3},symbols_:{$accept:0,$end:1,"*":5,"+":3,"-":4,"/":6,EOF:1,IDENTIFIER:7,NUMBER:8,error:2,expression:10,typinput:9},terminals_:{1:"EOF",2:"error",3:"+",4:"-",5:"*",6:"/",7:"IDENTIFIER",8:"NUMBER"},TERROR:2,EOF:1,originalQuoteName:null,originalParseError:null,cleanupAfterParse:null,constructParseErrorInfo:null,yyMergeLocationInfo:null,__reentrant_call_depth:0,__error_infos:[],__error_recovery_infos:[],quoteName:function(o){return'"'+o+'"'},getSymbolName:function(o){if(this.terminals_[o])return this.terminals_[o];var n=this.symbols_;for(var t in n)if(n[t]===o)return t;return null},describeSymbol:function(o){if(o!==this.EOF&&this.terminal_descriptions_&&this.terminal_descriptions_[o])return this.terminal_descriptions_[o];if(o===this.EOF)return"end of input";var n=this.getSymbolName(o);return n?this.quoteName(n):null},collect_expected_token_set:function(o,n){var t=this.TERROR,i=[],r={};if(!n&&this.state_descriptions_&&this.state_descriptions_[o])return[this.state_descriptions_[o]];for(var s in this.table[o])if(s=+s,s!==t){var e=n?s:this.describeSymbol(s);e&&!r[e]&&(i.push(e),r[e]=!0)}return i},productions_:V({pop:N([9,g,[10,6]]),rule:N([2,1,1,g,[3,4]])}),performAction:function(o,n,t){var i=this.yy,r=i.parser,s=i.lexer;switch(o){case 0:this.$=t[n-1];break;case 1:return this.$=t[n-1],t[n-1];break;case 2:this.$=new M("IDENTIFIER",t[n]);break;case 3:this.$=new M("NUMBER",t[n]);break;case 4:this.$=new M("ADD",t[n-1],[t[n-2],t[n]]);break;case 5:this.$=new M("SUB",t[n-1],[t[n-2],t[n]]);break;case 6:this.$=new M("MUL",t[n-1],[t[n-2],t[n]]);break;case 7:this.$=new M("DIV",t[n-1],[t[n-2],t[n]]);break}},table:z({len:N([4,1,5,g,[0,3],g,[3,4],5,T,[9,3]]),symbol:N([g,[7,4,1],1,1,g,[3,6,1],10,T,[3,9],T,[17,5],T,[5,5]]),type:N([2,2,0,0,1,g,[2,7],0,T,[3,11],g,[2,8]]),state:N([1,2,g,[10,4,1]]),mode:N([g,[1,15],g,[2,3],T,[5,7]]),goto:N([g,[3,7,1],3,4,3,4,T,[4,4],g,[4,3],8,9,g,[5,3],8,9])}),defaultActions:{3:2,4:3,5:1,12:6,13:7},parseError:function(o,n,t){if(n.recoverable)typeof this.trace=="function"&&this.trace(o),n.destroy();else throw typeof this.trace=="function"&&this.trace(o),t||(t=this.JisonParserError),new t(o,n)},parse:function(o){var n=this,t=new Array(128),i=new Array(128),r=new Array(128),s=this.table,e=0,h=0,_=this.TERROR,v=this.EOF,u=this.options.errorRecoveryTokenDiscardCount|0||3,d=[0,14],a;this.__lexer__?a=this.__lexer__:a=this.__lexer__=Object.create(this.lexer);var f={parseError:void 0,quoteName:void 0,lexer:void 0,parser:void 0,pre_parse:void 0,post_parse:void 0,pre_lex:void 0,post_lex:void 0},x;typeof assert!="function"?x=function(y,R){if(!y)throw new Error("assertion failed: "+(R||"***"))}:x=assert,this.yyGetSharedState=function(){return f};function j(c,y){for(var R in y)typeof c[R]>"u"&&Object.prototype.hasOwnProperty.call(y,R)&&(c[R]=y[R])}j(f,this.yy),f.lexer=a,f.parser=this,typeof f.parseError=="function"?this.parseError=function(y,R,w){return w||(w=this.JisonParserError),f.parseError.call(this,y,R,w)}:this.parseError=this.originalParseError,typeof f.quoteName=="function"?this.quoteName=function(y){return f.quoteName.call(this,y)}:this.quoteName=this.originalQuoteName,this.cleanupAfterParse=function(y,R,w){var A;if(R){var S;(f.post_parse||this.post_parse)&&(S=this.constructParseErrorInfo(null,null,null,!1)),f.post_parse&&(A=f.post_parse.call(this,f,y,S),typeof A<"u"&&(y=A)),this.post_parse&&(A=this.post_parse.call(this,f,y,S),typeof A<"u"&&(y=A)),S&&S.destroy&&S.destroy()}if(this.__reentrant_call_depth>1)return y;if(a.cleanupAfterLex&&a.cleanupAfterLex(w),f&&(f.lexer=void 0,f.parser=void 0,a.yy===f&&(a.yy=void 0)),f=void 0,this.parseError=this.originalParseError,this.quoteName=this.originalQuoteName,t.length=0,i.length=0,r.length=0,e=0,!w){for(var Y=this.__error_infos.length-1;Y>=0;Y--){var C=this.__error_infos[Y];C&&typeof C.destroy=="function"&&C.destroy()}this.__error_infos.length=0}return y},this.constructParseErrorInfo=function(y,R,w,A){var S={errStr:y,exception:R,text:a.match,value:a.yytext,token:this.describeSymbol(h)||h,token_id:h,line:a.yylineno,expected:w,recoverable:A,state:E,action:P,new_state:k,symbol_stack:t,state_stack:i,value_stack:r,stack_pointer:e,yy:f,lexer:a,parser:this,destroy:function(){var C=!!this.recoverable;for(var X in this)this.hasOwnProperty(X)&&typeof X=="object"&&(this[X]=void 0);this.recoverable=C}};return this.__error_infos.push(S),S};function q(c){var y=n.getSymbolName(c);return y||(y=c),y}function B(){var c=a.lex();return typeof c!="number"&&(c=n.symbols_[c]||c),c||v}function $(){var c=a.fastLex();return typeof c!="number"&&(c=n.symbols_[c]||c),c||v}var Q=B,E,P,p,F,L={$:!0,_$:void 0,yy:f},m,D,O,k,b=!1;try{if(this.__reentrant_call_depth++,a.setInput(o,f),typeof a.canIUse=="function"){var Z=a.canIUse();Z.fastLex&&typeof $=="function"&&(Q=$)}for(r[e]=null,i[e]=0,t[e]=0,++e,this.pre_parse&&this.pre_parse.call(this,f),f.pre_parse&&f.pre_parse.call(this,f),k=i[e-1];;){if(E=k,this.defaultActions[E])P=2,k=this.defaultActions[E];else if(h||(h=Q()),F=s[E]&&s[E][h]||d,k=F[1],P=F[0],!P){var J,W=this.describeSymbol(h)||h,G=this.collect_expected_token_set(E);typeof a.yylineno=="number"?J="Parse error on line "+(a.yylineno+1)+": ":J="Parse error: ",typeof a.showPosition=="function"&&(J+=`
|
|
2
|
+
`+a.showPosition(69,10)+`
|
|
3
|
+
`),G.length?J+="Expecting "+G.join(", ")+", got unexpected "+W:J+="Unexpected "+W,m=this.constructParseErrorInfo(J,null,G,!1),p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p);break}switch(P){default:if(P instanceof Array){m=this.constructParseErrorInfo("Parse Error: multiple actions possible at state: "+E+", token: "+h,null,null,!1),p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p);break}m=this.constructParseErrorInfo("Parsing halted. No viable error recovery approach available due to internal system failure.",null,null,!1),p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p);break;case 1:t[e]=h,r[e]=a.yytext,i[e]=k,++e,h=0;continue;case 2:if(O=this.productions_[k-1],D=O[1],p=this.performAction.call(L,k,e-1,r),typeof p<"u"){b=p;break}e-=D;var H=O[0];t[e]=H,r[e]=L.$,k=s[i[e-1]][H],i[e]=k,++e;continue;case 3:e!==-2&&(b=!0,e--,typeof r[e]<"u"&&(b=r[e]));break}break}}catch(c){if(c instanceof this.JisonParserError)throw c;if(a&&typeof a.JisonLexerError=="function"&&c instanceof a.JisonLexerError)throw c;m=this.constructParseErrorInfo("Parsing aborted due to exception.",c,null,!1),b=!1,p=this.parseError(m.errStr,m,this.JisonParserError),typeof p<"u"&&(b=p)}finally{b=this.cleanupAfterParse(b,!0,!0),this.__reentrant_call_depth--}return b}};I.originalParseError=I.parseError,I.originalQuoteName=I.quoteName;var tt=function(){function l(n,t){Object.defineProperty(this,"name",{enumerable:!1,writable:!1,value:"JisonLexerError"}),n==null&&(n="???"),Object.defineProperty(this,"message",{enumerable:!1,writable:!0,value:n}),this.hash=t;var i;if(t&&t.exception instanceof Error){var r=t.exception;this.message=r.message||n,i=r.stack}i||(Error.hasOwnProperty("captureStackTrace")?Error.captureStackTrace(this,this.constructor):i=new Error(n).stack),i&&Object.defineProperty(this,"stack",{enumerable:!1,writable:!1,value:i})}typeof Object.setPrototypeOf=="function"?Object.setPrototypeOf(l.prototype,Error.prototype):l.prototype=Object.create(Error.prototype),l.prototype.constructor=l,l.prototype.name="JisonLexerError";var o={EOF:1,ERROR:2,__currentRuleSet__:null,__error_infos:[],__decompressed:!1,done:!1,_backtrack:!1,_input:"",_more:!1,_signaled_error_token:!1,conditionStack:[],match:"",matched:"",matches:!1,yytext:"",offset:0,yyleng:0,yylineno:0,yylloc:null,constructLexErrorInfo:function(t,i,r){if(t=""+t,r==null&&(r=!(t.indexOf(`
|
|
4
|
+
`)>0&&t.indexOf("^")>0)),this.yylloc&&r){if(typeof this.prettyPrintRange=="function"){var s=this.prettyPrintRange(this.yylloc);/\n\s*$/.test(t)||(t+=`
|
|
5
|
+
`),t+=`
|
|
6
|
+
Erroneous area:
|
|
7
|
+
`+this.prettyPrintRange(this.yylloc)}else if(typeof this.showPosition=="function"){var e=this.showPosition();e&&(t.length&&t[t.length-1]!==`
|
|
8
|
+
`&&e[0]!==`
|
|
9
|
+
`?t+=`
|
|
10
|
+
`+e:t+=e)}}var h={errStr:t,recoverable:!!i,text:this.match,token:null,line:this.yylineno,loc:this.yylloc,yy:this.yy,lexer:this,destroy:function(){var v=!!this.recoverable;for(var u in this)this.hasOwnProperty(u)&&typeof u=="object"&&(this[u]=void 0);this.recoverable=v}};return this.__error_infos.push(h),h},parseError:function(t,i,r){if(r||(r=this.JisonLexerError),this.yy){if(this.yy.parser&&typeof this.yy.parser.parseError=="function")return this.yy.parser.parseError.call(this,t,i,r)||this.ERROR;if(typeof this.yy.parseError=="function")return this.yy.parseError.call(this,t,i,r)||this.ERROR}throw new r(t,i)},yyerror:function(t){var i="";this.yylloc&&(i=" on line "+(this.yylineno+1));var r=this.constructLexErrorInfo("Lexical error"+i+": "+t,this.options.lexerErrorsAreRecoverable),s=Array.prototype.slice.call(arguments,1);return s.length&&(r.extra_error_attributes=s),this.parseError(r.errStr,r,this.JisonLexerError)||this.ERROR},cleanupAfterLex:function(t){if(this.setInput("",{}),!t){for(var i=this.__error_infos.length-1;i>=0;i--){var r=this.__error_infos[i];r&&typeof r.destroy=="function"&&r.destroy()}this.__error_infos.length=0}return this},clear:function(){this.yytext="",this.yyleng=0,this.match="",this.matches=!1,this._more=!1,this._backtrack=!1;var t=this.yylloc?this.yylloc.last_column:0;this.yylloc={first_line:this.yylineno+1,first_column:t,last_line:this.yylineno+1,last_column:t,range:[this.offset,this.offset]}},setInput:function(t,i){if(this.yy=i||this.yy||{},!this.__decompressed){for(var r=this.rules,s=0,e=r.length;s<e;s++){var h=r[s];typeof h=="number"&&(r[s]=r[h])}var _=this.conditions;for(var v in _){for(var u=_[v],d=u.rules,e=d.length,a=new Array(e+1),f=new Array(e+1),s=0;s<e;s++){var x=d[s],h=r[x];a[s+1]=h,f[s+1]=x}u.rules=f,u.__rule_regexes=a,u.__rule_count=e}this.__decompressed=!0}return this._input=t||"",this.clear(),this._signaled_error_token=!1,this.done=!1,this.yylineno=0,this.matched="",this.conditionStack=["INITIAL"],this.__currentRuleSet__=null,this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0,range:[0,0]},this.offset=0,this},editRemainingInput:function(t,i){var r=t.call(this,this._input,i);return typeof r!="string"?r&&(this._input=""+r):this._input=r,this},input:function(){if(!this._input)return null;var t=this._input[0];this.yytext+=t,this.yyleng++,this.offset++,this.match+=t,this.matched+=t;var i=1,r=!1;if(t===`
|
|
11
|
+
`)r=!0;else if(t==="\r"){r=!0;var s=this._input[1];s===`
|
|
12
|
+
`&&(i++,t+=s,this.yytext+=s,this.yyleng++,this.offset++,this.match+=s,this.matched+=s,this.yylloc.range[1]++)}return r?(this.yylineno++,this.yylloc.last_line++,this.yylloc.last_column=0):this.yylloc.last_column++,this.yylloc.range[1]++,this._input=this._input.slice(i),t},unput:function(t){var i=t.length,r=t.split(/(?:\r\n?|\n)/g);if(this._input=t+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-i),this.yyleng=this.yytext.length,this.offset-=i,this.match=this.match.substr(0,this.match.length-i),this.matched=this.matched.substr(0,this.matched.length-i),r.length>1){this.yylineno-=r.length-1,this.yylloc.last_line=this.yylineno+1;var s=this.match,e=s.split(/(?:\r\n?|\n)/g);e.length===1&&(s=this.matched,e=s.split(/(?:\r\n?|\n)/g)),this.yylloc.last_column=e[e.length-1].length}else this.yylloc.last_column-=i;return this.yylloc.range[1]=this.yylloc.range[0]+this.yyleng,this.done=!1,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else{var t="";this.yylloc&&(t=" on line "+(this.yylineno+1));var i=this.constructLexErrorInfo("Lexical error"+t+": You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).",!1);this._signaled_error_token=this.parseError(i.errStr,i,this.JisonLexerError)||this.ERROR}return this},less:function(t){return this.unput(this.match.slice(t))},pastInput:function(t,i){var r=this.matched.substring(0,this.matched.length-this.match.length);t<0?t=r.length:t||(t=20),i<0?i=r.length:i||(i=1),r=r.substr(-t*2-2);var s=r.replace(/\r\n|\r/g,`
|
|
13
|
+
`).split(`
|
|
14
|
+
`);return s=s.slice(-i),r=s.join(`
|
|
15
|
+
`),r.length>t&&(r="..."+r.substr(-t)),r},upcomingInput:function(t,i){var r=this.match;t<0?t=r.length+this._input.length:t||(t=20),i<0?i=t:i||(i=1),r.length<t*2+2&&(r+=this._input.substring(0,t*2+2));var s=r.replace(/\r\n|\r/g,`
|
|
16
|
+
`).split(`
|
|
17
|
+
`);return s=s.slice(0,i),r=s.join(`
|
|
18
|
+
`),r.length>t&&(r=r.substring(0,t)+"..."),r},showPosition:function(t,i){var r=this.pastInput(t).replace(/\s/g," "),s=new Array(r.length+1).join("-");return r+this.upcomingInput(i).replace(/\s/g," ")+`
|
|
19
|
+
`+s+"^"},deriveLocationInfo:function(t,i,r,s){var e={first_line:1,first_column:0,last_line:1,last_column:0,range:[0,0]};return t&&(e.first_line=t.first_line|0,e.last_line=t.last_line|0,e.first_column=t.first_column|0,e.last_column=t.last_column|0,t.range&&(e.range[0]=t.range[0]|0,e.range[1]=t.range[1]|0)),(e.first_line<=0||e.last_line<e.first_line)&&(e.first_line<=0&&i&&(e.first_line=i.last_line|0,e.first_column=i.last_column|0,i.range&&(e.range[0]=t.range[1]|0)),(e.last_line<=0||e.last_line<e.first_line)&&r&&(e.last_line=r.first_line|0,e.last_column=r.first_column|0,r.range&&(e.range[1]=t.range[0]|0)),e.first_line<=0&&s&&(e.last_line<=0||s.last_line<=e.last_line)&&(e.first_line=s.first_line|0,e.first_column=s.first_column|0,s.range&&(e.range[0]=s.range[0]|0)),e.last_line<=0&&s&&(e.first_line<=0||s.first_line>=e.first_line)&&(e.last_line=s.last_line|0,e.last_column=s.last_column|0,s.range&&(e.range[1]=s.range[1]|0))),e.last_line<=0&&(e.first_line<=0?(e.first_line=this.yylloc.first_line,e.last_line=this.yylloc.last_line,e.first_column=this.yylloc.first_column,e.last_column=this.yylloc.last_column,e.range[0]=this.yylloc.range[0],e.range[1]=this.yylloc.range[1]):(e.last_line=this.yylloc.last_line,e.last_column=this.yylloc.last_column,e.range[1]=this.yylloc.range[1])),e.first_line<=0&&(e.first_line=e.last_line,e.first_column=0,e.range[1]=e.range[0]),e.first_column<0&&(e.first_column=0),e.last_column<0&&(e.last_column=e.first_column>0?e.first_column:80),e},prettyPrintRange:function(t,i,r){t=this.deriveLocationInfo(t,i,r);const s=3,e=1,h=2;var _=this.matched+this._input,v=_.split(`
|
|
20
|
+
`),u=Math.max(1,i?i.first_line:t.first_line-s),d=Math.max(1,r?r.last_line:t.last_line+e),a=1+Math.log10(d|1)|0,f=new Array(a).join(" "),x=[],j=v.slice(u-1,d+1).map(function(E,P){var p=P+u,F=(f+p).substr(-a),L=F+": "+E,m=new Array(a+1).join("^"),D=3,O=0;if(p===t.first_line?(D+=t.first_column,O=Math.max(2,(p===t.last_line?t.last_column:E.length)-t.first_column+1)):p===t.last_line?O=Math.max(2,t.last_column+1):p>t.first_line&&p<t.last_line&&(O=Math.max(2,E.length+1)),O){var k=new Array(D).join("."),b=new Array(O).join("^");L+=`
|
|
21
|
+
`+m+k+b,E.trim().length>0&&x.push(P)}return L=L.replace(/\t/g," "),L});if(x.length>2*h){var q=x[h-1]+1,B=x[x.length-h]-1,$=new Array(a+1).join(" ")+" (...continued...)";$+=`
|
|
22
|
+
`+new Array(a+1).join("-")+" (---------------)",j.splice(q,B-q+1,$)}return j.join(`
|
|
23
|
+
`)},describeYYLLOC:function(t,i){var r=t.first_line,s=t.last_line,e=t.first_column,h=t.last_column,_=s-r,v=h-e,u;if(_===0?(u="line "+r+", ",v<=1?u+="column "+e:u+="columns "+e+" .. "+h):u="lines "+r+"(column "+e+") .. "+s+"(column "+h+")",t.range&&i){var d=t.range[0],a=t.range[1]-1;a<=d?u+=" {String Offset: "+d+"}":u+=" {String Offset range: "+d+" .. "+a+"}"}return u},test_match:function(t,i){var r,s,e,h,_;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.yylloc.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column,range:this.yylloc.range.slice(0)},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done}),h=t[0],_=h.length,s=h.split(/(?:\r\n?|\n)/g),s.length>1?(this.yylineno+=s.length-1,this.yylloc.last_line=this.yylineno+1,this.yylloc.last_column=s[s.length-1].length):this.yylloc.last_column+=_,this.yytext+=h,this.match+=h,this.matched+=h,this.matches=t,this.yyleng=this.yytext.length,this.yylloc.range[1]+=_,this.offset+=_,this._more=!1,this._backtrack=!1,this._input=this._input.slice(_),r=this.performAction.call(this,this.yy,i,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),r)return r;if(this._backtrack){for(var v in e)this[v]=e[v];return this.__currentRuleSet__=null,!1}else if(this._signaled_error_token)return r=this._signaled_error_token,this._signaled_error_token=!1,r;return!1},next:function(){if(this.done)return this.clear(),this.EOF;this._input||(this.done=!0);var t,i,r,s;this._more||this.clear();var e=this.__currentRuleSet__;if(!e&&(e=this.__currentRuleSet__=this._currentRules(),!e||!e.rules)){var h="";this.options.trackPosition&&(h=" on line "+(this.yylineno+1));var _=this.constructLexErrorInfo("Internal lexer engine error"+h+': The lex grammar programmer pushed a non-existing condition name "'+this.topState()+'"; this is a fatal error and should be reported to the application programmer team!',!1);return this.parseError(_.errStr,_,this.JisonLexerError)||this.ERROR}for(var v=e.rules,u=e.__rule_regexes,d=e.__rule_count,a=1;a<=d;a++)if(r=this._input.match(u[a]),r&&(!i||r[0].length>i[0].length)){if(i=r,s=a,this.options.backtrack_lexer){if(t=this.test_match(r,v[a]),t!==!1)return t;if(this._backtrack){i=void 0;continue}else return!1}else if(!this.options.flex)break}if(i)return t=this.test_match(i,v[s]),t!==!1?t:!1;if(this._input){var h="";this.options.trackPosition&&(h=" on line "+(this.yylineno+1));var _=this.constructLexErrorInfo("Lexical error"+h+": Unrecognized text.",this.options.lexerErrorsAreRecoverable),f=this._input,x=this.topState(),j=this.conditionStack.length;return t=this.parseError(_.errStr,_,this.JisonLexerError)||this.ERROR,t===this.ERROR&&!this.matches&&f===this._input&&x===this.topState()&&j===this.conditionStack.length&&this.input(),t}else return this.done=!0,this.clear(),this.EOF},lex:function(){var t;for(typeof this.pre_lex=="function"&&(t=this.pre_lex.call(this,0)),typeof this.options.pre_lex=="function"&&(t=this.options.pre_lex.call(this,t)||t),this.yy&&typeof this.yy.pre_lex=="function"&&(t=this.yy.pre_lex.call(this,t)||t);!t;)t=this.next();return this.yy&&typeof this.yy.post_lex=="function"&&(t=this.yy.post_lex.call(this,t)||t),typeof this.options.post_lex=="function"&&(t=this.options.post_lex.call(this,t)||t),typeof this.post_lex=="function"&&(t=this.post_lex.call(this,t)||t),t},fastLex:function(){for(var t;!t;)t=this.next();return t},canIUse:function(){var t={fastLex:!(typeof this.pre_lex=="function"||typeof this.options.pre_lex=="function"||this.yy&&typeof this.yy.pre_lex=="function"||this.yy&&typeof this.yy.post_lex=="function"||typeof this.options.post_lex=="function"||typeof this.post_lex=="function")&&typeof this.fastLex=="function"};return t},begin:function(t){return this.pushState(t)},pushState:function(t){return this.conditionStack.push(t),this.__currentRuleSet__=null,this},popState:function(){var t=this.conditionStack.length-1;return t>0?(this.__currentRuleSet__=null,this.conditionStack.pop()):this.conditionStack[0]},topState:function(t){return t=this.conditionStack.length-1-Math.abs(t||0),t>=0?this.conditionStack[t]:"INITIAL"},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]]:this.conditions.INITIAL},stateStackSize:function(){return this.conditionStack.length},options:{trackPosition:!0},JisonLexerError:l,performAction:function(t,i,r){var s=this,e=r;switch(i){case 0:break;default:return this.simpleCaseActionClusters[i]}},simpleCaseActionClusters:{1:8,2:5,3:6,4:3,5:4,6:7,7:1,8:"INVALID"},rules:[/^(?:\s+)/,/^(?:\d+(\.\d+)?\b)/,/^(?:\*)/,/^(?:\/)/,/^(?:\+)/,/^(?:-)/,/^(?:[^\W\d]+)/,/^(?:$)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8],inclusive:!0}}};return o}();I.lexer=tt;function K(){this.yy={}}K.prototype=I,I.Parser=K;function et(){return I.parse.apply(I,arguments)}export default{parser:I,Parser:K,parse:et};
|
package/dist/tex2typst.min.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";(()=>{function
|
|
2
|
-
`));for(let
|
|
3
|
-
`)),e.push(new l(2,"\\end")),e.push(new l(1,"{")),e=e.concat(this.head),e.push(new l(1,"}")),e}};function
|
|
4
|
-
`)-1):this._col+=u,s}},
|
|
5
|
-
`)],[String.raw`\s+`,n=>new l(5,n.text())],[String.raw`\\[{}%$&#_|]`,n=>new l(1,n.text())],[String.raw`(\\[a-zA-Z]+)(\s*\d|\s+[a-zA-Z])\s*([0-9a-zA-Z])`,n=>{let e=n.reMatchArray(),
|
|
6
|
-
`))){if(u.head.eq(new l(7,"&")))throw new w("Unexpected & outside of an alignment");s.push(u)}}let a;return s.length===1?a=s[0]:a=new E(s),[a,
|
|
7
|
-
`))&&(a.head.eq(new l(7,"\\\\"))?(s=[],o=new E([]),s.push(o),
|
|
8
|
-
`)
|
|
9
|
-
`),
|
|
10
|
-
`)this.queue.push(new i(1,r));else throw new ue(`Unexpected whitespace character: ${r}`,t);break}else{this.queue.push(t.head);break}}case"group":{let t=e;for(let r of t.items)this.serialize(r);break}case"leftright":{let t=e,r=new i(1,"lr"),{left:s,right:o}=t;t.head.eq(r)&&(this.queue.push(r),this.queue.push(W)),s&&this.queue.push(s),this.serialize(t.body),o&&this.queue.push(o),t.head.eq(r)&&this.queue.push(U);break}case"supsub":{let t=e,{base:r,sup:s,sub:o}=t;this.appendWithBracketsIfNeeded(r);let a=!1,u=s&&s.head.eq(new i(2,"'"));u&&(this.queue.push(new i(2,"'")),a=!1),o&&(this.queue.push(new i(2,"_")),a=this.appendWithBracketsIfNeeded(o)),s&&!u&&(this.queue.push(new i(2,"^")),a=this.appendWithBracketsIfNeeded(s)),a&&this.queue.push(Me);break}case"funcCall":{let t=e,r=t.head;this.queue.push(r),this.insideFunctionDepth++,this.queue.push(W);for(let s=0;s<t.args.length;s++)this.serialize(t.args[s]),s<t.args.length-1&&this.queue.push(new i(2,","));if(t.options)for(let[s,o]of Object.entries(t.options))this.queue.push(new i(3,`, ${s}: ${o.toString()}`));this.queue.push(U),this.insideFunctionDepth--;break}case"fraction":{let t=e,[r,s]=t.args,o=this.queue.length;!this.appendWithBracketsIfNeeded(r)&&this.queue.splice(o,0,Me),this.queue.push(new i(2,"/")),this.appendWithBracketsIfNeeded(s);break}case"matrixLike":{let t=e,r=t.matrix,s,o;if(t.head.eq(f.MAT)?(s=new i(2,","),o=new i(2,";")):t.head.eq(f.CASES)?(s=new i(2,"&"),o=new i(2,",")):t.head.eq(i.NONE)&&(s=new i(2,"&"),o=new i(1,"\\")),!t.head.eq(i.NONE)&&(this.queue.push(t.head),this.insideFunctionDepth++,this.queue.push(W),t.options))for(let[a,u]of Object.entries(t.options))this.queue.push(new i(3,`${a}: ${u.toString()}, `));r.forEach((a,u)=>{a.forEach((p,c)=>{this.serialize(p),c<a.length-1?this.queue.push(s):u<r.length-1&&this.queue.push(o)})}),t.head.eq(i.NONE)||(this.queue.push(U),this.insideFunctionDepth--);break}case"markupFunc":{let t=e;if(this.queue.push(t.head),this.queue.push(W),t.options){let r=Object.entries(t.options);for(let s=0;s<r.length;s++){let[o,a]=r[s];this.queue.push(new i(3,`${o}: ${a.toString()}`)),s<r.length-1&&this.queue.push(new i(2,","))}}this.queue.push(U),this.queue.push(new i(3,"["));for(let r of t.fragments)this.queue.push(new i(3,"$")),this.serialize(r),this.queue.push(new i(3,"$"));this.queue.push(new i(3,"]"));break}default:throw new ue(`Unimplemented node type to append: ${e.type}`,e)}}appendWithBracketsIfNeeded(e){let t=["group","supsub","matrixLike","fraction","empty"].includes(e.type);if(e.type==="group"){let r=e;if(r.items.length===0)t=!0;else{let s=r.items[0],o=r.items[r.items.length-1];Fe(s)&&Fe(o)&&(t=!1)}}return t?(this.queue.push(W),this.serialize(e),this.queue.push(U)):this.serialize(e),!t}flushQueue(){let e=new i(1,"");for(let t=0;t<this.queue.length;t++)this.queue[t].eq(Me)&&(t===0||t===this.queue.length-1||this.queue[t-1].type===6||this.queue[t-1].isOneOf([W,Ge])||this.queue[t+1].isOneOf([U,gt,Ge]))&&(this.queue[t]=e);this.queue=this.queue.filter(t=>!t.eq(e));for(let t=0;t<this.queue.length;t++){let r=this.queue[t],s=t===0?null:this.queue[t-1];this.writeBuffer(s,r)}this.queue=[]}finalize(){this.flushQueue();let e=function(s){let o=s.replace(/floor\.l\s*(.*?)\s*floor\.r/g,"floor($1)");return o=o.replace(/floor\(\)/g,'floor("")'),o},t=function(s){let o=s.replace(/ceil\.l\s*(.*?)\s*ceil\.r/g,"ceil($1)");return o=o.replace(/ceil\(\)/g,'ceil("")'),o},r=function(s){let o=s.replace(/floor\.l\s*(.*?)\s*ceil\.r/g,"round($1)");return o=o.replace(/round\(\)/g,'round("")'),o};if(this.optimize){let s=[e,t,r];for(let o of s)this.buffer=o(this.buffer)}return this.buffer}};var x=new Map([["displaystyle","display"],["hspace","#h"],["|","bar.v.double"],[",","thin"],[":","med"],[" ","med"],[";","thick"],["ln","ln"],["log","log"],["cos","cos"],["sin","sin"],["tan","tan"],["cot","cot"],["sec","sec"],["csc","csc"],["mod","mod"],["omicron","omicron"],["Xi","Xi"],["Upsilon","Upsilon"],["lim","lim"],["binom","binom"],["tilde","tilde"],["hat","hat"],["sqrt","sqrt"],["nonumber",""],["vec","arrow"],["neq","eq.not"],["dot","dot"],["ddot","dot.double"],["doteq","dot(eq)"],["dots","dots.h"],["vdots","dots.v"],["ddots","dots.down"],["widehat","hat"],["widetilde","tilde"],["quad","quad"],["qquad","wide"],["overbrace","overbrace"],["underbrace","underbrace"],["overline","overline"],["underline","underline"],["bar","macron"],["dbinom","binom"],["tbinom","binom"],["dfrac","frac"],["tfrac","frac"],["operatorname","op"],["boldsymbol","bold"],["mathbb","bb"],["mathbf","bold"],["mathcal","cal"],["mathit","italic"],["mathfrak","frak"],["mathrm","upright"],["mathsf","sans"],["mathtt","mono"],["rm","upright"],["pmb","bold"],["leadsto","arrow.r.squiggly"],["P","pilcrow"],["S","section"],["aleph","alef"],["infin","infinity"],["Delta","Delta"],["Gamma","Gamma"],["Lambda","Lambda"],["Omega","Omega"],["Phi","Phi"],["Pi","Pi"],["Psi","Psi"],["Sigma","Sigma"],["Theta","Theta"],["alpha","alpha"],["beta","beta"],["bigcirc","circle.big"],["bullet","bullet"],["cdot","dot.op"],["cdots","dots.c"],["checkmark","checkmark"],["chi","chi"],["circ","circle.small"],["colon","colon"],["cong","tilde.equiv"],["coprod","product.co"],["copyright","copyright"],["cup","union"],["curlyvee","or.curly"],["curlywedge","and.curly"],["dagger","dagger"],["dashv","tack.l"],["ddagger","dagger.double"],["delta","delta"],["ddots","dots.down"],["diamond","diamond"],["div","div"],["divideontimes","times.div"],["dotplus","plus.dot"],["ell","ell"],["emptyset","nothing"],["epsilon","epsilon.alt"],["equiv","equiv"],["eta","eta"],["exists","exists"],["forall","forall"],["gamma","gamma"],["ge","gt.eq"],["geq","gt.eq"],["geqslant","gt.eq.slant"],["gg","gt.double"],["hbar","planck.reduce"],["imath","dotless.i"],["iiiint","integral.quad"],["iiint","integral.triple"],["iint","integral.double"],["in","in"],["infty","infinity"],["int","integral"],["intercal","top"],["iota","iota"],["jmath","dotless.j"],["kappa","kappa"],["lambda","lambda"],["land","and"],["langle","angle.l"],["lbrace","brace.l"],["lbrack","bracket.l"],["ldots","dots.h"],["le","lt.eq"],["leftthreetimes","times.three.l"],["leftrightarrow","arrow.l.r"],["leq","lt.eq"],["leqslant","lt.eq.slant"],["lhd","triangle.l"],["ll","lt.double"],["lor","or"],["ltimes","times.l"],["measuredangle","angle.arc"],["mid","divides"],["models","models"],["mp","minus.plus"],["mu","mu"],["nabla","nabla"],["ncong","tilde.equiv.not"],["ne","eq.not"],["neg","not"],["neq","eq.not"],["nexists","exists.not"],["ni","in.rev"],["nleftarrow","arrow.l.not"],["nleq","lt.eq.not"],["nparallel","parallel.not"],["ngeq","gt.eq.not"],["nmid","divides.not"],["notin","in.not"],["nsim","tilde.not"],["nsubseteq","subset.eq.not"],["nu","nu"],["ntriangleleft","lt.tri.not"],["ntriangleright","gt.tri.not"],["odot","dot.circle"],["oint","integral.cont"],["oiint","integral.surf"],["oiiint","integral.vol"],["omega","omega"],["ominus","minus.circle"],["otimes","times.circle"],["parallel","parallel"],["partial","diff"],["perp","perp"],["phi","phi.alt"],["pi","pi"],["pm","plus.minus"],["pounds","pound"],["prec","prec"],["preceq","prec.eq"],["prime","prime"],["prod","product"],["propto","prop"],["psi","psi"],["rangle","angle.r"],["rbrace","brace.r"],["rbrack","bracket.r"],["rhd","triangle"],["rho","rho"],["rightarrow","arrow.r"],["rightthreetimes","times.three.r"],["rtimes","times.r"],["setminus","without"],["sigma","sigma"],["sim","tilde.op"],["simeq","tilde.eq"],["slash","slash"],["smallsetminus","without"],["spadesuit","suit.spade"],["sqsubseteq","subset.eq.sq"],["sqsupseteq","supset.eq.sq"],["subset","subset"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["succeq","succ.eq"],["sum","sum"],["supset","supset"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["tau","tau"],["theta","theta"],["times","times"],["to","arrow.r"],["top","top"],["triangle","triangle.t"],["twoheadrightarrow","arrow.r.twohead"],["upharpoonright","harpoon.tr"],["uplus","union.plus"],["upsilon","upsilon"],["varepsilon","epsilon"],["varnothing","diameter"],["varphi","phi"],["varpi","pi.alt"],["varrho","rho.alt"],["varsigma","sigma.alt"],["vartheta","theta.alt"],["vdash","tack.r"],["vdots","dots.v"],["vee","or"],["wedge","and"],["wr","wreath"],["xi","xi"],["yen","yen"],["zeta","zeta"],["intop","limits(integral)"],["mathscr","scr"],["LaTeX","#LaTeX"],["TeX","#TeX"]]),Tt=new Map([["acwopencirclearrow","arrow.ccw"],["adots","dots.up"],["angdnr","angle.acute"],["angle","angle"],["angles","angle.s"],["approx","approx"],["approxeq","approx.eq"],["approxident","tilde.triple"],["assert","tack.r.short"],["ast","ast.op"],["asymp","asymp"],["awint","integral.ccw"],["backcong","tilde.rev.equiv"],["backdprime","prime.double.rev"],["backprime","prime.rev"],["backsim","tilde.rev"],["backsimeq","tilde.eq.rev"],["backslash","backslash"],["backtrprime","prime.triple.rev"],["bardownharpoonleft","harpoon.bl.bar"],["bardownharpoonright","harpoon.br.bar"],["barleftarrow","arrow.l.stop"],["barleftarrowrightarrowbar","arrows.lr.stop"],["barleftharpoondown","harpoon.lb.stop"],["barleftharpoonup","harpoon.lt.stop"],["barrightharpoondown","harpoon.rb.bar"],["barrightharpoonup","harpoon.rt.bar"],["baruparrow","arrow.t.stop"],["barupharpoonleft","harpoon.tl.stop"],["barupharpoonright","harpoon.tr.stop"],["barV","tack.b.double"],["BbbA","AA"],["BbbB","BB"],["BbbC","CC"],["BbbD","DD"],["BbbE","EE"],["BbbF","FF"],["BbbG","GG"],["BbbH","HH"],["BbbI","II"],["BbbJ","JJ"],["BbbK","KK"],["BbbL","LL"],["BbbM","MM"],["BbbN","NN"],["BbbO","OO"],["BbbP","PP"],["BbbQ","QQ"],["BbbR","RR"],["BbbS","SS"],["BbbT","TT"],["BbbU","UU"],["BbbV","VV"],["BbbW","WW"],["BbbX","XX"],["BbbY","YY"],["BbbZ","ZZ"],["because","because"],["bigblacktriangledown","triangle.filled.b"],["bigblacktriangleup","triangle.filled.t"],["bigbot","tack.t.big"],["bigcap","inter.big"],["bigcup","union.big"],["bigcupdot","union.dot.big"],["biginterleave","interleave.big"],["bigodot","dot.circle.big"],["bigoplus","plus.circle.big"],["bigotimes","times.circle.big"],["bigsqcap","inter.sq.big"],["bigsqcup","union.sq.big"],["bigstar","star.filled"],["bigtimes","times.big"],["bigtop","tack.b.big"],["bigtriangledown","triangle.stroked.b"],["bigtriangleup","triangle.stroked.t"],["biguplus","union.plus.big"],["bigvee","or.big"],["bigwedge","and.big"],["bigwhitestar","star.stroked"],["blackhourglass","hourglass.filled"],["blacktriangle","triangle.filled.small.t"],["blacktriangledown","triangle.filled.small.b"],["blacktriangleleft","triangle.filled.l"],["blacktriangleright","triangle.filled.r"],["blkhorzoval","ellipse.filled.h"],["blkvertoval","ellipse.filled.v"],["bot","bot"],["boxast","ast.square"],["boxdot","dot.square"],["boxminus","minus.square"],["boxplus","plus.square"],["boxtimes","times.square"],["cap","inter"],["Cap","inter.double"],["capdot","inter.dot"],["capwedge","inter.and"],["caretinsert","caret"],["cdot","dot.op"],["cdotp","dot.c"],["checkmark","checkmark"],["circledast","ast.circle"],["circledcirc","circle.nested"],["circleddash","dash.circle"],["circledequal","eq.circle"],["circledparallel","parallel.circle"],["circledvert","bar.v.circle"],["clubsuit","suit.club.filled"],["Colon","colon.double"],["coloneq","colon.eq"],["Coloneq","colon.double.eq"],["complement","complement"],["cong","tilde.equiv"],["coprod","product.co"],["cup","union"],["Cup","union.double"],["cupdot","union.dot"],["cupleftarrow","union.arrow"],["cupvee","union.or"],["curlyeqprec","eq.prec"],["curlyeqsucc","eq.succ"],["curlyvee","or.curly"],["curlywedge","and.curly"],["curvearrowleft","arrow.ccw.half"],["curvearrowright","arrow.cw.half"],["cwopencirclearrow","arrow.cw"],["dagger","dagger"],["dashcolon","dash.colon"],["dashv","tack.l"],["Dashv","tack.l.double"],["dashVdash","tack.l.r"],["ddagger","dagger.double"],["ddddot","dot.quad"],["dddot","dot.triple"],["ddots","dots.down"],["DDownarrow","arrow.b.quad"],["Ddownarrow","arrow.b.triple"],["diameter","diameter"],["diamondcdot","diamond.stroked.dot"],["diamondsuit","suit.diamond.stroked"],["dicei","die.one"],["diceii","die.two"],["diceiii","die.three"],["diceiv","die.four"],["dicev","die.five"],["dicevi","die.six"],["div","div"],["divideontimes","times.div"],["Doteq","eq.dots"],["dotminus","minus.dot"],["dotplus","plus.dot"],["dotsim","tilde.dot"],["dottedcircle","circle.dotted"],["dottedsquare","square.stroked.dotted"],["doubleplus","plus.double"],["downarrow","arrow.b"],["Downarrow","arrow.b.double"],["downarrowbar","arrow.b.stop"],["downdasharrow","arrow.b.dashed"],["downdownarrows","arrows.bb"],["downharpoonleft","harpoon.bl"],["downharpoonleftbar","harpoon.bl.stop"],["downharpoonright","harpoon.br"],["downharpoonrightbar","harpoon.br.stop"],["downharpoonsleftright","harpoons.blbr"],["downrightcurvedarrow","arrow.b.curve"],["downuparrows","arrows.bt"],["downupharpoonsleftright","harpoons.bltr"],["downwhitearrow","arrow.b.stroked"],["downzigzagarrow","arrow.zigzag"],["dprime","prime.double"],["dualmap","multimap.double"],["eighthnote","note.eighth.alt"],["ell","ell"],["emptysetoarr","emptyset.arrow.r"],["emptysetoarrl","emptyset.arrow.l"],["emptysetobar","emptyset.bar"],["emptysetocirc","emptyset.circle"],["eparsl","parallel.slanted.eq"],["eqcolon","eq.colon"],["eqdef","eq.def"],["eqgtr","eq.gt"],["eqless","eq.lt"],["eqsim","minus.tilde"],["equal","eq"],["equalparallel","parallel.eq"],["equiv","eq.triple"],["Equiv","eq.quad"],["equivVert","parallel.equiv"],["eqvparsl","parallel.slanted.equiv"],["errbarblackcircle","errorbar.circle.filled"],["errbarblackdiamond","errorbar.diamond.filled"],["errbarblacksquare","errorbar.square.filled"],["errbarcircle","errorbar.circle.stroked"],["errbardiamond","errorbar.diamond.stroked"],["errbarsquare","errorbar.square.stroked"],["euro","euro"],["Exclam","excl.double"],["exists","exists"],["fallingdotseq","eq.dots.down"],["fint","integral.slash"],["flat","flat"],["forall","forall"],["fourvdots","fence.dotted"],["fullouterjoin","join.l.r"],["geq","gt.eq"],["geqq","gt.equiv"],["geqslant","gt.eq.slant"],["gg","gt.double"],["ggg","gt.triple"],["gggnest","gt.triple.nested"],["gnapprox","gt.napprox"],["gneq","gt.neq"],["gneqq","gt.nequiv"],["gnsim","gt.ntilde"],["greater","gt"],["gtlpar","angle.spheric.rev"],["gtrapprox","gt.approx"],["gtrdot","gt.dot"],["gtreqless","gt.eq.lt"],["gtrless","gt.lt"],["gtrsim","gt.tilde"],["heartsuit","suit.heart.stroked"],["hknearrow","arrow.tr.hook"],["hknwarrow","arrow.tl.hook"],["hksearrow","arrow.br.hook"],["hkswarrow","arrow.bl.hook"],["hookleftarrow","arrow.l.hook"],["hookrightarrow","arrow.r.hook"],["horizbar","bar.h"],["hourglass","hourglass.stroked"],["hrectangle","rect.stroked.h"],["hrectangleblack","rect.filled.h"],["hslash","planck.reduce"],["hzigzag","dash.wave.double"],["iiiint","integral.quad"],["iiint","integral.triple"],["iinfin","infinity.incomplete"],["iint","integral.double"],["Im","Im"],["imageof","image"],["in","in"],["increment","laplace"],["infty","infinity"],["int","integral"],["intbar","integral.dash"],["intBar","integral.dash.double"],["intcap","integral.inter"],["intclockwise","integral.cw"],["intcup","integral.union"],["interleave","interleave"],["intlarhk","integral.arrow.hook"],["intx","integral.times"],["Join","join"],["langle","angle.l"],["lAngle","angle.l.double"],["langledot","angle.l.dot"],["lat","lat"],["late","lat.eq"],["lbrace","brace.l"],["lBrace","brace.l.double"],["lbrack","bracket.l"],["lBrack","bracket.l.double"],["lbrbrak","shell.l"],["Lbrbrak","shell.l.double"],["lceil","ceil.l"],["lcurvyangle","angle.l.curly"],["leftarrow","arrow.l"],["Leftarrow","arrow.l.double"],["leftarrowtail","arrow.l.tail"],["leftdasharrow","arrow.l.dashed"],["leftdotarrow","arrow.l.dotted"],["leftdowncurvedarrow","arrow.l.curve"],["leftharpoondown","harpoon.lb"],["leftharpoondownbar","harpoon.lb.bar"],["leftharpoonsupdown","harpoons.ltlb"],["leftharpoonup","harpoon.lt"],["leftharpoonupbar","harpoon.lt.bar"],["leftleftarrows","arrows.ll"],["leftouterjoin","join.l"],["leftrightarrow","arrow.l.r"],["Leftrightarrow","arrow.l.r.double"],["leftrightarrows","arrows.lr"],["leftrightharpoondowndown","harpoon.lb.rb"],["leftrightharpoondownup","harpoon.lb.rt"],["leftrightharpoons","harpoons.ltrb"],["leftrightharpoonsdown","harpoons.lbrb"],["leftrightharpoonsup","harpoons.ltrt"],["leftrightharpoonupdown","harpoon.lt.rb"],["leftrightharpoonupup","harpoon.lt.rt"],["leftrightsquigarrow","arrow.l.r.wave"],["leftsquigarrow","arrow.l.squiggly"],["leftthreearrows","arrows.lll"],["leftthreetimes","times.three.l"],["leftwavearrow","arrow.l.wave"],["leftwhitearrow","arrow.l.stroked"],["leq","lt.eq"],["leqq","lt.equiv"],["leqslant","lt.eq.slant"],["less","lt"],["lessapprox","lt.approx"],["lessdot","lt.dot"],["lesseqgtr","lt.eq.gt"],["lessgtr","lt.gt"],["lesssim","lt.tilde"],["lfloor","floor.l"],["lgblkcircle","circle.filled.big"],["lgblksquare","square.filled.big"],["lgwhtcircle","circle.stroked.big"],["lgwhtsquare","square.stroked.big"],["ll","lt.double"],["llblacktriangle","triangle.filled.bl"],["LLeftarrow","arrow.l.quad"],["Lleftarrow","arrow.l.triple"],["lll","lt.triple"],["lllnest","lt.triple.nested"],["lltriangle","triangle.stroked.bl"],["lnapprox","lt.napprox"],["lneq","lt.neq"],["lneqq","lt.nequiv"],["lnsim","lt.ntilde"],["longdashv","tack.l.long"],["Longleftarrow","arrow.l.double.long"],["longleftarrow","arrow.l.long"],["Longleftrightarrow","arrow.l.r.double.long"],["longleftrightarrow","arrow.l.r.long"],["longleftsquigarrow","arrow.l.long.squiggly"],["Longmapsfrom","arrow.l.double.long.bar"],["longmapsfrom","arrow.l.long.bar"],["longmapsto","arrow.r.long.bar"],["Longmapsto","arrow.r.double.long.bar"],["Longrightarrow","arrow.r.double.long"],["longrightarrow","arrow.r.long"],["longrightsquigarrow","arrow.r.long.squiggly"],["looparrowleft","arrow.l.loop"],["looparrowright","arrow.r.loop"],["lparen","paren.l"],["lParen","paren.l.double"],["lrblacktriangle","triangle.filled.br"],["lrtriangle","triangle.stroked.br"],["ltimes","times.l"],["lvzigzag","fence.l"],["Lvzigzag","fence.l.double"],["maltese","maltese"],["mapsdown","arrow.b.bar"],["mapsfrom","arrow.l.bar"],["Mapsfrom","arrow.l.double.bar"],["mapsto","arrow.r.bar"],["Mapsto","arrow.r.double.bar"],["mapsup","arrow.t.bar"],["mathampersand","amp"],["mathatsign","at"],["mathcolon","colon"],["mathcomma","comma"],["mathdollar","dollar"],["mathexclam","excl"],["mathoctothorpe","hash"],["mathparagraph","pilcrow"],["mathpercent","percent"],["mathperiod","dot.basic"],["mathplus","plus"],["mathquestion","quest"],["mathratio","ratio"],["mathsection","section"],["mathsemicolon","semi"],["mathslash","slash"],["mathsterling","pound"],["mathyen","yen"],["mdblkdiamond","diamond.filled.medium"],["mdblklozenge","lozenge.filled.medium"],["mdblksquare","square.filled.medium"],["mdlgblkcircle","circle.filled"],["mdlgblkdiamond","diamond.filled"],["mdlgblklozenge","lozenge.filled"],["mdlgblksquare","square.filled"],["mdlgwhtcircle","circle.stroked"],["mdlgwhtdiamond","diamond.stroked"],["mdlgwhtlozenge","lozenge.stroked"],["mdlgwhtsquare","square.stroked"],["mdsmblkcircle","circle.filled.tiny"],["mdsmblksquare","square.filled.small"],["mdsmwhtcircle","circle.stroked.small"],["mdsmwhtsquare","square.stroked.small"],["mdwhtdiamond","diamond.stroked.medium"],["mdwhtlozenge","lozenge.stroked.medium"],["mdwhtsquare","square.stroked.medium"],["measeq","eq.m"],["measuredangle","angle.arc"],["measuredangleleft","angle.arc.rev"],["measuredrightangle","angle.right.arc"],["mho","Omega.inv"],["mid","divides"],["minus","minus"],["models","models"],["mp","minus.plus"],["multimap","multimap"],["nabla","gradient"],["napprox","approx.not"],["nasymp","asymp.not"],["natural","natural"],["ncong","tilde.equiv.not"],["ne","eq.not"],["nearrow","arrow.tr"],["Nearrow","arrow.tr.double"],["neg","not"],["nequiv","equiv.not"],["neswarrow","arrow.tr.bl"],["nexists","exists.not"],["ngeq","gt.eq.not"],["ngtr","gt.not"],["ngtrless","gt.lt.not"],["ngtrsim","gt.tilde.not"],["nhpar","parallel.struck"],["nhVvert","interleave.struck"],["ni","in.rev"],["nLeftarrow","arrow.l.double.not"],["nleftarrow","arrow.l.not"],["nLeftrightarrow","arrow.l.r.double.not"],["nleftrightarrow","arrow.l.r.not"],["nleq","lt.eq.not"],["nless","lt.not"],["nlessgtr","lt.gt.not"],["nlesssim","lt.tilde.not"],["nmid","divides.not"],["nni","in.rev.not"],["notin","in.not"],["nparallel","parallel.not"],["nprec","prec.not"],["npreccurlyeq","prec.curly.eq.not"],["nRightarrow","arrow.r.double.not"],["nrightarrow","arrow.r.not"],["nsim","tilde.not"],["nsimeq","tilde.eq.not"],["nsqsubseteq","subset.eq.sq.not"],["nsqsupseteq","supset.eq.sq.not"],["nsubset","subset.not"],["nsubseteq","subset.eq.not"],["nsucc","succ.not"],["nsucccurlyeq","succ.curly.eq.not"],["nsupset","supset.not"],["nsupseteq","supset.eq.not"],["ntrianglelefteq","lt.tri.eq.not"],["ntrianglerighteq","gt.tri.eq.not"],["nvartriangleleft","lt.tri.not"],["nvartriangleright","gt.tri.not"],["nVdash","forces.not"],["nvdash","tack.r.not"],["nvDash","tack.r.double.not"],["nvinfty","infinity.bar"],["nwarrow","arrow.tl"],["Nwarrow","arrow.tl.double"],["nwsearrow","arrow.tl.br"],["obrbrak","shell.t"],["obslash","backslash.circle"],["odiv","div.circle"],["odot","dot.circle"],["ogreaterthan","gt.circle"],["oiiint","integral.vol"],["oiint","integral.surf"],["oint","integral.cont"],["ointctrclockwise","integral.cont.ccw"],["olessthan","lt.circle"],["ominus","minus.circle"],["operp","perp.circle"],["oplus","plus.circle"],["origof","original"],["otimes","times.circle"],["overbracket","bracket.t"],["overparen","paren.t"],["parallel","parallel"],["parallelogram","parallelogram.stroked"],["parallelogramblack","parallelogram.filled"],["parsim","parallel.tilde"],["partial","diff"],["pentagon","penta.stroked"],["pentagonblack","penta.filled"],["perp","perp"],["Planckconst","planck"],["pm","plus.minus"],["prec","prec"],["Prec","prec.double"],["precapprox","prec.approx"],["preccurlyeq","prec.curly.eq"],["preceq","prec.eq"],["preceqq","prec.equiv"],["precnapprox","prec.napprox"],["precneq","prec.neq"],["precneqq","prec.nequiv"],["precnsim","prec.ntilde"],["precsim","prec.tilde"],["prime","prime"],["prod","product"],["propto","prop"],["QED","qed"],["qprime","prime.quad"],["quarternote","note.quarter.alt"],["questeq","eq.quest"],["Question","quest.double"],["rangle","angle.r"],["rAngle","angle.r.double"],["rangledot","angle.r.dot"],["rbrace","brace.r"],["rBrace","brace.r.double"],["rbrack","bracket.r"],["rBrack","bracket.r.double"],["rbrbrak","shell.r"],["Rbrbrak","shell.r.double"],["rceil","ceil.r"],["rcurvyangle","angle.r.curly"],["Re","Re"],["revangle","angle.rev"],["revemptyset","emptyset.rev"],["revnmid","divides.not.rev"],["rfloor","floor.r"],["rightangle","angle.right"],["rightanglemdot","angle.right.dot"],["rightanglesqr","angle.right.sq"],["rightarrow","arrow.r"],["Rightarrow","arrow.r.double"],["rightarrowbar","arrow.r.stop"],["rightarrowonoplus","plus.circle.arrow"],["rightarrowtail","arrow.r.tail"],["rightdasharrow","arrow.r.dashed"],["rightdotarrow","arrow.r.dotted"],["rightdowncurvedarrow","arrow.r.curve"],["rightharpoondown","harpoon.rb"],["rightharpoondownbar","harpoon.rb.stop"],["rightharpoonsupdown","harpoons.rtrb"],["rightharpoonup","harpoon.rt"],["rightharpoonupbar","harpoon.rt.stop"],["rightleftarrows","arrows.rl"],["rightleftharpoons","harpoons.rtlb"],["rightleftharpoonsdown","harpoons.rblb"],["rightleftharpoonsup","harpoons.rtlt"],["rightouterjoin","join.r"],["rightrightarrows","arrows.rr"],["rightsquigarrow","arrow.r.squiggly"],["rightthreearrows","arrows.rrr"],["rightthreetimes","times.three.r"],["rightwavearrow","arrow.r.wave"],["rightwhitearrow","arrow.r.stroked"],["risingdotseq","eq.dots.up"],["rparen","paren.r"],["rParen","paren.r.double"],["RRightarrow","arrow.r.quad"],["Rrightarrow","arrow.r.triple"],["rsolbar","backslash.not"],["rtimes","times.r"],["rvzigzag","fence.r"],["Rvzigzag","fence.r.double"],["searrow","arrow.br"],["Searrow","arrow.br.double"],["setminus","without"],["sharp","sharp"],["shortdowntack","tack.b.short"],["shortlefttack","tack.l.short"],["shortuptack","tack.t.short"],["sim","tilde.op"],["sime","tilde.eq"],["similarleftarrow","arrow.l.tilde"],["similarrightarrow","arrow.r.tilde"],["simneqq","tilde.nequiv"],["smallblacktriangleleft","triangle.filled.small.l"],["smallblacktriangleright","triangle.filled.small.r"],["smallin","in.small"],["smallni","in.rev.small"],["smalltriangleleft","triangle.stroked.small.l"],["smalltriangleright","triangle.stroked.small.r"],["smashtimes","smash"],["smblkcircle","bullet"],["smblkdiamond","diamond.filled.small"],["smblklozenge","lozenge.filled.small"],["smblksquare","square.filled.tiny"],["smeparsl","parallel.slanted.eq.tilde"],["smt","smt"],["smte","smt.eq"],["smwhtdiamond","diamond.stroked.small"],["smwhtlozenge","lozenge.stroked.small"],["smwhtsquare","square.stroked.tiny"],["spadesuit","suit.spade.filled"],["sphericalangle","angle.spheric"],["sphericalangleup","angle.spheric.top"],["sqcap","inter.sq"],["Sqcap","inter.sq.double"],["sqcup","union.sq"],["Sqcup","union.sq.double"],["sqint","integral.square"],["sqsubset","subset.sq"],["sqsubseteq","subset.eq.sq"],["sqsubsetneq","subset.sq.neq"],["sqsupset","supset.sq"],["sqsupseteq","supset.eq.sq"],["sqsupsetneq","supset.sq.neq"],["squoval","square.stroked.rounded"],["sslash","slash.double"],["star","star.op"],["stareq","eq.star"],["subset","subset"],["Subset","subset.double"],["subsetdot","subset.dot"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["Succ","succ.double"],["succapprox","succ.approx"],["succcurlyeq","succ.curly.eq"],["succeq","succ.eq"],["succeqq","succ.equiv"],["succnapprox","succ.napprox"],["succneq","succ.neq"],["succneqq","succ.nequiv"],["succnsim","succ.ntilde"],["succsim","succ.tilde"],["sum","sum"],["sumint","sum.integral"],["supset","supset"],["Supset","supset.double"],["supsetdot","supset.dot"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["swarrow","arrow.bl"],["Swarrow","arrow.bl.double"],["therefore","therefore"],["threedangle","angle.spatial"],["threedotcolon","colon.tri.op"],["tieinfty","infinity.tie"],["times","times"],["tminus","miny"],["top","tack.b"],["tplus","tiny"],["trianglecdot","triangle.stroked.dot"],["triangledown","triangle.stroked.small.b"],["triangleleft","triangle.stroked.l"],["trianglelefteq","lt.tri.eq"],["triangleminus","minus.triangle"],["triangleplus","plus.triangle"],["triangleq","eq.delta"],["triangleright","triangle.stroked.r"],["trianglerighteq","gt.tri.eq"],["triangletimes","times.triangle"],["tripleplus","plus.triple"],["trprime","prime.triple"],["trslash","slash.triple"],["twoheaddownarrow","arrow.b.twohead"],["twoheadleftarrow","arrow.l.twohead"],["twoheadmapsfrom","arrow.l.twohead.bar"],["twoheadmapsto","arrow.r.twohead.bar"],["twoheadrightarrow","arrow.r.twohead"],["twoheaduparrow","arrow.t.twohead"],["twonotes","note.eighth.beamed"],["ubrbrak","shell.b"],["ulblacktriangle","triangle.filled.tl"],["ultriangle","triangle.stroked.tl"],["uminus","union.minus"],["underbrace","brace.b"],["underbracket","bracket.b"],["underparen","paren.b"],["unicodecdots","dots.h.c"],["unicodeellipsis","dots.h"],["upand","amp.inv"],["uparrow","arrow.t"],["Uparrow","arrow.t.double"],["updasharrow","arrow.t.dashed"],["updownarrow","arrow.t.b"],["Updownarrow","arrow.t.b.double"],["updownarrows","arrows.tb"],["updownharpoonleftleft","harpoon.tl.bl"],["updownharpoonleftright","harpoon.tl.br"],["updownharpoonrightleft","harpoon.tr.bl"],["updownharpoonrightright","harpoon.tr.br"],["updownharpoonsleftright","harpoons.tlbr"],["upharpoonleft","harpoon.tl"],["upharpoonleftbar","harpoon.tl.bar"],["upharpoonright","harpoon.tr"],["upharpoonrightbar","harpoon.tr.bar"],["upharpoonsleftright","harpoons.tltr"],["uplus","union.plus"],["uprightcurvearrow","arrow.t.curve"],["upuparrows","arrows.tt"],["upwhitearrow","arrow.t.stroked"],["urblacktriangle","triangle.filled.tr"],["urtriangle","triangle.stroked.tr"],["UUparrow","arrow.t.quad"],["Uuparrow","arrow.t.triple"],["varclubsuit","suit.club.stroked"],["vardiamondsuit","suit.diamond.filled"],["varheartsuit","suit.heart.filled"],["varhexagon","hexa.stroked"],["varhexagonblack","hexa.filled"],["varnothing","emptyset"],["varointclockwise","integral.cont.cw"],["varspadesuit","suit.spade.stroked"],["vartriangle","triangle.stroked.small.t"],["vartriangleleft","lt.tri"],["vartriangleright","gt.tri"],["Vbar","tack.t.double"],["Vdash","forces"],["vdash","tack.r"],["vDash","tack.r.double"],["vdots","dots.v"],["vee","or"],["Vee","or.double"],["veedot","or.dot"],["veeeq","eq.equi"],["vert","bar.v"],["Vert","bar.v.double"],["vlongdash","tack.r.long"],["vrectangle","rect.stroked.v"],["vrectangleblack","rect.filled.v"],["Vvert","bar.v.triple"],["vysmblkcircle","circle.filled.small"],["vysmwhtcircle","circle.stroked.tiny"],["wedge","and"],["Wedge","and.double"],["wedgedot","and.dot"],["wedgeq","eq.est"],["whiteinwhitetriangle","triangle.stroked.nested"],["whthorzoval","ellipse.stroked.h"],["whtvertoval","ellipse.stroked.v"],["wideangledown","angle.oblique"],["wr","wreath"],["xsol","slash.big"]]),wt=new Map([["gets","leftarrow"],["iff","Longleftrightarrow"],["implies","Longrightarrow"]]);for(let[n,e]of Tt)x.has(n)||x.set(n,e);var $=new Map;for(let[n,e]of Array.from(x.entries()).reverse())$.set(e,n);$.set("oo","infty");var mt=new Map([["top","top"],["frac","frac"],["tilde","tilde"],["hat","hat"],["upright","mathrm"],["bold","boldsymbol"],["infinity","infty"]]);for(let[n,e]of mt)$.set(n,e);for(let[n,e]of wt)x.has(n)||x.set(n,x.get(e));var G=class extends Error{node;constructor(e,t=null){super(e),this.name="ConverterError",this.node=t}},bt=i.NONE.toNode(),ft=["dim","id","im","mod","Pr","sech","csch"];function yt(n){if(/^[a-zA-Z0-9]$/.test(n))return n;if(n==="/")return"\\/";if(["\\\\","\\{","\\}","\\%"].includes(n))return n.substring(1);if(["\\$","\\#","\\&","\\_"].includes(n))return n;if(n.startsWith("\\")){let e=n.slice(1);return x.has(e)?x.get(e):null}return n}function F(n,e){let t;switch(n.type){case 0:return i.NONE;case 2:t=1;break;case 1:t=2;break;case 3:t=3;break;case 4:t=5;break;case 5:t=6;break;case 6:t=8;break;case 7:{if(n.value==="\\\\")return new i(7,"\\");if(n.value==="\\!")return new i(1,"#h(-math.thin.amount)");if(x.has(n.value.substring(1))){let s=x.get(n.value.substring(1));return new i(1,s)}else throw new Error(`Unknown control sequence: ${n.value}`)}default:throw Error(`Unknown token type: ${n.type}`)}let r=yt(n.value);if(r===null){if(e.nonStrict)return new i(t,n.value.substring(1));throw new G(`Unknown token: ${n.value}`,n)}return new i(t,r)}function Et(n,e){let[t,r]=n.args;if(e.optimize&&["\\overset{\\text{def}}{=}","\\overset{d e f}{=}"].includes(n.toString()))return new i(1,"eq.def").toNode();let s=new y(new i(1,"limits"),[b(r,e)]);return new S({base:s,sup:b(t,e),sub:null})}function xt(n,e){let[t,r]=n.args,s=new y(new i(1,"limits"),[b(r,e)]);return new S({base:s,sub:b(t,e),sup:null})}function Nt(n){let e={},t={l:"#left",c:"#center",r:"#right"},r=Array.from(n),s=[],o=0;for(let u of r)u==="|"?s.push(o):(u==="l"||u==="c"||u==="r")&&o++;if(s.length>0){let u;s.length===1?u=`#${s[0]}`:u=`#(vline: (${s.join(", ")}))`,e.augment=new i(3,u).toNode()}let a=r.map(u=>t[u]).filter(u=>u!==void 0).map(u=>new i(3,u).toNode());if(a.length>0){let u=a.every(p=>p.eq(a[0]));e.align=u?a[0]:new i(3,"#center").toNode()}return e}function b(n,e={}){switch(n.type){case"terminal":return F(n.head,e).toNode();case"text":{let r=n;return/[^\x00-\x7F]+/.test(r.head.value)&&e.nonAsciiWrapper!==""?new y(new i(1,e.nonAsciiWrapper),[new i(4,r.head.value).toNode()]):new i(4,r.head.value).toNode()}case"ordgroup":let t=n;return new N(t.items.map(r=>b(r,e)));case"supsub":{let r=n,{base:s,sup:o,sub:a}=r;if(s&&s.type==="funcCall"&&s.head.value==="\\overbrace"&&o)return new y(new i(1,"overbrace"),[b(s.args[0],e),b(o,e)]);if(s&&s.type==="funcCall"&&s.head.value==="\\underbrace"&&a)return new y(new i(1,"underbrace"),[b(s.args[0],e),b(a,e)]);let u={base:b(s,e),sup:o?b(o,e):null,sub:a?b(a,e):null};return new S(u)}case"leftright":{let r=n,{left:s,right:o}=r,a=b(r.body,e);if(e.optimize&&s!==null&&o!==null){let h=F(s,e),d=F(o,e);if(s.value==="\\|"&&o.value==="\\|")return new y(new i(1,"norm"),[a]);if(["[]","()","\\{\\}","\\lfloor\\rfloor","\\lceil\\rceil","\\lfloor\\rceil"].includes(s.value+o.value))return new N([h.toNode(),a,d.toNode()])}let u=function(h){return["(",")","{","["].includes(h.value)?new i(2,"\\"+h.value):h},p=s?F(s,e):null,c=o?F(o,e):null;return p===null&&c!==null&&(c=u(c)),c===null&&p!==null&&(p=u(p)),new A(new i(1,"lr"),{body:a,left:p,right:c})}case"funcCall":{let r=n,s=b(r.args[0],e);if(r.head.value==="\\sqrt"&&r.data){let o=b(r.data,e);return new y(new i(1,"root"),[o,s])}if(r.head.value==="\\mathbf"){let o=new y(new i(1,"bold"),[s]);return new y(new i(1,"upright"),[o])}if(r.head.value==="\\overrightarrow")return new y(new i(1,"arrow"),[s]);if(r.head.value==="\\overleftarrow")return new y(new i(1,"accent"),[s,new i(1,"arrow.l").toNode()]);if(r.head.value==="\\operatorname")return e.optimize&&ft.includes(s.head.value)?new i(1,s.head.value).toNode():new y(new i(1,"op"),[new i(4,s.head.value).toNode()]);if(r.head.value==="\\textcolor"){let o=new Y(new i(1,"#text"),[b(r.args[1],e)]);return o.setOptions({fill:s}),o}if(r.head.value==="\\substack")return s;if(r.head.value==="\\overset")return Et(r,e);if(r.head.value==="\\underset")return xt(r,e);if(r.head.value==="\\frac"&&e.fracToSlash)return new z(r.args.map(o=>b(o,e)));if(e.optimize){if(r.head.value==="\\mathbb"&&/^\\mathbb{[A-Z]}$/.test(r.toString()))return new i(1,s.head.value.repeat(2)).toNode();if(r.head.value==="\\mathrm"&&r.toString()==="\\mathrm{d}")return new i(1,"dif").toNode()}return new y(F(r.head,e),r.args.map(o=>b(o,e)))}case"beginend":{let r=n,s=r.matrix.map(o=>o.map(a=>b(a,e)));if(r.head.value.startsWith("align"))return new f(null,s);if(r.head.value==="cases")return new f(f.CASES,s);if(r.head.value==="subarray"){if(r.data)switch(r.data.head.value){case"r":s.forEach(a=>a.push(i.EMPTY.toNode()));break;case"l":s.forEach(a=>a.unshift(i.EMPTY.toNode()));break;default:break}return new f(null,s)}if(r.head.value==="array"){let o={delim:bt};g(r.data!==null&&r.head.type===3);let a=Nt(r.data.head.value);Object.assign(o,a);let u=new f(f.MAT,s);return u.setOptions(o),u}if(r.head.value.endsWith("matrix")){let o=new f(f.MAT,s),a;switch(r.head.value){case"matrix":a=i.NONE;break;case"pmatrix":return o;case"bmatrix":a=new i(4,"[");break;case"Bmatrix":a=new i(4,"{");break;case"vmatrix":a=new i(4,"|");break;case"Vmatrix":{a=new i(1,"bar.v.double");break}default:throw new G(`Unimplemented beginend: ${r.head}`,r)}return o.setOptions({delim:a.toNode()}),o}throw new G(`Unimplemented beginend: ${r.head}`,r)}default:throw new G(`Unimplemented node type: ${n.type}`,n)}}function P(n){switch(n.type){case 0:return l.EMPTY;case 1:{let e=function(t){return $.has(t)?"\\"+$.get(t):"\\"+t};return new l(2,e(n.value))}case 2:{let e;return["{","}","%"].includes(n.value)?e="\\"+n.value:e=n.value,new l(1,e)}case 3:return new l(3,n.value);case 4:return new l(3,n.value);case 5:return new l(4,n.value);case 6:return new l(5,n.value);case 7:{let e;switch(n.value){case"\\":e="\\\\";break;case"&":e="&";break;default:throw new Error(`[typst_token_to_tex]Unimplemented control sequence: ${n.value}`)}return new l(7,e)}case 8:return new l(6,n.value);default:throw new Error(`Unimplemented token type: ${n.type}`)}}var qt=new l(1,",").toNode();function m(n){switch(n.type){case"terminal":{let e=n;if(e.head.type===1){if(e.head.value==="eq.def")return new T(new l(2,"\\overset"),[new O(new l(3,"def")),new l(1,"=").toNode()]);if(e.head.value==="comma")return new l(1,",").toNode();if(e.head.value==="dif")return new T(new l(2,"\\mathrm"),[new l(1,"d").toNode()]);if(e.head.value==="hyph"||e.head.value==="hyph.minus")return new O(new l(3,"-"));if(/^([A-Z])\1$/.test(e.head.value))return new T(new l(2,"\\mathbb"),[new l(1,e.head.value[0]).toNode()])}return e.head.type===4?new O(new l(3,e.head.value)):P(e.head).toNode()}case"group":{let t=n.items.map(m),r=new l(7,"&").toNode(),s=new l(7,"\\\\").toNode();if(ne(t,r)){let o=ye(t,s),a=[];for(let u of o){let p=ye(u,r);a.push(p.map(c=>new E(c)))}return new M(new l(3,"aligned"),a)}return new E(t)}case"leftright":{let e=n,t=m(e.body),r=e.left?P(e.left):new l(1,"."),s=e.right?P(e.right):new l(1,".");return e.isOverHigh()&&(r.value="\\left"+r.value,s.value="\\right"+s.value),new E([r.toNode(),t,s.toNode()])}case"funcCall":{let e=n;switch(e.head.value){case"norm":{let t=e.args[0],r=m(t);return e.isOverHigh()?new B({body:r,left:new l(2,"\\|"),right:new l(2,"\\|")}):r}case"floor":case"ceil":{let t="\\l"+e.head.value,r="\\r"+e.head.value,s=e.args[0],o=m(s),a=new l(2,t),u=new l(2,r);return e.isOverHigh()?new B({body:o,left:a,right:u}):new E([a.toNode(),o,u.toNode()])}case"root":{let[t,r]=e.args,s=m(t);return new T(new l(2,"\\sqrt"),[m(r)],s)}case"overbrace":case"underbrace":{let[t,r]=e.args,s=new T(P(e.head),[m(t)]),o=m(r),a=e.head.value==="overbrace"?{base:s,sup:o,sub:null}:{base:s,sub:o,sup:null};return new I(a)}case"vec":{let t=e.args.map(m).map(r=>[r]);return new M(new l(3,"pmatrix"),t)}case"op":{let t=e.args[0];return g(t.head.type===4),new T(P(e.head),[new l(3,t.head.value).toNode()])}default:{let t=P(e.head),r=j.includes(t.value.substring(1))||V.includes(t.value.substring(1));return t.value.length>0&&r?new T(t,e.args.map(m)):new E([P(e.head).toNode(),new l(1,"(").toNode(),...Pe(e.args.map(m),qt),new l(1,")").toNode()])}}}case"markupFunc":{let e=n;switch(e.head.value){case"#text":if(e.options&&e.options.fill){let t=e.options.fill;return new T(new l(2,"\\textcolor"),[m(t),m(e.fragments[0])])}case"#heading":default:throw new Error(`Unimplemented markup function: ${e.head.value}`)}}case"supsub":{let e=n,{base:t,sup:r,sub:s}=e,o=r?m(r):null,a=s?m(s):null;if(t.head.eq(new i(1,"limits"))){let h=m(t.args[0]);if(o!==null&&a===null)return new T(new l(2,"\\overset"),[o,h]);if(o===null&&a!==null)return new T(new l(2,"\\underset"),[a,h]);{let d=new T(new l(2,"\\underset"),[a,h]);return new T(new l(2,"\\overset"),[o,d])}}let u=m(t);return new I({base:u,sup:o,sub:a})}case"matrixLike":{let e=n,t=e.matrix.map(r=>r.map(m));if(e.head.eq(f.MAT)){let r="pmatrix";if(e.options&&"delim"in e.options){let s=e.options.delim;switch(s.head.value){case"#none":r="matrix";break;case"[":case"]":r="bmatrix";break;case"(":case")":r="pmatrix";break;case"{":case"}":r="Bmatrix";break;case"|":r="vmatrix";break;case"bar":case"bar.v":r="vmatrix";break;case"bar.v.double":r="Vmatrix";break;default:throw new Error(`Unexpected delimiter ${s.head}`)}}return new M(new l(3,r),t)}else{if(e.head.eq(f.CASES))return new M(new l(3,"cases"),t);throw new Error(`Unexpected matrix type ${e.head}`)}}case"fraction":{let e=n,[t,r]=e.args,s=m(t),o=m(r);return new T(new l(2,"\\frac"),[s,o])}default:throw new Error("[convert_typst_node_to_tex] Unimplemented type: "+n.type)}}var vt=Array.from(le.keys());function _t(){return`(${vt.map(e=>(e=e.replaceAll("|","\\|"),e=e.replaceAll(".","\\."),e=e.replaceAll("[","\\["),e=e.replaceAll("]","\\]"),e)).join("|")})`}var Lt=_t(),Mt=new Map([[String.raw`//[^\n]*`,n=>new i(5,n.text().substring(2))],[String.raw`/`,n=>new i(2,n.text())],[String.raw`[_^&]`,n=>new i(7,n.text())],[String.raw`\r?\n`,n=>new i(8,`
|
|
1
|
+
"use strict";(()=>{function Re(n){return"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".includes(n)}function T(n,e="Assertion failed."){if(!n)throw new Error(e)}var l=class n{type;value;constructor(e,r){this.type=e,this.value=r}eq(e){return this.type===e.type&&this.value===e.value}toString(){switch(this.type){case 4:return"%"+this.value;default:return this.value}}toNode(){return new we(this)}static EMPTY=new n(0,"")},k=class{type;head;constructor(e,r){this.type=e,this.head=r||l.EMPTY}eq(e){return this.type===e.type&&this.head.eq(e.head)}toString(){return this.serialize().reduce(be,"")}},we=class extends k{constructor(e){super("terminal",e)}serialize(){switch(this.head.type){case 0:return[];case 1:case 2:case 3:case 4:case 7:return[this.head];case 5:case 6:{let e=[];for(let r of this.head.value){let t=r===" "?5:6;e.push(new l(t,r))}return e}default:throw new Error(`Unknown terminal token type: ${this.head.type}`)}}},S=class extends k{constructor(e){T(e.type===3),super("text",e)}serialize(){return[new l(2,"\\text"),new l(1,"{"),this.head,new l(1,"}")]}},E=class extends k{items;constructor(e){super("ordgroup",l.EMPTY),this.items=e}serialize(){return this.items.map(e=>e.serialize()).flat()}},R=class extends k{base;sup;sub;constructor(e){super("supsub",l.EMPTY),this.base=e.base,this.sup=e.sup,this.sub=e.sub}serialize(){let e=[],{base:r,sup:t,sub:s}=this;e=e.concat(r.serialize());function o(a){return a.type==="ordgroup"||a.type==="supsub"||a.head.type===0?!0:!!(a.head.type===1&&/\d+(\.\d+)?/.test(a.head.value)&&a.head.value.length>1)}return s&&(e.push(new l(7,"_")),o(s)?(e.push(new l(1,"{")),e=e.concat(s.serialize()),e.push(new l(1,"}"))):e=e.concat(s.serialize())),t&&(e.push(new l(7,"^")),o(t)?(e.push(new l(1,"{")),e=e.concat(t.serialize()),e.push(new l(1,"}"))):e=e.concat(t.serialize())),e}},g=class extends k{args;data;constructor(e,r,t=null){super("funcCall",e),this.args=r,this.data=t}serialize(){let e=[];e.push(this.head),this.head.value==="\\sqrt"&&this.data&&(e.push(new l(1,"[")),e=e.concat(this.data.serialize()),e.push(new l(1,"]")));for(let r of this.args)e.push(new l(1,"{")),e=e.concat(r.serialize()),e.push(new l(1,"}"));return e}},I=class extends k{body;left;right;constructor(e){super("leftright",l.EMPTY),this.body=e.body,this.left=e.left,this.right=e.right}serialize(){let e=[];return e.push(new l(2,"\\left")),e.push(new l(1,this.left?this.left.value:".")),e=e.concat(this.body.serialize()),e.push(new l(2,"\\right")),e.push(new l(1,this.right?this.right.value:".")),e}},M=class extends k{matrix;data;constructor(e,r,t=null){T(e.type===3),super("beginend",e),this.matrix=r,this.data=t}serialize(){let e=[],r=this.matrix;e.push(new l(2,"\\begin")),e.push(new l(1,"{")),e=e.concat(this.head),e.push(new l(1,"}")),e.push(new l(6,`
|
|
2
|
+
`));for(let t=0;t<r.length;t++){let s=r[t];for(let o=0;o<s.length;o++){let a=s[o];e=e.concat(a.serialize()),o!==s.length-1&&e.push(new l(7,"&"))}t!==r.length-1&&e.push(new l(7,"\\\\"))}return e.push(new l(6,`
|
|
3
|
+
`)),e.push(new l(2,"\\end")),e.push(new l(1,"{")),e=e.concat(this.head),e.push(new l(1,"}")),e}};function be(n,e){let r=e.toString(),t=!1;return e.type===5?t=!0:(t||=/[{\(\[\|]$/.test(n),t||=/\\\w+$/.test(n)&&r==="[",t||=/^[\.,;:!\?\(\)\]{}_^]$/.test(r),t||=["\\{","\\}"].includes(r),t||=r==="'",t||=n.endsWith("_")||n.endsWith("^"),t||=/\s$/.test(n),t||=/^\s/.test(r),t||=n==="",t||=/[\(\[{]\s*(-|\+)$/.test(n)||n==="-"||n==="+",t||=n.endsWith("&")&&r==="=",t||=/\d$/.test(n)&&/^[a-zA-Z]$/.test(r)),t||(n+=" "),n+r}function G(n,e,r=0){let t=n.slice(r).findIndex(s=>s.eq(e));return t===-1?-1:t+r}function re(n,e){return n.some(r=>r.eq(e))}function me(n,e){let r=[],t=[];for(let s of n)s.eq(e)?(r.push(t),t=[]):t.push(s);return r.push(t),r}function Ie(n,e){return n.flatMap((r,t)=>t!==n.length-1?[r,e]:[r])}var Pe={};function et(n,e){let r=n.reMatchArray[0].length,t=e.reMatchArray[0].length;return t!==r?t-r:n.index-e.index}var fe=class{_input;_lexer;_pos=0;_line=0;_col=0;_offset=0;_less=null;_go=!1;_newstate=null;_state;_text=null;_leng=null;_reMatchArray=null;constructor(e,r){this._input=e,this._lexer=r,this._state=r.states[0]}text(){return this._text}leng(){return this._leng}reMatchArray(){return this._reMatchArray}pos(){return this._pos}line(){return this._line}column(){return this._col}input(){return this._input.charAt(this._pos+this._leng+this._offset++)}unput(){return this._offset=this._offset>0?this._offset--:0}less(e){return this._less=e,this._offset=0,this._text=this._text.substring(0,e),this._leng=this._text.length}pushback(e){return this.less(this._leng-e)}reject(){this._go=!0}begin(e){if(this._lexer.specification[e])return this._newstate=e;let r=this._lexer.states[parseInt(e)];if(r)return this._newstate=r;throw"Unknown state '"+e+"' requested"}state(){return this._state}scan(){if(this._pos>=this._input.length)return Pe;let e=this._input.substring(this._pos),r=this._lexer.specification[this._state],t=[];for(let c=0;c<r.length;c++){let h=r[c],d=e.match(h.re);d!==null&&d[0].length>0&&t.push({index:c,rule:h,reMatchArray:d})}if(t.length===0)throw new Error("No match found for input '"+e+"'");t.sort(et),this._go=!0;let s,o;for(let c=0,h=t.length;c<h&&this._go;c++){this._offset=0,this._less=null,this._go=!1,this._newstate=null;let d=t[c];if(o=d.reMatchArray[0],this._text=o,this._leng=o.length,this._reMatchArray=d.reMatchArray,s=d.rule.action(this),this._newstate&&this._newstate!=this._state){this._state=this._newstate;break}}let a=this._less===null?o:o.substring(0,this._less),u=a.length;this._pos+=u+this._offset;let p=a.match(/\n/g);return p!==null?(this._line+=p.length,this._col=u-a.lastIndexOf(`
|
|
4
|
+
`)-1):this._col+=u,s}},B=class{states;specification;constructor(e){this.states=Object.keys(e),this.specification={};for(let r of this.states){let t=e[r];if(r in this.specification)throw"Duplicate state declaration encountered for state '"+r+"'";this.specification[r]=[];for(let[s,o]of t.entries()){let a;try{a=new RegExp("^"+s)}catch(u){throw"Invalid regexp '"+s+"' in state '"+r+"' ("+u.message+")"}this.specification[r].push({re:a,action:o})}}}scanner(e){return new fe(e,this)}lex(e,r){let t=this.scanner(e);for(;;){let s=t.scan();if(s===Pe)return;s!==void 0&&r(s)}}collect(e){let r=[],t=function(s){Array.isArray(s)?r.push(...s):r.push(s)};return this.lex(e,t),r}};var H=["sqrt","text","bar","bold","boldsymbol","ddot","dot","hat","mathbb","mathbf","mathcal","mathfrak","mathit","mathrm","mathscr","mathsf","mathtt","operatorname","overbrace","overline","pmb","rm","tilde","underbrace","underline","vec","widehat","widetilde","overleftarrow","overrightarrow","hspace","substack","set"],X=["frac","tfrac","binom","dbinom","dfrac","tbinom","overset","underset","textcolor"];function tt(n){let e=["{","}","\\","$","&","#","_","%"];for(let r of e)n=n.replaceAll("\\"+r,r);return n}var rt=new Map([[String.raw`\\begin{(array|subarry)}{(.+?)}`,n=>{let e=n.reMatchArray();return[new l(2,"\\begin"),new l(7,"{"),new l(3,e[1]),new l(7,"}"),new l(7,"{"),new l(3,e[2]),new l(7,"}")]}],[String.raw`\\(text|operatorname|textcolor|begin|end|hspace|array){(.+?)}`,n=>{let e=n.reMatchArray();return[new l(2,"\\"+e[1]),new l(7,"{"),new l(3,tt(e[2])),new l(7,"}")]}],[String.raw`%[^\n]*`,n=>new l(4,n.text().substring(1))],[String.raw`[{}_^&]`,n=>new l(7,n.text())],[String.raw`\\[\\,:;! ]`,n=>new l(7,n.text())],[String.raw`\r?\n`,n=>new l(6,`
|
|
5
|
+
`)],[String.raw`\s+`,n=>new l(5,n.text())],[String.raw`\\[{}%$&#_|]`,n=>new l(1,n.text())],[String.raw`(\\[a-zA-Z]+)(\s*\d|\s+[a-zA-Z])\s*([0-9a-zA-Z])`,n=>{let e=n.reMatchArray(),r=e[1];if(X.includes(r.substring(1))){let t=e[2].trimStart(),s=e[3];return[new l(2,r),new l(1,t),new l(1,s)]}else return n.reject(),[]}],[String.raw`(\\[a-zA-Z]+)(\s*\d|\s+[a-zA-Z])`,n=>{let e=n.reMatchArray(),r=e[1];if(H.includes(r.substring(1))){let t=e[2].trimStart();return[new l(2,r),new l(1,t)]}else return n.reject(),[]}],[String.raw`\\[a-zA-Z]+`,n=>new l(2,n.text())],[String.raw`[0-9]+(\.[0-9]+)?`,n=>new l(1,n.text())],[String.raw`[a-zA-Z]`,n=>new l(1,n.text())],[String.raw`[+\-*/='<>!.,;:?()\[\]|]`,n=>new l(1,n.text())],[String.raw`[^\x00-\x7F]`,n=>new l(1,n.text())],[String.raw`.`,n=>new l(8,n.text())]]),nt={start:rt};function ye(n){return new B(nt).collect(n)}var st=["bigl","bigr","bigm","biggl","biggr","biggm","Bigl","Bigr","Bigm","Biggl","Biggr","Biggm"],De=l.EMPTY.toNode();function ot(n){return H.includes(n)?1:X.includes(n)?2:0}var ne=new l(7,"{"),se=new l(7,"}"),ze=new l(1,"["),at=new l(1,"]");function oe(n,e){let r=e;for(;r<n.length&&[5,6].includes(n[r].type);)r++;return n.slice(e,r)}function Ye(n,e){let r=n[e];return r.type===1&&["(",")","[","]","|","\\{","\\}",".","\\|"].includes(r.value)||r.type===2&&["lfloor","rfloor","lceil","rceil","langle","rangle"].includes(r.value.slice(1))?r:null}function j(n,e){let r=e;for(;r<n.length&&n[r].eq(new l(1,"'"));)r+=1;return r-e}function ae(n,e,r,t){T(n[e].eq(r));let s=1,o=e+1;for(;s>0;){if(o>=n.length)return-1;n[o].eq(r)?s+=1:n[o].eq(t)&&(s-=1),o+=1}return o-1}var Ee=new l(2,"\\left"),it=new l(2,"\\right");function lt(n,e){return ae(n,e,Ee,it)}var xe=new l(2,"\\begin"),ut=new l(2,"\\end");function pt(n,e){return ae(n,e,xe,ut)}var w=class extends Error{constructor(e){super(e),this.name="LatexParserError"}},Ne=new l(7,"_"),qe=new l(7,"^"),ve=class{space_sensitive;newline_sensitive;constructor(e=!1,r=!0){this.space_sensitive=e,this.newline_sensitive=r}parse(e){let r=new l(2,"\\displaystyle"),t=G(e,r);if(t===-1){let[s,o]=this.parseGroup(e,0,e.length);return s}else if(t===0){let[s,o]=this.parseGroup(e,1,e.length);return new g(r,[s])}else{let[s,o]=this.parseGroup(e,0,t),[a,u]=this.parseGroup(e,t+1,e.length),p=new g(r,[a]);return new E([s,p])}}parseGroup(e,r,t){let s=[],o=r;for(;o<t;){let[u,p]=this.parseNextExpr(e,o);if(o=p,!((u.head.type===5||u.head.type===6)&&(!this.space_sensitive&&u.head.value.replace(/ /g,"").length===0||!this.newline_sensitive&&u.head.value===`
|
|
6
|
+
`))){if(u.head.eq(new l(7,"&")))throw new w("Unexpected & outside of an alignment");s.push(u)}}let a;return s.length===1?a=s[0]:a=new E(s),[a,t+1]}parseNextExpr(e,r){let[t,s]=this.parseNextExprWithoutSupSub(e,r),o=null,a=null,u=0;if(u+=j(e,s),s+=u,s<e.length&&e[s].eq(Ne)){if([o,s]=this.parseNextExprWithoutSupSub(e,s+1),u+=j(e,s),s+=u,s<e.length&&e[s].eq(qe)&&([a,s]=this.parseNextExprWithoutSupSub(e,s+1),j(e,s)>0))throw new w("Double superscript")}else if(s<e.length&&e[s].eq(qe)){if([a,s]=this.parseNextExprWithoutSupSub(e,s+1),j(e,s)>0)throw new w("Double superscript");if(s<e.length&&e[s].eq(Ne)&&([o,s]=this.parseNextExprWithoutSupSub(e,s+1),j(e,s)>0))throw new w("Double superscript")}if(o!==null||a!==null||u>0){let p={base:t,sup:null,sub:null};if(o&&(p.sub=o),u>0){let c=[];for(let h=0;h<u;h++)c.push(new l(1,"'").toNode());a&&c.push(a),p.sup=c.length===1?c[0]:new E(c)}else a&&(p.sup=a);return[new R(p),s]}else return[t,s]}parseNextExprWithoutSupSub(e,r){if(r>=e.length)return[De,r];let t=e[r];switch(t.type){case 1:case 3:case 4:case 5:case 6:return[t.toNode(),r+1];case 2:let s=t.value.slice(1);return st.includes(s)?this.parseNextExprWithoutSupSub(e,r+1):t.eq(xe)?this.parseBeginEndExpr(e,r):t.eq(Ee)?this.parseLeftRightExpr(e,r):this.parseCommandExpr(e,r);case 7:switch(t.value){case"{":let a=ae(e,r,ne,se);if(a===-1)throw new w("Unmatched '{'");return this.parseGroup(e,r+1,a);case"}":throw new w("Unmatched '}'");case"\\\\":case"\\!":case"\\,":case"\\:":case"\\;":return[t.toNode(),r+1];case"\\ ":return[t.toNode(),r+1];case"_":case"^":return[De,r];case"&":return[t.toNode(),r+1];default:throw new w("Unknown control sequence")}default:throw new w("Unknown token type")}}parseCommandExpr(e,r){T(e[r].type===2);let t=e[r],s=t.value,o=r+1;if(["left","right","begin","end"].includes(s.slice(1)))throw new w("Unexpected command: "+s);switch(ot(s.slice(1))){case 0:return[t.toNode(),o];case 1:{if(o>=e.length)throw new w("Expecting argument for "+s);if(s==="\\sqrt"&&o<e.length&&e[o].eq(ze)){let c=o,h=ae(e,o,ze,at);if(h===-1)throw new w("No matching right square bracket for [");let[d,v]=this.parseGroup(e,c+1,h),[C,O]=this.parseNextArg(e,h+1);return[new g(t,[C],d),O]}else if(s==="\\text"){if(o+2>=e.length)throw new w("Expecting content for \\text command");T(e[o].eq(ne)),T(e[o+1].type===3),T(e[o+2].eq(se));let c=e[o+1];return[new S(c),o+3]}let[u,p]=this.parseNextArg(e,o);return[new g(t,[u]),p]}case 2:{let[u,p]=this.parseNextArg(e,o),[c,h]=this.parseNextArg(e,p);return[new g(t,[u,c]),h]}default:throw new Error("Invalid number of parameters")}}parseNextArg(e,r){let t=r,s=null;for(;t<e.length;){let o;if([o,t]=this.parseNextExprWithoutSupSub(e,t),!(o.head.type===5||o.head.type===6)){s=o;break}}if(s===null)throw new w("Expecting argument but token stream ended");return[s,t]}parseLeftRightExpr(e,r){T(e[r].eq(Ee));let t=r+1;if(t+=oe(e,t).length,t>=e.length)throw new w("Expecting delimiter after \\left");let s=Ye(e,t);if(s===null)throw new w("Invalid delimiter after \\left");t++;let o=t,a=lt(e,r);if(a===-1)throw new w("No matching \\right");let u=a;if(t=a+1,t+=oe(e,t).length,t>=e.length)throw new w("Expecting \\right after \\left");let p=Ye(e,t);if(p===null)throw new w("Invalid delimiter after \\right");t++;let[c,h]=this.parseGroup(e,o,u),d=s.value==="."?null:s,v=p.value==="."?null:p;return[new I({body:c,left:d,right:v}),t]}parseBeginEndExpr(e,r){T(e[r].eq(xe));let t=r+1;T(e[t].eq(ne)),T(e[t+1].type===3),T(e[t+2].eq(se));let s=e[t+1].value;t+=3;let o=null;["array","subarray"].includes(s)&&(t+=oe(e,t).length,[o,t]=this.parseNextArg(e,t)),t+=oe(e,t).length;let a=t,u=pt(e,r);if(u===-1)throw new w("No matching \\end");let p=u;if(t=u+1,T(e[t].eq(ne)),T(e[t+1].type===3),T(e[t+2].eq(se)),e[t+1].value!==s)throw new w("Mismatched \\begin and \\end environments");t+=3;let c=e.slice(a,p);for(;c.length>0&&[5,6].includes(c[c.length-1].type);)c.pop();let h=this.parseAligned(c);return[new M(new l(3,s),h,o),t]}parseAligned(e){let r=0,t=[],s=[];t.push(s);let o=new E([]);for(s.push(o);r<e.length;){let[a,u]=this.parseNextExpr(e,r);r=u,!((a.head.type===5||a.head.type===6)&&(!this.space_sensitive&&a.head.value.replace(/ /g,"").length===0||!this.newline_sensitive&&a.head.value===`
|
|
7
|
+
`))&&(a.head.eq(new l(7,"\\\\"))?(s=[],o=new E([]),s.push(o),t.push(s)):a.head.eq(new l(7,"&"))?(o=new E([]),s.push(o)):o.items.push(a))}return t}};function ct(n){let e=t=>t.eq(Ne)||t.eq(qe),r=[];for(let t=0;t<n.length;t++)n[t].type===5&&t+1<n.length&&e(n[t+1])||n[t].type===5&&t-1>=0&&e(n[t-1])||r.push(n[t]);return r}function ht(n,e){let r=[];for(let t of n)if(t.type===2&&e[t.value]){let s=ye(e[t.value]);r=r.concat(s)}else r.push(t);return r}function We(n,e){let r=new ve,t=ye(n);return t=ct(t),t=ht(t,e),r.parse(t)}var V=new Map([["arrow.l.r.double.long","<==>"],["arrow.l.r.long","<-->"],["arrow.r.bar","|->"],["arrow.r.double.bar","|=>"],["arrow.r.double.long","==>"],["arrow.r.long","-->"],["arrow.r.long.squiggly","~~>"],["arrow.r.tail",">->"],["arrow.r.twohead","->>"],["arrow.l.double.long","<=="],["arrow.l.long","<--"],["arrow.l.long.squiggly","<~~"],["arrow.l.tail","<-<"],["arrow.l.twohead","<<-"],["arrow.l.r","<->"],["arrow.l.r.double","<=>"],["colon.double.eq","::="],["dots.h","..."],["gt.triple",">>>"],["lt.triple","<<<"],["arrow.r","->"],["arrow.r.double","=>"],["arrow.r.squiggly","~>"],["arrow.l","<-"],["arrow.l.squiggly","<~"],["bar.v.double","||"],["bracket.l.double","[|"],["bracket.r.double","|]"],["colon.eq",":="],["eq.colon","=:"],["eq.not","!="],["gt.double",">>"],["gt.eq",">="],["lt.double","<<"],["lt.eq","<="],["ast.op","*"],["minus","-"],["tilde.op","~"]]),ie=new Map;for(let[n,e]of V.entries())e.length>1&&ie.set(e,n);var i=class n{type;value;constructor(e,r){this.type=e,this.value=r}eq(e){return this.type===e.type&&this.value===e.value}isOneOf(e){return re(e,this)}toNode(){return new K(this)}toString(){switch(this.type){case 4:return`"${this.value}"`;case 5:return`//${this.value}`;default:return this.value}}static NONE=new n(0,"#none");static EMPTY=new n(2,"");static LEFT_BRACE=new n(2,"{");static RIGHT_BRACE=new n(2,"}");static LEFT_DELIMITERS=[new n(2,"("),new n(2,"["),new n(2,"{"),new n(2,"|"),new n(1,"angle.l")];static RIGHT_DELIMITERS=[new n(2,")"),new n(2,"]"),new n(2,"}"),new n(2,"|"),new n(1,"angle.r")]},Le=class extends Error{node;constructor(e,r){super(e),this.name="TypstWriterError",this.node=r}},Z=new i(7," "),N=class{type;head;options;constructor(e,r){this.type=e,this.head=r||i.NONE}setOptions(e){this.options=e}eq(e){return this.type===e.type&&this.head.eq(e.head)}toString(){throw new Error("Unimplemented toString() in base class TypstNode")}},K=class extends N{constructor(e){super("terminal",e)}isOverHigh(){return!1}toString(){return this.head.toString()}serialize(e,r){if(this.head.type===2){if(this.head.value===","&&e.insideFunctionDepth>0)return[new i(1,"comma")]}else if(this.head.type===1){let t=this.head.value;return r.preferShorthands&&V.has(t)&&(t=V.get(t)),r.inftyToOo&&t==="infinity"&&(t="oo"),[new i(1,t)]}else if(this.head.type===6||this.head.type===8){let t=[];for(let s of this.head.value)if(s===" ")r.keepSpaces&&t.push(new i(6,s));else if(s===`
|
|
8
|
+
`)t.push(new i(1,s));else throw new Le(`Unexpected whitespace character: ${s}`,this);return t}return[this.head]}},_=class extends N{items;constructor(e){super("group",i.NONE),this.items=e}isOverHigh(){return this.items.some(e=>e.isOverHigh())}serialize(e,r){let t=this.items.flatMap(s=>s.serialize(e,r));return t.length>0&&t[0].eq(Z)&&t.shift(),t.length>0&&t[t.length-1].eq(Z)&&t.pop(),t}},A=class extends N{base;sup;sub;constructor(e){super("supsub",i.NONE),this.base=e.base,this.sup=e.sup,this.sub=e.sub}isOverHigh(){return this.base.isOverHigh()}serialize(e,r){let t=[],{base:s,sup:o,sub:a}=this;t.push(...s.serialize(e,r));let u=o&&o.head.eq(new i(2,"'"));return u&&t.push(new i(2,"'")),a&&(t.push(new i(2,"_")),t.push(...a.serialize(e,r))),o&&!u&&(t.push(new i(2,"^")),t.push(...o.serialize(e,r))),t.push(Z),t}},f=class extends N{args;constructor(e,r){super("funcCall",e),this.args=r}isOverHigh(){return this.head.value==="frac"?!0:this.args.some(e=>e.isOverHigh())}serialize(e,r){let t=[],s=this.head;t.push(s),e.insideFunctionDepth++,t.push(le);for(let o=0;o<this.args.length;o++)t.push(...this.args[o].serialize(e,r)),o<this.args.length-1&&t.push(new i(2,","));if(this.options)for(let[o,a]of Object.entries(this.options))t.push(new i(3,`, ${o}: ${a.toString()}`));return t.push(ue),e.insideFunctionDepth--,t}},D=class extends N{args;constructor(e){super("fraction",i.NONE),this.args=e}isOverHigh(){return!0}serialize(e,r){let t=[],[s,o]=this.args;return t.push(Z),t.push(...s.serialize(e,r)),t.push(new i(2,"/")),t.push(...o.serialize(e,r)),t.push(Z),t}},le=new i(2,"("),ue=new i(2,")"),q=class extends N{body;left;right;constructor(e,r){super("leftright",e),this.body=r.body,this.left=r.left,this.right=r.right}isOverHigh(){return this.body.isOverHigh()}serialize(e,r){let t=[],s=new i(1,"lr"),{left:o,right:a}=this;return this.head.eq(s)&&(t.push(s),t.push(le)),o&&t.push(o),t.push(...this.body.serialize(e,r)),a&&t.push(a),this.head.eq(s)&&t.push(ue),t}},y=class n extends N{matrix;constructor(e,r){super("matrixLike",e),this.matrix=r}isOverHigh(){return!0}serialize(e,r){let t=[],s,o;if(this.head.eq(n.MAT)?(s=new i(2,","),o=new i(2,";")):this.head.eq(n.CASES)?(s=new i(2,"&"),o=new i(2,",")):this.head.eq(i.NONE)&&(s=new i(2,"&"),o=new i(1,"\\")),!this.head.eq(i.NONE)&&(t.push(this.head),e.insideFunctionDepth++,t.push(le),this.options))for(let[a,u]of Object.entries(this.options))t.push(new i(3,`${a}: ${u.toString()}, `));return this.matrix.forEach((a,u)=>{a.forEach((p,c)=>{t.push(...p.serialize(e,r)),c<a.length-1?t.push(s):u<this.matrix.length-1&&t.push(o)})}),this.head.eq(i.NONE)||(t.push(ue),e.insideFunctionDepth--),t}static MAT=new i(1,"mat");static CASES=new i(1,"cases")},z=class extends N{fragments;constructor(e,r){super("markupFunc",e),this.fragments=r}isOverHigh(){return this.fragments.some(e=>e.isOverHigh())}serialize(e,r){let t=[];if(t.push(this.head),e.insideFunctionDepth++,t.push(le),this.options){let s=Object.entries(this.options);for(let o=0;o<s.length;o++){let[a,u]=s[o];t.push(new i(3,`${a}: ${u.toString()}`)),o<s.length-1&&t.push(new i(2,","))}}t.push(ue),t.push(new i(3,"["));for(let s of this.fragments)t.push(new i(3,"$")),t.push(...s.serialize(e,r)),t.push(new i(3,"$"));return t.push(new i(3,"]")),t}};var dt=new i(2,"("),Tt=new i(2,")"),gt=new i(2,","),Ue=new i(1,`
|
|
9
|
+
`),ke=new i(7," ");var pe=class{buffer="";queue=[];options;constructor(e){this.options=e}writeBuffer(e,r){let t=r.toString();if(t==="")return;let s=!1;s||=/[\(\[\|]$/.test(this.buffer)&&/^\w/.test(t),s||=/^[})\]\|]$/.test(t),s||=/[^=]$/.test(this.buffer)&&t==="(",s||=/^[_^,;!]$/.test(t),s||=t==="'",s||=/[\(\[{]\s*(-|\+)$/.test(this.buffer)||this.buffer==="-"||this.buffer==="+",s||=t.startsWith(`
|
|
10
|
+
`),s||=this.buffer==="",s||=/\s$/.test(this.buffer)||/^\s/.test(t),s||=this.buffer.endsWith("&")&&t==="=",s||=this.buffer.endsWith("/")||t==="/",s||=r.type===3,s||=/[\s_^{\(]$/.test(this.buffer),e!==null&&(s||=e.type===3),s||(this.buffer+=" "),this.buffer+=t}serialize(e){let r={insideFunctionDepth:0};this.queue.push(...e.serialize(r,this.options))}flushQueue(){let e=[];for(let t of this.queue)t.eq(ke)&&e.length>0&&e[e.length-1].eq(ke)||e.push(t);let r=new i(1,"");for(let t=0;t<e.length;t++)e[t].eq(ke)&&(t===0||t===e.length-1||e[t-1].type===6||e[t-1].isOneOf([dt,Ue])||e[t+1].isOneOf([Tt,gt,Ue]))&&(e[t]=r);e=e.filter(t=>!t.eq(r));for(let t=0;t<e.length;t++){let s=e[t],o=t===0?null:e[t-1];this.writeBuffer(o,s)}this.queue=[]}finalize(){this.flushQueue();let e=function(s){let o=s.replace(/floor\.l\s*(.*?)\s*floor\.r/g,"floor($1)");return o=o.replace(/floor\(\)/g,'floor("")'),o},r=function(s){let o=s.replace(/ceil\.l\s*(.*?)\s*ceil\.r/g,"ceil($1)");return o=o.replace(/ceil\(\)/g,'ceil("")'),o},t=function(s){let o=s.replace(/floor\.l\s*(.*?)\s*ceil\.r/g,"round($1)");return o=o.replace(/round\(\)/g,'round("")'),o};if(this.options.optimize){let s=[e,r,t];for(let o of s)this.buffer=o(this.buffer)}return this.buffer}};var x=new Map([["displaystyle","display"],["hspace","#h"],["|","bar.v.double"],[",","thin"],[":","med"],[" ","med"],[";","thick"],["ln","ln"],["log","log"],["cos","cos"],["sin","sin"],["tan","tan"],["cot","cot"],["sec","sec"],["csc","csc"],["mod","mod"],["omicron","omicron"],["Xi","Xi"],["Upsilon","Upsilon"],["lim","lim"],["binom","binom"],["tilde","tilde"],["hat","hat"],["sqrt","sqrt"],["nonumber",""],["vec","arrow"],["neq","eq.not"],["dot","dot"],["ddot","dot.double"],["doteq","dot(eq)"],["dots","dots.h"],["vdots","dots.v"],["ddots","dots.down"],["widehat","hat"],["widetilde","tilde"],["quad","quad"],["qquad","wide"],["overbrace","overbrace"],["underbrace","underbrace"],["overline","overline"],["underline","underline"],["bar","macron"],["dbinom","binom"],["tbinom","binom"],["dfrac","frac"],["tfrac","frac"],["operatorname","op"],["boldsymbol","bold"],["mathbb","bb"],["mathbf","bold"],["mathcal","cal"],["mathit","italic"],["mathfrak","frak"],["mathrm","upright"],["mathsf","sans"],["mathtt","mono"],["rm","upright"],["pmb","bold"],["leadsto","arrow.r.squiggly"],["P","pilcrow"],["S","section"],["aleph","alef"],["infin","infinity"],["Delta","Delta"],["Gamma","Gamma"],["Lambda","Lambda"],["Omega","Omega"],["Phi","Phi"],["Pi","Pi"],["Psi","Psi"],["Sigma","Sigma"],["Theta","Theta"],["alpha","alpha"],["beta","beta"],["bigcirc","circle.big"],["bullet","bullet"],["cdot","dot.op"],["cdots","dots.c"],["checkmark","checkmark"],["chi","chi"],["circ","circle.small"],["colon","colon"],["cong","tilde.equiv"],["coprod","product.co"],["copyright","copyright"],["cup","union"],["curlyvee","or.curly"],["curlywedge","and.curly"],["dagger","dagger"],["dashv","tack.l"],["ddagger","dagger.double"],["delta","delta"],["ddots","dots.down"],["diamond","diamond"],["div","div"],["divideontimes","times.div"],["dotplus","plus.dot"],["ell","ell"],["emptyset","nothing"],["epsilon","epsilon.alt"],["equiv","equiv"],["eta","eta"],["exists","exists"],["forall","forall"],["gamma","gamma"],["ge","gt.eq"],["geq","gt.eq"],["geqslant","gt.eq.slant"],["gg","gt.double"],["hbar","planck.reduce"],["imath","dotless.i"],["iiiint","integral.quad"],["iiint","integral.triple"],["iint","integral.double"],["in","in"],["infty","infinity"],["int","integral"],["intercal","top"],["iota","iota"],["jmath","dotless.j"],["kappa","kappa"],["lambda","lambda"],["land","and"],["langle","angle.l"],["lbrace","brace.l"],["lbrack","bracket.l"],["ldots","dots.h"],["le","lt.eq"],["leftthreetimes","times.three.l"],["leftrightarrow","arrow.l.r"],["leq","lt.eq"],["leqslant","lt.eq.slant"],["lhd","triangle.l"],["ll","lt.double"],["lor","or"],["ltimes","times.l"],["measuredangle","angle.arc"],["mid","divides"],["models","models"],["mp","minus.plus"],["mu","mu"],["nabla","nabla"],["ncong","tilde.equiv.not"],["ne","eq.not"],["neg","not"],["neq","eq.not"],["nexists","exists.not"],["ni","in.rev"],["nleftarrow","arrow.l.not"],["nleq","lt.eq.not"],["nparallel","parallel.not"],["ngeq","gt.eq.not"],["nmid","divides.not"],["notin","in.not"],["nsim","tilde.not"],["nsubseteq","subset.eq.not"],["nu","nu"],["ntriangleleft","lt.tri.not"],["ntriangleright","gt.tri.not"],["odot","dot.circle"],["oint","integral.cont"],["oiint","integral.surf"],["oiiint","integral.vol"],["omega","omega"],["ominus","minus.circle"],["otimes","times.circle"],["parallel","parallel"],["partial","diff"],["perp","perp"],["phi","phi.alt"],["pi","pi"],["pm","plus.minus"],["pounds","pound"],["prec","prec"],["preceq","prec.eq"],["prime","prime"],["prod","product"],["propto","prop"],["psi","psi"],["rangle","angle.r"],["rbrace","brace.r"],["rbrack","bracket.r"],["rhd","triangle"],["rho","rho"],["rightarrow","arrow.r"],["rightthreetimes","times.three.r"],["rtimes","times.r"],["setminus","without"],["sigma","sigma"],["sim","tilde.op"],["simeq","tilde.eq"],["slash","slash"],["smallsetminus","without"],["spadesuit","suit.spade"],["sqsubseteq","subset.eq.sq"],["sqsupseteq","supset.eq.sq"],["subset","subset"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["succeq","succ.eq"],["sum","sum"],["supset","supset"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["tau","tau"],["theta","theta"],["times","times"],["to","arrow.r"],["top","top"],["triangle","triangle.t"],["twoheadrightarrow","arrow.r.twohead"],["upharpoonright","harpoon.tr"],["uplus","union.plus"],["upsilon","upsilon"],["varepsilon","epsilon"],["varnothing","diameter"],["varphi","phi"],["varpi","pi.alt"],["varrho","rho.alt"],["varsigma","sigma.alt"],["vartheta","theta.alt"],["vdash","tack.r"],["vdots","dots.v"],["vee","or"],["wedge","and"],["wr","wreath"],["xi","xi"],["yen","yen"],["zeta","zeta"],["intop","limits(integral)"],["mathscr","scr"],["LaTeX","#LaTeX"],["TeX","#TeX"]]),wt=new Map([["acwopencirclearrow","arrow.ccw"],["adots","dots.up"],["angdnr","angle.acute"],["angle","angle"],["angles","angle.s"],["approx","approx"],["approxeq","approx.eq"],["approxident","tilde.triple"],["assert","tack.r.short"],["ast","ast.op"],["asymp","asymp"],["awint","integral.ccw"],["backcong","tilde.rev.equiv"],["backdprime","prime.double.rev"],["backprime","prime.rev"],["backsim","tilde.rev"],["backsimeq","tilde.eq.rev"],["backslash","backslash"],["backtrprime","prime.triple.rev"],["bardownharpoonleft","harpoon.bl.bar"],["bardownharpoonright","harpoon.br.bar"],["barleftarrow","arrow.l.stop"],["barleftarrowrightarrowbar","arrows.lr.stop"],["barleftharpoondown","harpoon.lb.stop"],["barleftharpoonup","harpoon.lt.stop"],["barrightharpoondown","harpoon.rb.bar"],["barrightharpoonup","harpoon.rt.bar"],["baruparrow","arrow.t.stop"],["barupharpoonleft","harpoon.tl.stop"],["barupharpoonright","harpoon.tr.stop"],["barV","tack.b.double"],["BbbA","AA"],["BbbB","BB"],["BbbC","CC"],["BbbD","DD"],["BbbE","EE"],["BbbF","FF"],["BbbG","GG"],["BbbH","HH"],["BbbI","II"],["BbbJ","JJ"],["BbbK","KK"],["BbbL","LL"],["BbbM","MM"],["BbbN","NN"],["BbbO","OO"],["BbbP","PP"],["BbbQ","QQ"],["BbbR","RR"],["BbbS","SS"],["BbbT","TT"],["BbbU","UU"],["BbbV","VV"],["BbbW","WW"],["BbbX","XX"],["BbbY","YY"],["BbbZ","ZZ"],["because","because"],["bigblacktriangledown","triangle.filled.b"],["bigblacktriangleup","triangle.filled.t"],["bigbot","tack.t.big"],["bigcap","inter.big"],["bigcup","union.big"],["bigcupdot","union.dot.big"],["biginterleave","interleave.big"],["bigodot","dot.circle.big"],["bigoplus","plus.circle.big"],["bigotimes","times.circle.big"],["bigsqcap","inter.sq.big"],["bigsqcup","union.sq.big"],["bigstar","star.filled"],["bigtimes","times.big"],["bigtop","tack.b.big"],["bigtriangledown","triangle.stroked.b"],["bigtriangleup","triangle.stroked.t"],["biguplus","union.plus.big"],["bigvee","or.big"],["bigwedge","and.big"],["bigwhitestar","star.stroked"],["blackhourglass","hourglass.filled"],["blacktriangle","triangle.filled.small.t"],["blacktriangledown","triangle.filled.small.b"],["blacktriangleleft","triangle.filled.l"],["blacktriangleright","triangle.filled.r"],["blkhorzoval","ellipse.filled.h"],["blkvertoval","ellipse.filled.v"],["bot","bot"],["boxast","ast.square"],["boxdot","dot.square"],["boxminus","minus.square"],["boxplus","plus.square"],["boxtimes","times.square"],["cap","inter"],["Cap","inter.double"],["capdot","inter.dot"],["capwedge","inter.and"],["caretinsert","caret"],["cdot","dot.op"],["cdotp","dot.c"],["checkmark","checkmark"],["circledast","ast.circle"],["circledcirc","circle.nested"],["circleddash","dash.circle"],["circledequal","eq.circle"],["circledparallel","parallel.circle"],["circledvert","bar.v.circle"],["clubsuit","suit.club.filled"],["Colon","colon.double"],["coloneq","colon.eq"],["Coloneq","colon.double.eq"],["complement","complement"],["cong","tilde.equiv"],["coprod","product.co"],["cup","union"],["Cup","union.double"],["cupdot","union.dot"],["cupleftarrow","union.arrow"],["cupvee","union.or"],["curlyeqprec","eq.prec"],["curlyeqsucc","eq.succ"],["curlyvee","or.curly"],["curlywedge","and.curly"],["curvearrowleft","arrow.ccw.half"],["curvearrowright","arrow.cw.half"],["cwopencirclearrow","arrow.cw"],["dagger","dagger"],["dashcolon","dash.colon"],["dashv","tack.l"],["Dashv","tack.l.double"],["dashVdash","tack.l.r"],["ddagger","dagger.double"],["ddddot","dot.quad"],["dddot","dot.triple"],["ddots","dots.down"],["DDownarrow","arrow.b.quad"],["Ddownarrow","arrow.b.triple"],["diameter","diameter"],["diamondcdot","diamond.stroked.dot"],["diamondsuit","suit.diamond.stroked"],["dicei","die.one"],["diceii","die.two"],["diceiii","die.three"],["diceiv","die.four"],["dicev","die.five"],["dicevi","die.six"],["div","div"],["divideontimes","times.div"],["Doteq","eq.dots"],["dotminus","minus.dot"],["dotplus","plus.dot"],["dotsim","tilde.dot"],["dottedcircle","circle.dotted"],["dottedsquare","square.stroked.dotted"],["doubleplus","plus.double"],["downarrow","arrow.b"],["Downarrow","arrow.b.double"],["downarrowbar","arrow.b.stop"],["downdasharrow","arrow.b.dashed"],["downdownarrows","arrows.bb"],["downharpoonleft","harpoon.bl"],["downharpoonleftbar","harpoon.bl.stop"],["downharpoonright","harpoon.br"],["downharpoonrightbar","harpoon.br.stop"],["downharpoonsleftright","harpoons.blbr"],["downrightcurvedarrow","arrow.b.curve"],["downuparrows","arrows.bt"],["downupharpoonsleftright","harpoons.bltr"],["downwhitearrow","arrow.b.stroked"],["downzigzagarrow","arrow.zigzag"],["dprime","prime.double"],["dualmap","multimap.double"],["eighthnote","note.eighth.alt"],["ell","ell"],["emptysetoarr","emptyset.arrow.r"],["emptysetoarrl","emptyset.arrow.l"],["emptysetobar","emptyset.bar"],["emptysetocirc","emptyset.circle"],["eparsl","parallel.slanted.eq"],["eqcolon","eq.colon"],["eqdef","eq.def"],["eqgtr","eq.gt"],["eqless","eq.lt"],["eqsim","minus.tilde"],["equal","eq"],["equalparallel","parallel.eq"],["equiv","eq.triple"],["Equiv","eq.quad"],["equivVert","parallel.equiv"],["eqvparsl","parallel.slanted.equiv"],["errbarblackcircle","errorbar.circle.filled"],["errbarblackdiamond","errorbar.diamond.filled"],["errbarblacksquare","errorbar.square.filled"],["errbarcircle","errorbar.circle.stroked"],["errbardiamond","errorbar.diamond.stroked"],["errbarsquare","errorbar.square.stroked"],["euro","euro"],["Exclam","excl.double"],["exists","exists"],["fallingdotseq","eq.dots.down"],["fint","integral.slash"],["flat","flat"],["forall","forall"],["fourvdots","fence.dotted"],["fullouterjoin","join.l.r"],["geq","gt.eq"],["geqq","gt.equiv"],["geqslant","gt.eq.slant"],["gg","gt.double"],["ggg","gt.triple"],["gggnest","gt.triple.nested"],["gnapprox","gt.napprox"],["gneq","gt.neq"],["gneqq","gt.nequiv"],["gnsim","gt.ntilde"],["greater","gt"],["gtlpar","angle.spheric.rev"],["gtrapprox","gt.approx"],["gtrdot","gt.dot"],["gtreqless","gt.eq.lt"],["gtrless","gt.lt"],["gtrsim","gt.tilde"],["heartsuit","suit.heart.stroked"],["hknearrow","arrow.tr.hook"],["hknwarrow","arrow.tl.hook"],["hksearrow","arrow.br.hook"],["hkswarrow","arrow.bl.hook"],["hookleftarrow","arrow.l.hook"],["hookrightarrow","arrow.r.hook"],["horizbar","bar.h"],["hourglass","hourglass.stroked"],["hrectangle","rect.stroked.h"],["hrectangleblack","rect.filled.h"],["hslash","planck.reduce"],["hzigzag","dash.wave.double"],["iiiint","integral.quad"],["iiint","integral.triple"],["iinfin","infinity.incomplete"],["iint","integral.double"],["Im","Im"],["imageof","image"],["in","in"],["increment","laplace"],["infty","infinity"],["int","integral"],["intbar","integral.dash"],["intBar","integral.dash.double"],["intcap","integral.inter"],["intclockwise","integral.cw"],["intcup","integral.union"],["interleave","interleave"],["intlarhk","integral.arrow.hook"],["intx","integral.times"],["Join","join"],["langle","angle.l"],["lAngle","angle.l.double"],["langledot","angle.l.dot"],["lat","lat"],["late","lat.eq"],["lbrace","brace.l"],["lBrace","brace.l.double"],["lbrack","bracket.l"],["lBrack","bracket.l.double"],["lbrbrak","shell.l"],["Lbrbrak","shell.l.double"],["lceil","ceil.l"],["lcurvyangle","angle.l.curly"],["leftarrow","arrow.l"],["Leftarrow","arrow.l.double"],["leftarrowtail","arrow.l.tail"],["leftdasharrow","arrow.l.dashed"],["leftdotarrow","arrow.l.dotted"],["leftdowncurvedarrow","arrow.l.curve"],["leftharpoondown","harpoon.lb"],["leftharpoondownbar","harpoon.lb.bar"],["leftharpoonsupdown","harpoons.ltlb"],["leftharpoonup","harpoon.lt"],["leftharpoonupbar","harpoon.lt.bar"],["leftleftarrows","arrows.ll"],["leftouterjoin","join.l"],["leftrightarrow","arrow.l.r"],["Leftrightarrow","arrow.l.r.double"],["leftrightarrows","arrows.lr"],["leftrightharpoondowndown","harpoon.lb.rb"],["leftrightharpoondownup","harpoon.lb.rt"],["leftrightharpoons","harpoons.ltrb"],["leftrightharpoonsdown","harpoons.lbrb"],["leftrightharpoonsup","harpoons.ltrt"],["leftrightharpoonupdown","harpoon.lt.rb"],["leftrightharpoonupup","harpoon.lt.rt"],["leftrightsquigarrow","arrow.l.r.wave"],["leftsquigarrow","arrow.l.squiggly"],["leftthreearrows","arrows.lll"],["leftthreetimes","times.three.l"],["leftwavearrow","arrow.l.wave"],["leftwhitearrow","arrow.l.stroked"],["leq","lt.eq"],["leqq","lt.equiv"],["leqslant","lt.eq.slant"],["less","lt"],["lessapprox","lt.approx"],["lessdot","lt.dot"],["lesseqgtr","lt.eq.gt"],["lessgtr","lt.gt"],["lesssim","lt.tilde"],["lfloor","floor.l"],["lgblkcircle","circle.filled.big"],["lgblksquare","square.filled.big"],["lgwhtcircle","circle.stroked.big"],["lgwhtsquare","square.stroked.big"],["ll","lt.double"],["llblacktriangle","triangle.filled.bl"],["LLeftarrow","arrow.l.quad"],["Lleftarrow","arrow.l.triple"],["lll","lt.triple"],["lllnest","lt.triple.nested"],["lltriangle","triangle.stroked.bl"],["lnapprox","lt.napprox"],["lneq","lt.neq"],["lneqq","lt.nequiv"],["lnsim","lt.ntilde"],["longdashv","tack.l.long"],["Longleftarrow","arrow.l.double.long"],["longleftarrow","arrow.l.long"],["Longleftrightarrow","arrow.l.r.double.long"],["longleftrightarrow","arrow.l.r.long"],["longleftsquigarrow","arrow.l.long.squiggly"],["Longmapsfrom","arrow.l.double.long.bar"],["longmapsfrom","arrow.l.long.bar"],["longmapsto","arrow.r.long.bar"],["Longmapsto","arrow.r.double.long.bar"],["Longrightarrow","arrow.r.double.long"],["longrightarrow","arrow.r.long"],["longrightsquigarrow","arrow.r.long.squiggly"],["looparrowleft","arrow.l.loop"],["looparrowright","arrow.r.loop"],["lparen","paren.l"],["lParen","paren.l.double"],["lrblacktriangle","triangle.filled.br"],["lrtriangle","triangle.stroked.br"],["ltimes","times.l"],["lvzigzag","fence.l"],["Lvzigzag","fence.l.double"],["maltese","maltese"],["mapsdown","arrow.b.bar"],["mapsfrom","arrow.l.bar"],["Mapsfrom","arrow.l.double.bar"],["mapsto","arrow.r.bar"],["Mapsto","arrow.r.double.bar"],["mapsup","arrow.t.bar"],["mathampersand","amp"],["mathatsign","at"],["mathcolon","colon"],["mathcomma","comma"],["mathdollar","dollar"],["mathexclam","excl"],["mathoctothorpe","hash"],["mathparagraph","pilcrow"],["mathpercent","percent"],["mathperiod","dot.basic"],["mathplus","plus"],["mathquestion","quest"],["mathratio","ratio"],["mathsection","section"],["mathsemicolon","semi"],["mathslash","slash"],["mathsterling","pound"],["mathyen","yen"],["mdblkdiamond","diamond.filled.medium"],["mdblklozenge","lozenge.filled.medium"],["mdblksquare","square.filled.medium"],["mdlgblkcircle","circle.filled"],["mdlgblkdiamond","diamond.filled"],["mdlgblklozenge","lozenge.filled"],["mdlgblksquare","square.filled"],["mdlgwhtcircle","circle.stroked"],["mdlgwhtdiamond","diamond.stroked"],["mdlgwhtlozenge","lozenge.stroked"],["mdlgwhtsquare","square.stroked"],["mdsmblkcircle","circle.filled.tiny"],["mdsmblksquare","square.filled.small"],["mdsmwhtcircle","circle.stroked.small"],["mdsmwhtsquare","square.stroked.small"],["mdwhtdiamond","diamond.stroked.medium"],["mdwhtlozenge","lozenge.stroked.medium"],["mdwhtsquare","square.stroked.medium"],["measeq","eq.m"],["measuredangle","angle.arc"],["measuredangleleft","angle.arc.rev"],["measuredrightangle","angle.right.arc"],["mho","Omega.inv"],["mid","divides"],["minus","minus"],["models","models"],["mp","minus.plus"],["multimap","multimap"],["nabla","gradient"],["napprox","approx.not"],["nasymp","asymp.not"],["natural","natural"],["ncong","tilde.equiv.not"],["ne","eq.not"],["nearrow","arrow.tr"],["Nearrow","arrow.tr.double"],["neg","not"],["nequiv","equiv.not"],["neswarrow","arrow.tr.bl"],["nexists","exists.not"],["ngeq","gt.eq.not"],["ngtr","gt.not"],["ngtrless","gt.lt.not"],["ngtrsim","gt.tilde.not"],["nhpar","parallel.struck"],["nhVvert","interleave.struck"],["ni","in.rev"],["nLeftarrow","arrow.l.double.not"],["nleftarrow","arrow.l.not"],["nLeftrightarrow","arrow.l.r.double.not"],["nleftrightarrow","arrow.l.r.not"],["nleq","lt.eq.not"],["nless","lt.not"],["nlessgtr","lt.gt.not"],["nlesssim","lt.tilde.not"],["nmid","divides.not"],["nni","in.rev.not"],["notin","in.not"],["nparallel","parallel.not"],["nprec","prec.not"],["npreccurlyeq","prec.curly.eq.not"],["nRightarrow","arrow.r.double.not"],["nrightarrow","arrow.r.not"],["nsim","tilde.not"],["nsimeq","tilde.eq.not"],["nsqsubseteq","subset.eq.sq.not"],["nsqsupseteq","supset.eq.sq.not"],["nsubset","subset.not"],["nsubseteq","subset.eq.not"],["nsucc","succ.not"],["nsucccurlyeq","succ.curly.eq.not"],["nsupset","supset.not"],["nsupseteq","supset.eq.not"],["ntrianglelefteq","lt.tri.eq.not"],["ntrianglerighteq","gt.tri.eq.not"],["nvartriangleleft","lt.tri.not"],["nvartriangleright","gt.tri.not"],["nVdash","forces.not"],["nvdash","tack.r.not"],["nvDash","tack.r.double.not"],["nvinfty","infinity.bar"],["nwarrow","arrow.tl"],["Nwarrow","arrow.tl.double"],["nwsearrow","arrow.tl.br"],["obrbrak","shell.t"],["obslash","backslash.circle"],["odiv","div.circle"],["odot","dot.circle"],["ogreaterthan","gt.circle"],["oiiint","integral.vol"],["oiint","integral.surf"],["oint","integral.cont"],["ointctrclockwise","integral.cont.ccw"],["olessthan","lt.circle"],["ominus","minus.circle"],["operp","perp.circle"],["oplus","plus.circle"],["origof","original"],["otimes","times.circle"],["overbracket","bracket.t"],["overparen","paren.t"],["parallel","parallel"],["parallelogram","parallelogram.stroked"],["parallelogramblack","parallelogram.filled"],["parsim","parallel.tilde"],["partial","diff"],["pentagon","penta.stroked"],["pentagonblack","penta.filled"],["perp","perp"],["Planckconst","planck"],["pm","plus.minus"],["prec","prec"],["Prec","prec.double"],["precapprox","prec.approx"],["preccurlyeq","prec.curly.eq"],["preceq","prec.eq"],["preceqq","prec.equiv"],["precnapprox","prec.napprox"],["precneq","prec.neq"],["precneqq","prec.nequiv"],["precnsim","prec.ntilde"],["precsim","prec.tilde"],["prime","prime"],["prod","product"],["propto","prop"],["QED","qed"],["qprime","prime.quad"],["quarternote","note.quarter.alt"],["questeq","eq.quest"],["Question","quest.double"],["rangle","angle.r"],["rAngle","angle.r.double"],["rangledot","angle.r.dot"],["rbrace","brace.r"],["rBrace","brace.r.double"],["rbrack","bracket.r"],["rBrack","bracket.r.double"],["rbrbrak","shell.r"],["Rbrbrak","shell.r.double"],["rceil","ceil.r"],["rcurvyangle","angle.r.curly"],["Re","Re"],["revangle","angle.rev"],["revemptyset","emptyset.rev"],["revnmid","divides.not.rev"],["rfloor","floor.r"],["rightangle","angle.right"],["rightanglemdot","angle.right.dot"],["rightanglesqr","angle.right.sq"],["rightarrow","arrow.r"],["Rightarrow","arrow.r.double"],["rightarrowbar","arrow.r.stop"],["rightarrowonoplus","plus.circle.arrow"],["rightarrowtail","arrow.r.tail"],["rightdasharrow","arrow.r.dashed"],["rightdotarrow","arrow.r.dotted"],["rightdowncurvedarrow","arrow.r.curve"],["rightharpoondown","harpoon.rb"],["rightharpoondownbar","harpoon.rb.stop"],["rightharpoonsupdown","harpoons.rtrb"],["rightharpoonup","harpoon.rt"],["rightharpoonupbar","harpoon.rt.stop"],["rightleftarrows","arrows.rl"],["rightleftharpoons","harpoons.rtlb"],["rightleftharpoonsdown","harpoons.rblb"],["rightleftharpoonsup","harpoons.rtlt"],["rightouterjoin","join.r"],["rightrightarrows","arrows.rr"],["rightsquigarrow","arrow.r.squiggly"],["rightthreearrows","arrows.rrr"],["rightthreetimes","times.three.r"],["rightwavearrow","arrow.r.wave"],["rightwhitearrow","arrow.r.stroked"],["risingdotseq","eq.dots.up"],["rparen","paren.r"],["rParen","paren.r.double"],["RRightarrow","arrow.r.quad"],["Rrightarrow","arrow.r.triple"],["rsolbar","backslash.not"],["rtimes","times.r"],["rvzigzag","fence.r"],["Rvzigzag","fence.r.double"],["searrow","arrow.br"],["Searrow","arrow.br.double"],["setminus","without"],["sharp","sharp"],["shortdowntack","tack.b.short"],["shortlefttack","tack.l.short"],["shortuptack","tack.t.short"],["sim","tilde.op"],["sime","tilde.eq"],["similarleftarrow","arrow.l.tilde"],["similarrightarrow","arrow.r.tilde"],["simneqq","tilde.nequiv"],["smallblacktriangleleft","triangle.filled.small.l"],["smallblacktriangleright","triangle.filled.small.r"],["smallin","in.small"],["smallni","in.rev.small"],["smalltriangleleft","triangle.stroked.small.l"],["smalltriangleright","triangle.stroked.small.r"],["smashtimes","smash"],["smblkcircle","bullet"],["smblkdiamond","diamond.filled.small"],["smblklozenge","lozenge.filled.small"],["smblksquare","square.filled.tiny"],["smeparsl","parallel.slanted.eq.tilde"],["smt","smt"],["smte","smt.eq"],["smwhtdiamond","diamond.stroked.small"],["smwhtlozenge","lozenge.stroked.small"],["smwhtsquare","square.stroked.tiny"],["spadesuit","suit.spade.filled"],["sphericalangle","angle.spheric"],["sphericalangleup","angle.spheric.top"],["sqcap","inter.sq"],["Sqcap","inter.sq.double"],["sqcup","union.sq"],["Sqcup","union.sq.double"],["sqint","integral.square"],["sqsubset","subset.sq"],["sqsubseteq","subset.eq.sq"],["sqsubsetneq","subset.sq.neq"],["sqsupset","supset.sq"],["sqsupseteq","supset.eq.sq"],["sqsupsetneq","supset.sq.neq"],["squoval","square.stroked.rounded"],["sslash","slash.double"],["star","star.op"],["stareq","eq.star"],["subset","subset"],["Subset","subset.double"],["subsetdot","subset.dot"],["subseteq","subset.eq"],["subsetneq","subset.neq"],["succ","succ"],["Succ","succ.double"],["succapprox","succ.approx"],["succcurlyeq","succ.curly.eq"],["succeq","succ.eq"],["succeqq","succ.equiv"],["succnapprox","succ.napprox"],["succneq","succ.neq"],["succneqq","succ.nequiv"],["succnsim","succ.ntilde"],["succsim","succ.tilde"],["sum","sum"],["sumint","sum.integral"],["supset","supset"],["Supset","supset.double"],["supsetdot","supset.dot"],["supseteq","supset.eq"],["supsetneq","supset.neq"],["swarrow","arrow.bl"],["Swarrow","arrow.bl.double"],["therefore","therefore"],["threedangle","angle.spatial"],["threedotcolon","colon.tri.op"],["tieinfty","infinity.tie"],["times","times"],["tminus","miny"],["top","tack.b"],["tplus","tiny"],["trianglecdot","triangle.stroked.dot"],["triangledown","triangle.stroked.small.b"],["triangleleft","triangle.stroked.l"],["trianglelefteq","lt.tri.eq"],["triangleminus","minus.triangle"],["triangleplus","plus.triangle"],["triangleq","eq.delta"],["triangleright","triangle.stroked.r"],["trianglerighteq","gt.tri.eq"],["triangletimes","times.triangle"],["tripleplus","plus.triple"],["trprime","prime.triple"],["trslash","slash.triple"],["twoheaddownarrow","arrow.b.twohead"],["twoheadleftarrow","arrow.l.twohead"],["twoheadmapsfrom","arrow.l.twohead.bar"],["twoheadmapsto","arrow.r.twohead.bar"],["twoheadrightarrow","arrow.r.twohead"],["twoheaduparrow","arrow.t.twohead"],["twonotes","note.eighth.beamed"],["ubrbrak","shell.b"],["ulblacktriangle","triangle.filled.tl"],["ultriangle","triangle.stroked.tl"],["uminus","union.minus"],["underbrace","brace.b"],["underbracket","bracket.b"],["underparen","paren.b"],["unicodecdots","dots.h.c"],["unicodeellipsis","dots.h"],["upand","amp.inv"],["uparrow","arrow.t"],["Uparrow","arrow.t.double"],["updasharrow","arrow.t.dashed"],["updownarrow","arrow.t.b"],["Updownarrow","arrow.t.b.double"],["updownarrows","arrows.tb"],["updownharpoonleftleft","harpoon.tl.bl"],["updownharpoonleftright","harpoon.tl.br"],["updownharpoonrightleft","harpoon.tr.bl"],["updownharpoonrightright","harpoon.tr.br"],["updownharpoonsleftright","harpoons.tlbr"],["upharpoonleft","harpoon.tl"],["upharpoonleftbar","harpoon.tl.bar"],["upharpoonright","harpoon.tr"],["upharpoonrightbar","harpoon.tr.bar"],["upharpoonsleftright","harpoons.tltr"],["uplus","union.plus"],["uprightcurvearrow","arrow.t.curve"],["upuparrows","arrows.tt"],["upwhitearrow","arrow.t.stroked"],["urblacktriangle","triangle.filled.tr"],["urtriangle","triangle.stroked.tr"],["UUparrow","arrow.t.quad"],["Uuparrow","arrow.t.triple"],["varclubsuit","suit.club.stroked"],["vardiamondsuit","suit.diamond.filled"],["varheartsuit","suit.heart.filled"],["varhexagon","hexa.stroked"],["varhexagonblack","hexa.filled"],["varnothing","emptyset"],["varointclockwise","integral.cont.cw"],["varspadesuit","suit.spade.stroked"],["vartriangle","triangle.stroked.small.t"],["vartriangleleft","lt.tri"],["vartriangleright","gt.tri"],["Vbar","tack.t.double"],["Vdash","forces"],["vdash","tack.r"],["vDash","tack.r.double"],["vdots","dots.v"],["vee","or"],["Vee","or.double"],["veedot","or.dot"],["veeeq","eq.equi"],["vert","bar.v"],["Vert","bar.v.double"],["vlongdash","tack.r.long"],["vrectangle","rect.stroked.v"],["vrectangleblack","rect.filled.v"],["Vvert","bar.v.triple"],["vysmblkcircle","circle.filled.small"],["vysmwhtcircle","circle.stroked.tiny"],["wedge","and"],["Wedge","and.double"],["wedgedot","and.dot"],["wedgeq","eq.est"],["whiteinwhitetriangle","triangle.stroked.nested"],["whthorzoval","ellipse.stroked.h"],["whtvertoval","ellipse.stroked.v"],["wideangledown","angle.oblique"],["wr","wreath"],["xsol","slash.big"]]),bt=new Map([["gets","leftarrow"],["iff","Longleftrightarrow"],["implies","Longrightarrow"]]);for(let[n,e]of wt)x.has(n)||x.set(n,e);var Y=new Map;for(let[n,e]of Array.from(x.entries()).reverse())Y.set(e,n);Y.set("oo","infty");var mt=new Map([["top","top"],["frac","frac"],["tilde","tilde"],["hat","hat"],["upright","mathrm"],["bold","boldsymbol"],["infinity","infty"]]);for(let[n,e]of mt)Y.set(n,e);for(let[n,e]of bt)x.has(n)||x.set(n,x.get(e));var U=class extends Error{node;constructor(e,r=null){super(e),this.name="ConverterError",this.node=r}},ft=i.NONE.toNode(),yt=["dim","id","im","mod","Pr","sech","csch"];function Et(n){if(/^[a-zA-Z0-9]$/.test(n))return n;if(n==="/")return"\\/";if(["\\\\","\\{","\\}","\\%"].includes(n))return n.substring(1);if(["\\$","\\#","\\&","\\_"].includes(n))return n;if(n.startsWith("\\")){let e=n.slice(1);return x.has(e)?x.get(e):null}return n}function W(n,e){let r;switch(n.type){case 0:return i.NONE;case 2:r=1;break;case 1:r=2;break;case 3:r=3;break;case 4:r=5;break;case 5:r=6;break;case 6:r=8;break;case 7:{if(n.value==="\\\\")return new i(7,"\\");if(n.value==="\\!")return new i(1,"#h(-math.thin.amount)");if(x.has(n.value.substring(1))){let s=x.get(n.value.substring(1));return new i(1,s)}else throw new Error(`Unknown control sequence: ${n.value}`)}default:throw Error(`Unknown token type: ${n.type}`)}let t=Et(n.value);if(t===null){if(e.nonStrict)return new i(r,n.value.substring(1));throw new U(`Unknown token: ${n.value}`,n)}return new i(r,t)}function xt(n,e){let[r,t]=n.args;if(e.optimize&&["\\overset{\\text{def}}{=}","\\overset{d e f}{=}"].includes(n.toString()))return new i(1,"eq.def").toNode();let s=new f(new i(1,"limits"),[m(t,e)]);return new A({base:s,sup:m(r,e),sub:null})}function Nt(n,e){let[r,t]=n.args,s=new f(new i(1,"limits"),[m(t,e)]);return new A({base:s,sub:m(r,e),sup:null})}function qt(n){let e={},r={l:"#left",c:"#center",r:"#right"},t=Array.from(n),s=[],o=0;for(let u of t)u==="|"?s.push(o):(u==="l"||u==="c"||u==="r")&&o++;if(s.length>0){let u;s.length===1?u=`#${s[0]}`:u=`#(vline: (${s.join(", ")}))`,e.augment=new i(3,u).toNode()}let a=t.map(u=>r[u]).filter(u=>u!==void 0).map(u=>new i(3,u).toNode());if(a.length>0){let u=a.every(p=>p.eq(a[0]));e.align=u?a[0]:new i(3,"#center").toNode()}return e}var vt=new i(2,"("),Lt=new i(2,")");function $e(n){return n.head.type===2&&["(",")","[","]","{","}","|","\u230A","\u230B","\u2308","\u2309"].includes(n.head.value)}function ce(n){let e=["group","supsub","matrixLike","fraction","empty"].includes(n.type);if(n.type==="group"){let r=n;if(r.items.length===0)e=!0;else{let t=r.items[0],s=r.items[r.items.length-1];$e(t)&&$e(s)&&(e=!1)}}return e?new q(null,{left:vt,right:Lt,body:n}):n}function m(n,e={}){switch(n.type){case"terminal":return W(n.head,e).toNode();case"text":{let t=n;return/[^\x00-\x7F]+/.test(t.head.value)&&e.nonAsciiWrapper!==""?new f(new i(1,e.nonAsciiWrapper),[new i(4,t.head.value).toNode()]):new i(4,t.head.value).toNode()}case"ordgroup":let r=n;return new _(r.items.map(t=>m(t,e)));case"supsub":{let t=n,{base:s,sup:o,sub:a}=t;if(s&&s.type==="funcCall"&&s.head.value==="\\overbrace"&&o)return new f(new i(1,"overbrace"),[m(s.args[0],e),m(o,e)]);if(s&&s.type==="funcCall"&&s.head.value==="\\underbrace"&&a)return new f(new i(1,"underbrace"),[m(s.args[0],e),m(a,e)]);let u={base:m(s,e),sup:o?m(o,e):null,sub:a?m(a,e):null};return u.base=ce(u.base),u.sup&&(u.sup=ce(u.sup)),u.sub&&(u.sub=ce(u.sub)),new A(u)}case"leftright":{let t=n,{left:s,right:o}=t,a=m(t.body,e);if(e.optimize&&s!==null&&o!==null){let h=W(s,e),d=W(o,e);if(s.value==="\\|"&&o.value==="\\|")return new f(new i(1,"norm"),[a]);if(["[]","()","\\{\\}","\\lfloor\\rfloor","\\lceil\\rceil","\\lfloor\\rceil"].includes(s.value+o.value))return new _([h.toNode(),a,d.toNode()])}let u=function(h){return["(",")","{","["].includes(h.value)?new i(2,"\\"+h.value):h},p=s?W(s,e):null,c=o?W(o,e):null;return p===null&&c!==null&&(c=u(c)),c===null&&p!==null&&(p=u(p)),new q(new i(1,"lr"),{body:a,left:p,right:c})}case"funcCall":{let t=n,s=m(t.args[0],e);if(t.head.value==="\\sqrt"&&t.data){let o=m(t.data,e);return new f(new i(1,"root"),[o,s])}if(t.head.value==="\\mathbf"){let o=new f(new i(1,"bold"),[s]);return new f(new i(1,"upright"),[o])}if(t.head.value==="\\overrightarrow")return new f(new i(1,"arrow"),[s]);if(t.head.value==="\\overleftarrow")return new f(new i(1,"accent"),[s,new i(1,"arrow.l").toNode()]);if(t.head.value==="\\operatorname")return e.optimize&&yt.includes(s.head.value)?new i(1,s.head.value).toNode():new f(new i(1,"op"),[new i(4,s.head.value).toNode()]);if(t.head.value==="\\textcolor"){let o=new z(new i(1,"#text"),[m(t.args[1],e)]);return o.setOptions({fill:s}),o}if(t.head.value==="\\substack")return s;if(t.head.value==="\\set")return new q(null,{body:s,left:i.LEFT_BRACE,right:i.RIGHT_BRACE});if(t.head.value==="\\overset")return xt(t,e);if(t.head.value==="\\underset")return Nt(t,e);if(t.head.value==="\\frac"&&e.fracToSlash)return new D(t.args.map(o=>m(o,e)).map(ce));if(e.optimize){if(t.head.value==="\\mathbb"&&/^\\mathbb{[A-Z]}$/.test(t.toString()))return new i(1,s.head.value.repeat(2)).toNode();if(t.head.value==="\\mathrm"&&t.toString()==="\\mathrm{d}")return new i(1,"dif").toNode()}return new f(W(t.head,e),t.args.map(o=>m(o,e)))}case"beginend":{let t=n,s=t.matrix.map(o=>o.map(a=>m(a,e)));if(t.head.value.startsWith("align"))return new y(null,s);if(t.head.value==="cases")return new y(y.CASES,s);if(t.head.value==="subarray"){if(t.data)switch(t.data.head.value){case"r":s.forEach(a=>a.push(i.EMPTY.toNode()));break;case"l":s.forEach(a=>a.unshift(i.EMPTY.toNode()));break;default:break}return new y(null,s)}if(t.head.value==="array"){let o={delim:ft};T(t.data!==null&&t.head.type===3);let a=qt(t.data.head.value);Object.assign(o,a);let u=new y(y.MAT,s);return u.setOptions(o),u}if(t.head.value.endsWith("matrix")){let o=new y(y.MAT,s),a;switch(t.head.value){case"matrix":a=i.NONE;break;case"pmatrix":return o;case"bmatrix":a=new i(4,"[");break;case"Bmatrix":a=new i(4,"{");break;case"vmatrix":a=new i(4,"|");break;case"Vmatrix":{a=new i(1,"bar.v.double");break}default:throw new U(`Unimplemented beginend: ${t.head}`,t)}return o.setOptions({delim:a.toNode()}),o}throw new U(`Unimplemented beginend: ${t.head}`,t)}default:throw new U(`Unimplemented node type: ${n.type}`,n)}}function P(n){switch(n.type){case 0:return l.EMPTY;case 1:{let e=function(r){return Y.has(r)?"\\"+Y.get(r):"\\"+r};return new l(2,e(n.value))}case 2:{let e;return["{","}","%"].includes(n.value)?e="\\"+n.value:e=n.value,new l(1,e)}case 3:return new l(3,n.value);case 4:return new l(3,n.value);case 5:return new l(4,n.value);case 6:return new l(5,n.value);case 7:{let e;switch(n.value){case"\\":e="\\\\";break;case"&":e="&";break;default:throw new Error(`[typst_token_to_tex]Unimplemented control sequence: ${n.value}`)}return new l(7,e)}case 8:return new l(6,n.value);default:throw new Error(`Unimplemented token type: ${n.type}`)}}var kt=new l(1,",").toNode();function b(n){switch(n.type){case"terminal":{let e=n;if(e.head.type===1){if(e.head.value==="eq.def")return new g(new l(2,"\\overset"),[new S(new l(3,"def")),new l(1,"=").toNode()]);if(e.head.value==="comma")return new l(1,",").toNode();if(e.head.value==="dif")return new g(new l(2,"\\mathrm"),[new l(1,"d").toNode()]);if(e.head.value==="hyph"||e.head.value==="hyph.minus")return new S(new l(3,"-"));if(/^([A-Z])\1$/.test(e.head.value))return new g(new l(2,"\\mathbb"),[new l(1,e.head.value[0]).toNode()])}return e.head.type===4?new S(new l(3,e.head.value)):P(e.head).toNode()}case"group":{let r=n.items.map(b),t=new l(7,"&").toNode(),s=new l(7,"\\\\").toNode();if(re(r,t)){let o=me(r,s),a=[];for(let u of o){let p=me(u,t);a.push(p.map(c=>new E(c)))}return new M(new l(3,"aligned"),a)}return new E(r)}case"leftright":{let e=n,r=b(e.body),t=e.left?P(e.left):new l(1,"."),s=e.right?P(e.right):new l(1,".");return e.isOverHigh()&&(t.value="\\left"+t.value,s.value="\\right"+s.value),new E([t.toNode(),r,s.toNode()])}case"funcCall":{let e=n;switch(e.head.value){case"norm":{let r=e.args[0],t=b(r);return e.isOverHigh()?new I({body:t,left:new l(2,"\\|"),right:new l(2,"\\|")}):t}case"floor":case"ceil":{let r="\\l"+e.head.value,t="\\r"+e.head.value,s=e.args[0],o=b(s),a=new l(2,r),u=new l(2,t);return e.isOverHigh()?new I({body:o,left:a,right:u}):new E([a.toNode(),o,u.toNode()])}case"root":{let[r,t]=e.args,s=b(r);return new g(new l(2,"\\sqrt"),[b(t)],s)}case"overbrace":case"underbrace":{let[r,t]=e.args,s=new g(P(e.head),[b(r)]),o=b(t),a=e.head.value==="overbrace"?{base:s,sup:o,sub:null}:{base:s,sub:o,sup:null};return new R(a)}case"vec":{let r=e.args.map(b).map(t=>[t]);return new M(new l(3,"pmatrix"),r)}case"op":{let r=e.args[0];return T(r.head.type===4),new g(P(e.head),[new l(3,r.head.value).toNode()])}default:{let r=P(e.head),t=H.includes(r.value.substring(1))||X.includes(r.value.substring(1));return r.value.length>0&&t?new g(r,e.args.map(b)):new E([P(e.head).toNode(),new l(1,"(").toNode(),...Ie(e.args.map(b),kt),new l(1,")").toNode()])}}}case"markupFunc":{let e=n;switch(e.head.value){case"#text":if(e.options&&e.options.fill){let r=e.options.fill;return new g(new l(2,"\\textcolor"),[b(r),b(e.fragments[0])])}case"#heading":default:throw new Error(`Unimplemented markup function: ${e.head.value}`)}}case"supsub":{let e=n,{base:r,sup:t,sub:s}=e,o=t?b(t):null,a=s?b(s):null;if(r.head.eq(new i(1,"limits"))){let h=b(r.args[0]);if(o!==null&&a===null)return new g(new l(2,"\\overset"),[o,h]);if(o===null&&a!==null)return new g(new l(2,"\\underset"),[a,h]);{let d=new g(new l(2,"\\underset"),[a,h]);return new g(new l(2,"\\overset"),[o,d])}}let u=b(r);return new R({base:u,sup:o,sub:a})}case"matrixLike":{let e=n,r=e.matrix.map(t=>t.map(b));if(e.head.eq(y.MAT)){let t="pmatrix";if(e.options&&"delim"in e.options){let s=e.options.delim;switch(s.head.value){case"#none":t="matrix";break;case"[":case"]":t="bmatrix";break;case"(":case")":t="pmatrix";break;case"{":case"}":t="Bmatrix";break;case"|":t="vmatrix";break;case"bar":case"bar.v":t="vmatrix";break;case"bar.v.double":t="Vmatrix";break;default:throw new Error(`Unexpected delimiter ${s.head}`)}}return new M(new l(3,t),r)}else{if(e.head.eq(y.CASES))return new M(new l(3,"cases"),r);throw new Error(`Unexpected matrix type ${e.head}`)}}case"fraction":{let e=n,[r,t]=e.args,s=b(r),o=b(t);return new g(new l(2,"\\frac"),[s,o])}default:throw new Error("[convert_typst_node_to_tex] Unimplemented type: "+n.type)}}var Mt=Array.from(ie.keys());function _t(){return`(${Mt.map(e=>(e=e.replaceAll("|","\\|"),e=e.replaceAll(".","\\."),e=e.replaceAll("[","\\["),e=e.replaceAll("]","\\]"),e)).join("|")})`}var Ot=_t(),St=new Map([[String.raw`//[^\n]*`,n=>new i(5,n.text().substring(2))],[String.raw`/`,n=>new i(2,n.text())],[String.raw`[_^&]`,n=>new i(7,n.text())],[String.raw`\r?\n`,n=>new i(8,`
|
|
11
11
|
`)],[String.raw`\s+`,n=>new i(6,n.text())],[String.raw`\\[$&#_]`,n=>new i(2,n.text())],[String.raw`\\\n`,n=>[new i(7,"\\"),new i(8,`
|
|
12
|
-
`)]],[String.raw`\\\s`,n=>[new i(7,"\\"),new i(6," ")]],[String.raw`\\\S`,n=>new i(7,"")],[String.raw`"([^"]|(\\"))*"`,n=>{let e=n.text().substring(1,n.text().length-1);return e.replaceAll('\\"','"'),new i(4,e)}],[
|
|
13
|
-
`))&&o.push(p)}let u;return s?u=he(o,!0):o.length===1?u=o[0]:u=he(o),[u,
|
|
12
|
+
`)]],[String.raw`\\\s`,n=>[new i(7,"\\"),new i(6," ")]],[String.raw`\\\S`,n=>new i(7,"")],[String.raw`"([^"]|(\\"))*"`,n=>{let e=n.text().substring(1,n.text().length-1);return e.replaceAll('\\"','"'),new i(4,e)}],[Ot,n=>{let e=n.text(),r=ie.get(e);return new i(1,r)}],[String.raw`[0-9]+(\.[0-9]+)?`,n=>new i(2,n.text())],[String.raw`[+\-*/=\'<>!.,;?()\[\]|]`,n=>new i(2,n.text())],[String.raw`#h\((.+?)\)`,n=>{let e=n.reMatchArray();return[new i(1,"#h"),new i(2,"("),new i(3,e[1]),new i(2,")")]}],[String.raw`#none`,n=>new i(0,n.text())],[String.raw`#?[a-zA-Z\.]+`,n=>new i(n.text().length===1?2:1,n.text())],[String.raw`.`,n=>new i(2,n.text())]]),At={start:St};function Fe(n){return new B(At).collect(n)}function Ge(n,e){let r=e;for(;r<n.length&&n[r].eq(new i(2,"'"));)r+=1;return r-e}function Ae(n,e,r,t){T(n[e].isOneOf(r));let s=1,o=e+1;for(;s>0;){if(o>=n.length)throw new Error("Unmatched brackets or parentheses");n[o].isOneOf(t)?s-=1:n[o].isOneOf(r)&&(s+=1),o+=1}return o-1}function Q(n,e){return Ae(n,e,[$,Ve,Dt],[Oe,Ze,zt])}function Ct(n,e){return Ae(n,e,i.LEFT_DELIMITERS,i.RIGHT_DELIMITERS)}function Rt(n,e){let r=new i(2,"(").toNode(),t=new i(2,")").toNode();T(n[e].eq(r));let s=1,o=e+1;for(;s>0;){if(o>=n.length)throw new Error("Unmatched '('");n[o].eq(r)?s+=1:n[o].eq(t)&&(s-=1),o+=1}return o-1}function He(n){let e=[];for(let r=0;r<n;r++)e.push(new i(2,"'").toNode());return e}var de=new i(2,"/").toNode();function It(n,e){let r=e;for(;r<n.length&&(n[r].head.type===6||n[r].head.type===8);)r++;return r===n.length?null:n[r]}function Pt(n){let e=!1,r=[];for(let t=0;t<n.length;t++){let s=n[t];(s.head.type===6||s.head.type===8)&&(e||It(n,t+1)?.eq(de))||(s.eq(de)?e=!0:e=!1,r.push(s))}return r}function he(n,e=!1){n=Pt(n);let r=$.toNode(),t=Oe.toNode(),s=[],o=[],a=0;for(;a<n.length;){let p=n[a];if(p.eq(t))throw new F("Unexpected ')'");if(p.eq(de))s.push(p),a++;else{let c;if(p.eq(r)){let h=Rt(n,a);c=he(n.slice(a+1,h),!0),a=h+1}else c=p,a++;if(s.length>0&&s[s.length-1].eq(de)){let h=c;if(o.length===0)throw new F("Unexpected '/' operator, no numerator before it");let d=o.pop();h.type==="leftright"&&(h=h.body),d.type==="leftright"&&(d=d.body),o.push(new D([d,h])),s.pop()}else o.push(c)}}let u=o.length===1?o[0]:new _(o);return e?new q(null,{body:u,left:$,right:Oe}):u}function Bt(n){let e=new i(2,":").toNode(),r={};for(let t of n)T(t.items.length==3),T(t.items[1].eq(e)),r[t.items[0].toString()]=new K(new i(3,t.items[2].toString()));return r}var F=class extends Error{constructor(e){super(e),this.name="TypstParserError"}},Xe=new i(7,"_"),je=new i(7,"^"),$=new i(2,"("),Oe=new i(2,")"),Ve=new i(2,"["),Ze=new i(2,"]"),Dt=new i(2,"{"),zt=new i(2,"}"),_e=new i(2,","),Yt=new i(2,";"),Wt=new i(6," "),Ut=new i(7,"&"),Se=class{space_sensitive;newline_sensitive;constructor(e=!0,r=!0){this.space_sensitive=e,this.newline_sensitive=r}parse(e){let[r,t]=this.parseGroup(e,0,e.length);return r}parseGroup(e,r,t,s=!1){let o=[],a=r;for(;a<t;){let[p,c]=this.parseNextExpr(e,a);a=c,!((p.head.type===6||p.head.type===8)&&(!this.space_sensitive&&p.head.value.replace(/ /g,"").length===0||!this.newline_sensitive&&p.head.value===`
|
|
13
|
+
`))&&o.push(p)}let u;return s?u=he(o,!0):o.length===1?u=o[0]:u=he(o),[u,t+1]}parseNextExpr(e,r){let[t,s]=this.parseNextExprWithoutSupSub(e,r),o=null,a=null,u=Ge(e,s);if(u>0&&(t=new _([t].concat(He(u))),s+=u),s<e.length&&e[s].eq(Xe)?([o,s]=this.parseSupOrSub(e,s+1),s<e.length&&e[s].eq(je)&&([a,s]=this.parseSupOrSub(e,s+1))):s<e.length&&e[s].eq(je)&&([a,s]=this.parseSupOrSub(e,s+1),s<e.length&&e[s].eq(Xe)&&([o,s]=this.parseSupOrSub(e,s+1))),o!==null||a!==null){let p={base:t,sup:a,sub:o};return[new A(p),s]}else return[t,s]}parseSupOrSub(e,r){let t,s;if(e[r].eq($)){let a=Q(e,r);[t,s]=this.parseGroup(e,r+1,a)}else[t,s]=this.parseNextExprWithoutSupSub(e,r);let o=Ge(e,s);return o>0&&(t=new _([t].concat(He(o))),s+=o),[t,s]}parseNextExprWithoutSupSub(e,r){let t=e[r],s=t.toNode();if(t.eq($)){let o=Q(e,r);return this.parseGroup(e,r+1,o,!0)}if(t.type===2&&!Re(t.value[0]))return[s,r+1];if([2,1].includes(t.type)&&r+1<e.length&&e[r+1].eq($)){if(t.value==="mat"){let[p,c,h]=this.parseMatrix(e,r+1,Yt,_e),d=new y(t,p);return d.setOptions(c),[d,h]}if(t.value==="cases"){let[p,c,h]=this.parseMatrix(e,r+1,_e,Ut),d=new y(t,p);return d.setOptions(c),[d,h]}if(t.value==="lr")return this.parseLrArguments(e,r+1);if(["#heading","#text"].includes(t.value)){let[p,c]=this.parseArguments(e,r+1),h=Bt(p);T(e[c].eq(Ve));let d=new i(2,"$"),v=Ae(e,c+1,[d],[d]),[C,O]=this.parseGroup(e,c+2,v);T(e[v+1].eq(Ze));let J=new z(t,[C]);return J.setOptions(h),[J,v+2]}let[o,a]=this.parseArguments(e,r+1);return[new f(t,o),a]}return[s,r+1]}parseArguments(e,r){let t=Q(e,r);return[this.parseArgumentsWithSeparator(e,r+1,t,_e),t+1]}parseLrArguments(e,r){let t=e[r],s=Q(e,r);if(e[r+1].isOneOf(i.LEFT_DELIMITERS)){let o=r+1,a=Ct(e,o),[u,p]=this.parseGroup(e,o+1,a);return[new q(t,{body:u,left:e[o],right:e[a]}),s+1]}else{let[o,a]=this.parseGroup(e,r+1,s-1);return[new q(t,{body:o,left:null,right:null}),s+1]}}parseMatrix(e,r,t,s){let o=Q(e,r);e=e.slice(0,o);let a=[],u={},p=r+1;for(;p<o;)for(;p<o;){let C=function(O){let J=new i(2,":").toNode(),Ce={},ge=[];for(let L=0;L<O.length;L++){if(O[L].type!=="group")continue;let ee=O[L],te=G(ee.items,J);if(te===-1||te===0)continue;if(ge.push(L),ee.items[te-1].eq(new i(1,"delim").toNode())){if(ee.items.length!==3)throw new F("Invalid number of arguments for delim");Ce.delim=ee.items[te+1]}else throw new F("Not implemented for other named parameters")}for(let L=ge.length-1;L>=0;L--)O.splice(ge[L],1);return[O,Ce]};var c=C;let h=G(e,t,p);h===-1&&(h=o);let d=this.parseArgumentsWithSeparator(e,p,h,s),v={};[d,v]=C(d),a.push(d),Object.assign(u,v),p=h+1}return[a,u,o+1]}parseArgumentsWithSeparator(e,r,t,s){let o=[],a=r;for(;a<t;){let u=[];for(;a<t;){if(e[a].eq(s)){a+=1;break}else if(e[a].eq(Wt)){a+=1;continue}let[c,h]=this.parseNextExpr(e,a);a=h,u.push(c)}let p;u.length===1?p=u[0]:p=he(u),o.push(p)}return o}};function Ke(n){let e=new Se,r=Fe(n);return e.parse(r)}var Te=class{buffer="";queue=[];append(e){this.queue=this.queue.concat(e.serialize())}flushQueue(){for(let e=0;e<this.queue.length;e++)this.buffer=be(this.buffer,this.queue[e]);this.queue=[]}finalize(){return this.flushQueue(),this.buffer}};function Qe(n,e){let r={nonStrict:!0,preferShorthands:!0,keepSpaces:!1,fracToSlash:!0,inftyToOo:!1,optimize:!0,nonAsciiWrapper:"",customTexMacros:{}};if(e!==void 0){if(typeof e!="object")throw new Error("options must be an object");for(let a in r)a in e&&(r[a]=e[a])}let t=We(n,r.customTexMacros),s=m(t,r),o=new pe(r);return o.serialize(s),o.finalize()}function Je(n){let e=Ke(n),r=b(e),t=new Te;return t.append(r),t.finalize()}window.tex2typst=Qe;window.typst2tex=Je;})();
|