From 3019ac16f262b089a3d27318b656d5d37d4daeb1 Mon Sep 17 00:00:00 2001 From: J08nY Date: Sat, 20 Jul 2019 16:06:08 +0200 Subject: [PATCH 1/3] Add \DOWNTO for loop. --- README.md | 2 +- docs/katex-samples.html | 11 +++++++++++ src/Parser.js | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9224d4b..c291deb 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ $i \gets i + 1$ # Function call \CALL{}{} # Keywords -\AND, \OR, \XOR, \NOT, \TO, \TRUE, \FALSE +\AND, \OR, \XOR, \NOT, \TO, \DOWNTO, \TRUE, \FALSE # LaTeX's sizing commands \tiny, \scriptsize, \footnotesize, \small \normalsize, \large, \Large, \LARGE, \huge, \HUGE diff --git a/docs/katex-samples.html b/docs/katex-samples.html index 81ef0f1..0b7ff7a 100644 --- a/docs/katex-samples.html +++ b/docs/katex-samples.html @@ -77,6 +77,17 @@ \STATE $i \gets i + 1$ \ENDFOR \ENDPROCEDURE + \PROCEDURE{Test-For-To}{$n$} + \STATE $i \gets 0$ + \FOR{$i$ \TO $n$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE + \PROCEDURE{Test-For-DownTo}{$n$} + \FOR{$i \gets n$ \DOWNTO $0$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE \PROCEDURE{Test-For-All}{$n$} \FORALL{$i \in \{0, 1, \cdots, n\}$} \PRINT $i$ diff --git a/src/Parser.js b/src/Parser.js index f3da028..23a7114 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -54,7 +54,7 @@ * * :== \CALL{}({}) * :== \\ | \{ | \} | \$ | \& | \# | \% | \_ - * :== \AND | \OR | \NOT | \TRUE | \FALSE | \TO + * :== \AND | \OR | \NOT | \TRUE | \FALSE | \TO | \DOWNTO * :== \textbackslash * :== ` | `` | ' | '' * (More LaTeX symbols can be added if necessary. See @@ -447,7 +447,7 @@ var ACCEPTED_TOKEN_BY_ATOM = { 'special': { tokenType: 'special' }, 'cond-symbol': { tokenType: 'func', - tokenValues: ['and', 'or', 'not', 'true', 'false', 'to'], + tokenValues: ['and', 'or', 'not', 'true', 'false', 'to', 'downto'], }, 'quote-symbol': { tokenType: 'quote', From 0bfbda2e18fedc9b3bbcdba64d6706db269b624a Mon Sep 17 00:00:00 2001 From: Saswat Padhi Date: Thu, 4 Jun 2020 16:52:39 -0700 Subject: [PATCH 2/3] Moved sample fragment to body.html.part --- docs/katex-samples.html | 11 ----------- static/body.html.part | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/katex-samples.html b/docs/katex-samples.html index 0b7ff7a..81ef0f1 100644 --- a/docs/katex-samples.html +++ b/docs/katex-samples.html @@ -77,17 +77,6 @@ \STATE $i \gets i + 1$ \ENDFOR \ENDPROCEDURE - \PROCEDURE{Test-For-To}{$n$} - \STATE $i \gets 0$ - \FOR{$i$ \TO $n$} - \PRINT $i$ - \ENDFOR - \ENDPROCEDURE - \PROCEDURE{Test-For-DownTo}{$n$} - \FOR{$i \gets n$ \DOWNTO $0$} - \PRINT $i$ - \ENDFOR - \ENDPROCEDURE \PROCEDURE{Test-For-All}{$n$} \FORALL{$i \in \{0, 1, \cdots, n\}$} \PRINT $i$ diff --git a/static/body.html.part b/static/body.html.part index ff39276..c1251f4 100644 --- a/static/body.html.part +++ b/static/body.html.part @@ -62,6 +62,17 @@ \STATE $i \gets i + 1$ \ENDFOR \ENDPROCEDURE + \PROCEDURE{Test-For-To}{$n$} + \STATE $i \gets 0$ + \FOR{$i$ \TO $n$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE + \PROCEDURE{Test-For-DownTo}{$n$} + \FOR{$i \gets n$ \DOWNTO $0$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE \PROCEDURE{Test-For-All}{$n$} \FORALL{$i \in \{0, 1, \cdots, n\}$} \PRINT $i$ From f73d881e6faa4f324cd8ea02cf4c298591abfb09 Mon Sep 17 00:00:00 2001 From: Saswat Padhi Date: Thu, 4 Jun 2020 16:54:29 -0700 Subject: [PATCH 3/3] updated docs --- docs/katex-samples.html | 11 +++++++++++ docs/mathjax-v2-samples.html | 11 +++++++++++ docs/mathjax-v3-samples.html | 11 +++++++++++ docs/pseudocode.js | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/katex-samples.html b/docs/katex-samples.html index 81ef0f1..0b7ff7a 100644 --- a/docs/katex-samples.html +++ b/docs/katex-samples.html @@ -77,6 +77,17 @@ \STATE $i \gets i + 1$ \ENDFOR \ENDPROCEDURE + \PROCEDURE{Test-For-To}{$n$} + \STATE $i \gets 0$ + \FOR{$i$ \TO $n$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE + \PROCEDURE{Test-For-DownTo}{$n$} + \FOR{$i \gets n$ \DOWNTO $0$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE \PROCEDURE{Test-For-All}{$n$} \FORALL{$i \in \{0, 1, \cdots, n\}$} \PRINT $i$ diff --git a/docs/mathjax-v2-samples.html b/docs/mathjax-v2-samples.html index 1288693..e36b547 100644 --- a/docs/mathjax-v2-samples.html +++ b/docs/mathjax-v2-samples.html @@ -87,6 +87,17 @@ \STATE $i \gets i + 1$ \ENDFOR \ENDPROCEDURE + \PROCEDURE{Test-For-To}{$n$} + \STATE $i \gets 0$ + \FOR{$i$ \TO $n$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE + \PROCEDURE{Test-For-DownTo}{$n$} + \FOR{$i \gets n$ \DOWNTO $0$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE \PROCEDURE{Test-For-All}{$n$} \FORALL{$i \in \{0, 1, \cdots, n\}$} \PRINT $i$ diff --git a/docs/mathjax-v3-samples.html b/docs/mathjax-v3-samples.html index 39cf209..fa62096 100644 --- a/docs/mathjax-v3-samples.html +++ b/docs/mathjax-v3-samples.html @@ -87,6 +87,17 @@ \STATE $i \gets i + 1$ \ENDFOR \ENDPROCEDURE + \PROCEDURE{Test-For-To}{$n$} + \STATE $i \gets 0$ + \FOR{$i$ \TO $n$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE + \PROCEDURE{Test-For-DownTo}{$n$} + \FOR{$i \gets n$ \DOWNTO $0$} + \PRINT $i$ + \ENDFOR + \ENDPROCEDURE \PROCEDURE{Test-For-All}{$n$} \FORALL{$i \in \{0, 1, \cdots, n\}$} \PRINT $i$ diff --git a/docs/pseudocode.js b/docs/pseudocode.js index 8011d7d..bf3460b 100644 --- a/docs/pseudocode.js +++ b/docs/pseudocode.js @@ -1 +1 @@ -(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.pseudocode=e()}})(function(){var e,t,n;return function(){function e(t,n,i){function r(s,a){if(!n[s]){if(!t[s]){var h="function"==typeof require&&require;if(!a&&h)return h(s,!0);if(o)return o(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var p=n[s]={exports:{}};t[s][0].call(p.exports,function(e){var n=t[s][1][e];return r(n||e)},p,p.exports,e,t,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s0&&h[l-1]==="\\"){var p=l+s.length;h=h.slice(p);a+=p;continue}var u=[e.slice(0,a+l+s.length),e.slice(o.length,a+l)];return u}}return null}};var a={special:/^(\\\\|\\{|\\}|\\\$|\\&|\\#|\\%|\\_)/,math:s,func:/^\\([a-zA-Z]+)/,open:/^\{/,close:/^\}/,quote:/^(`|``|'|'')/,ordinary:/^[^\\{}$&#%_\s]+/};var h=/^%.*/;var l=/^\s+/;o.prototype._skip=function(e){this._pos+=e;this._remain=this._remain.slice(e)};o.prototype._next=function(){var e=false;while(1){var t=l.exec(this._remain);if(t){e=true;var n=t[0].length;this._skip(n)}var i=h.exec(this._remain);if(!i)break;var o=i[0].length;this._skip(o)}this._currentAtom=this._nextAtom;if(this._remain===""){this._nextAtom={type:"EOF",text:null,whitespace:false};return false}for(var s in a){var p=a[s];var u=p.exec(this._remain);if(!u)continue;var c=u[0];var f=u[1]?u[1]:c;this._nextAtom={type:s,text:f,whitespace:e};this._pos+=c.length;this._remain=this._remain.slice(u[0].length);return true}throw new r("Unrecoganizable atom",this._pos,this._input)};o.prototype._matchText=function(e){if(e===null||e===undefined)return true;if(i.isString(e))return e.toLowerCase()===this._nextAtom.text.toLowerCase();else{e=e.map(function(e){return e.toLowerCase()});return e.indexOf(this._nextAtom.text.toLowerCase())>=0}};t.exports=o},{"./ParseError":3,"./utils":6}],3:[function(e,t,n){function i(e,t,n){var i="Error: "+e;if(t!==undefined&&n!==undefined){i+=" at position "+t+": `";n=n.slice(0,t)+"\u21b1"+n.slice(t);var r=Math.max(0,t-15);var o=t+15;i+=n.slice(r,o)+"`"}this.message=i}i.prototype=Object.create(Error.prototype);i.prototype.constructor=i;t.exports=i},{}],4:[function(e,t,n){var i=e("./utils");var r=e("./ParseError");var o=function(e,t){this.type=e;this.value=t;this.children=[]};o.prototype.toString=function(e){if(!e)e=0;var t="";for(var n=0;n";if(this.value)r+=" ("+i.toString(this.value)+")";r+="\n";if(this.children){for(var o=0;o0){e.addChild(t);continue}break}return e};a.prototype._parseCaption=function(){var e=this._lexer;if(!e.accept("func","caption"))return null;var t=new o("caption");e.expect("open");t.addChild(this._parseCloseText());e.expect("close");return t};a.prototype._parseBlock=function(){var e=new o("block");while(true){var t=this._parseControl();if(t){e.addChild(t);continue}var n=this._parseFunction();if(n){e.addChild(n);continue}var i=this._parseCommand(l);if(i){e.addChild(i);continue}var r=this._parseComment();if(r){e.addChild(r);continue}break}return e};a.prototype._parseControl=function(){var e;if(e=this._parseIf())return e;if(e=this._parseLoop())return e;if(e=this._parseRepeat())return e};a.prototype._parseFunction=function(){var e=this._lexer;if(!e.accept("func",["function","procedure"]))return null;var t=this._lexer.get().text;e.expect("open");var n=e.expect("ordinary");e.expect("close");e.expect("open");var i=this._parseCloseText();e.expect("close");var r=this._parseBlock();e.expect("func","end"+t);var s=new o("function",{type:t,name:n});s.addChild(i);s.addChild(r);return s};a.prototype._parseIf=function(){if(!this._lexer.accept("func","if"))return null;var e=new o("if");this._lexer.expect("open");e.addChild(this._parseCond());this._lexer.expect("close");e.addChild(this._parseBlock());var t=0;while(this._lexer.accept("func",["elif","elsif","elseif"])){this._lexer.expect("open");e.addChild(this._parseCond());this._lexer.expect("close");e.addChild(this._parseBlock());t++}var n=false;if(this._lexer.accept("func","else")){n=true;e.addChild(this._parseBlock())}this._lexer.expect("func","endif");e.value={numElif:t,hasElse:n};return e};a.prototype._parseLoop=function(){if(!this._lexer.accept("func",["FOR","FORALL","WHILE"]))return null;var e=this._lexer.get().text.toLowerCase();var t=new o("loop",e);this._lexer.expect("open");t.addChild(this._parseCond());this._lexer.expect("close");t.addChild(this._parseBlock());var n=e!=="forall"?"end"+e:"endfor";this._lexer.expect("func",n);return t};a.prototype._parseRepeat=function(){if(!this._lexer.accept("func",["REPEAT"]))return null;var e=this._lexer.get().text.toLowerCase();var t=new o("repeat",e);t.addChild(this._parseBlock());this._lexer.expect("func","until");this._lexer.expect("open");t.addChild(this._parseCond());this._lexer.expect("close");return t};var h=["ensure","require","input","output"];var l=["state","print","return"];a.prototype._parseCommand=function(e){if(!this._lexer.accept("func",e))return null;var t=this._lexer.get().text.toLowerCase();var n=new o("command",t);n.addChild(this._parseOpenText());return n};a.prototype._parseComment=function(){if(!this._lexer.accept("func","comment"))return null;var e=new o("comment");this._lexer.expect("open");e.addChild(this._parseCloseText());this._lexer.expect("close");return e};a.prototype._parseCall=function(){var e=this._lexer;if(!e.accept("func","call"))return null;var t=e.get().whitespace;e.expect("open");var n=e.expect("ordinary");e.expect("close");var i=new o("call");i.whitespace=t;i.value=n;e.expect("open");var r=this._parseCloseText();i.addChild(r);e.expect("close");return i};a.prototype._parseCond=a.prototype._parseCloseText=function(){return this._parseText("close")};a.prototype._parseOpenText=function(){return this._parseText("open")};a.prototype._parseText=function(e){var t=new o(e+"-text");var n=false;var i;while(true){i=this._parseAtom()||this._parseCall();if(i){if(n)i.whitespace|=n;t.addChild(i);continue}if(this._lexer.accept("open")){i=this._parseCloseText();n=this._lexer.get().whitespace;i.whitespace=n;t.addChild(i);this._lexer.expect("close");n=this._lexer.get().whitespace;continue}break}return t};var p={ordinary:{tokenType:"ordinary"},math:{tokenType:"math"},special:{tokenType:"special"},"cond-symbol":{tokenType:"func",tokenValues:["and","or","not","true","false","to"]},"quote-symbol":{tokenType:"quote"},"sizing-dclr":{tokenType:"func",tokenValues:["tiny","scriptsize","footnotesize","small","normalsize","large","Large","LARGE","huge","Huge"]},"font-dclr":{tokenType:"func",tokenValues:["normalfont","rmfamily","sffamily","ttfamily","upshape","itshape","slshape","scshape","bfseries","mdseries","lfseries"]},"font-cmd":{tokenType:"func",tokenValues:["textnormal","textrm","textsf","texttt","textup","textit","textsl","textsc","uppercase","lowercase","textbf","textmd","textlf"]},"text-symbol":{tokenType:"func",tokenValues:["textbackslash"]}};a.prototype._parseAtom=function(){for(var e in p){var t=p[e];var n=this._lexer.accept(t.tokenType,t.tokenValues);if(n===null)continue;var i=this._lexer.get().whitespace;if(e!=="ordinary"&&e!=="math")n=n.toLowerCase();return new s(e,n,i)}return null};t.exports=a},{"./ParseError":3,"./utils":6}],5:[function(e,t,n){var i=e("./utils");function r(e){this._css={};this._fontSize=this._outerFontSize=e!==undefined?e:1}r.prototype.outerFontSize=function(e){if(e!==undefined)this._outerFontSize=e;return this._outerFontSize};r.prototype.fontSize=function(){return this._fontSize};r.prototype._fontCommandTable={normalfont:{"font-family":"KaTeX_Main"},rmfamily:{"font-family":"KaTeX_Main"},sffamily:{"font-family":"KaTeX_SansSerif"},ttfamily:{"font-family":"KaTeX_Typewriter"},bfseries:{"font-weight":"bold"},mdseries:{"font-weight":"medium"},lfseries:{"font-weight":"lighter"},upshape:{"font-style":"normal","font-variant":"normal"},itshape:{"font-style":"italic","font-variant":"normal"},scshape:{"font-style":"normal","font-variant":"small-caps"},slshape:{"font-style":"oblique","font-variant":"normal"},textnormal:{"font-family":"KaTeX_Main"},textrm:{"font-family":"KaTeX_Main"},textsf:{"font-family":"KaTeX_SansSerif"},texttt:{"font-family":"KaTeX_Typewriter"},textbf:{"font-weight":"bold"},textmd:{"font-weight":"medium"},textlf:{"font-weight":"lighter"},textup:{"font-style":"normal","font-variant":"normal"},textit:{"font-style":"italic","font-variant":"normal"},textsc:{"font-style":"normal","font-variant":"small-caps"},textsl:{"font-style":"oblique","font-variant":"normal"},uppercase:{"text-transform":"uppercase"},lowercase:{"text-transform":"lowercase"}};r.prototype._sizingScalesTable={tiny:.68,scriptsize:.8,footnotesize:.85,small:.92,normalsize:1,large:1.17,Large:1.41,LARGE:1.58,huge:1.9,Huge:2.28};r.prototype.updateByCommand=function(e){var t=this._fontCommandTable[e];if(t!==undefined){for(var n in t)this._css[n]=t[n];return}var i=this._sizingScalesTable[e];if(i!==undefined){this._outerFontSize=this._fontSize;this._fontSize=i;return}throw new ParserError("unrecogniazed text-style command")};r.prototype.toCSS=function(){var e="";for(var t in this._css){var n=this._css[t];if(n===undefined)continue;e+=t+":"+n+";"}if(this._fontSize!==this._outerFontSize){e+="font-size:"+this._fontSize/this._outerFontSize+"em;"}return e};function o(e,t){this._nodes=e;this._textStyle=t}o.prototype._renderCloseText=function(e,t){var n=new r(this._textStyle.fontSize());var i=new o(e.children,n);if(e.whitespace)this._html.putText(" ");this._html.putHTML(i.renderToHTML(t))};o.prototype.renderToHTML=function(e){this._html=new s;var t;while((t=this._nodes.shift())!==undefined){var n=t.type;var i=t.value;if(t.whitespace)this._html.putText(" ");switch(n){case"ordinary":this._html.putText(i);break;case"math":if(typeof e==="undefined"){throw"No math backend found. Please setup KaTeX or MathJax."}else if(e.name==="katex"){this._html.putHTML(e.driver.renderToString(i))}else if(e.name==="mathjax"){this._html.putText("$"+i+"$")}else{throw"Unknown math backend "+e}break;case"cond-symbol":this._html.beginSpan("ps-keyword").putText(i.toLowerCase()).endSpan();break;case"special":if(i==="\\\\"){this._html.putHTML("
");break}var a={"\\{":"{","\\}":"}","\\$":"$","\\&":"&","\\#":"#","\\%":"%","\\_":"_"};var h=a[i];this._html.putText(h);break;case"text-symbol":var l={textbackslash:"\\"};var p=l[i];this._html.putText(p);break;case"quote-symbol":var u={"`":"\u2018","``":"\u201c","'":"\u2019","''":"\u201d"};var c=u[i];this._html.putText(c);break;case"call":this._html.beginSpan("ps-funcname").putText(i).endSpan();this._html.write("(");var f=t.children[0];this._renderCloseText(f,e);this._html.write(")");break;case"close-text":this._renderCloseText(t,e);break;case"font-dclr":case"sizing-dclr":this._textStyle.updateByCommand(i);this._html.beginSpan(null,this._textStyle.toCSS());var d=new o(this._nodes,this._textStyle);this._html.putHTML(d.renderToHTML(e));this._html.endSpan();break;case"font-cmd":var _=this._nodes[0];if(_.type!=="close-text")continue;var m=new r(this._textStyle.fontSize());m.updateByCommand(i);this._html.beginSpan(null,m.toCSS());var x=new o(_.children,m);this._html.putHTML(x.renderToHTML(e));this._html.endSpan();break;default:throw new ParseError("Unexpected ParseNode of type "+t.type)}}return this._html.toMarkup()};function s(){this._body=[];this._textBuf=[]}s.prototype.beginDiv=function(e,t,n){this._beginTag("div",e,t,n);this._body.push("\n");return this};s.prototype.endDiv=function(){this._endTag("div");this._body.push("\n");return this};s.prototype.beginP=function(e,t,n){this._beginTag("p",e,t,n);this._body.push("\n");return this};s.prototype.endP=function(){this._flushText();this._endTag("p");this._body.push("\n");return this};s.prototype.beginSpan=function(e,t,n){this._flushText();return this._beginTag("span",e,t,n)};s.prototype.endSpan=function(){this._flushText();return this._endTag("span")};s.prototype.putHTML=function(e){this._flushText();this._body.push(e);return this};s.prototype.putText=function(e){this._textBuf.push(e);return this};s.prototype.write=function(e){this._body.push(e)};s.prototype.toMarkup=function(){this._flushText();var e=this._body.join("");return e.trim()};s.prototype.toDOM=function(){var e=this.toMarkup();var t=document.createElement("div");t.innerHTML=e;return t.firstChild};s.prototype._flushText=function(){if(this._textBuf.length===0)return;var e=this._textBuf.join("");this._body.push(this._escapeHtml(e));this._textBuf=[]};s.prototype._beginTag=function(e,t,n,r){var o="<"+e;if(t)o+=' class="'+t+'"';if(n){var s;if(i.isString(n))s=n;else{s="";for(var a in n){attrVal=n[a];s+=a+":"+attrVal+";"}}if(r)s+=r;o+=' style="'+s+'"'}o+=">";this._body.push(o);return this};s.prototype._endTag=function(e){this._body.push("");return this};var a={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};s.prototype._escapeHtml=function(e){return String(e).replace(/[&<>"'/]/g,function(e){return a[e]})};function h(e){e=e||{};this.indentSize=e.indentSize?this._parseEmVal(e.indentSize):1.2;this.commentDelimiter=e.commentDelimiter||" // ";this.lineNumberPunc=e.lineNumberPunc||":";this.lineNumber=e.lineNumber!==undefined?e.lineNumber:false;this.noEnd=e.noEnd!==undefined?e.noEnd:false;if(e.captionCount!==undefined)l.captionCount=e.captionCount}h.prototype._parseEmVal=function(e){e=e.trim();if(e.indexOf("em")!==e.length-2)throw"option unit error; no `em` found";return Number(e.substring(0,e.length-2))};function l(t,n){this._root=t.parse();this._options=new h(n);this._openLine=false;this._blockLevel=0;this._textLevel=-1;this._globalTextStyle=new r;this.backend=undefined;try{if(typeof katex==="undefined")katex=e("katex")}catch(e){}try{if(typeof MathJax==="undefined")MathJax=e("mathjax")}catch(e){}if(typeof katex!=="undefined"){this.backend={name:"katex",driver:katex}}else if(typeof MathJax!=="undefined"){this.backend={name:"mathjax",driver:MathJax}}}l.captionCount=0;l.prototype.toMarkup=function(){var e=this._html=new s;this._buildTree(this._root);delete this._html;return e.toMarkup()};l.prototype.toDOM=function(){var e=this.toMarkup();var t=document.createElement("div");t.innerHTML=e;return t.firstChild};l.prototype._beginGroup=function(e,t,n){this._closeLineIfAny();this._html.beginDiv("ps-"+e+(t?" "+t:""),n)};l.prototype._endGroup=function(e){this._closeLineIfAny();this._html.endDiv()};l.prototype._beginBlock=function(){var e=this._options.lineNumber&&this._blockLevel===0?.6:0;var t=this._options.indentSize+e;this._beginGroup("block",null,{"margin-left":t+"em"});this._blockLevel++};l.prototype._endBlock=function(){this._closeLineIfAny();this._endGroup();this._blockLevel--};l.prototype._newLine=function(){this._closeLineIfAny();this._openLine=true;this._globalTextStyle.outerFontSize(1);var e=this._options.indentSize;if(this._blockLevel>0){this._numLOC++;this._html.beginP("ps-line ps-code",this._globalTextStyle.toCSS());if(this._options.lineNumber){this._html.beginSpan("ps-linenum",{left:-((this._blockLevel-1)*(e*1.25))+"em"}).putText(this._numLOC+this._options.lineNumberPunc).endSpan()}}else{this._html.beginP("ps-line",{"text-indent":-e+"em","padding-left":e+"em"},this._globalTextStyle.toCSS())}};l.prototype._closeLineIfAny=function(){if(!this._openLine)return;this._html.endP();this._openLine=false};l.prototype._typeKeyword=function(e){this._html.beginSpan("ps-keyword").putText(e).endSpan()};l.prototype._typeFuncName=function(e){this._html.beginSpan("ps-funcname").putText(e).endSpan()};l.prototype._typeText=function(e){this._html.write(e)};l.prototype._buildTreeForAllChildren=function(e){var t=e.children;for(var n=0;n0&&t[0].type==="comment"){var n=t.shift();this._buildTree(n)}};l.prototype._buildTree=function(e){var t;var n;var i;switch(e.type){case"root":this._beginGroup("root");this._buildTreeForAllChildren(e);this._endGroup();break;case"algorithm":var s;for(t=0;t0&&h[l-1]==="\\"){var p=l+s.length;h=h.slice(p);a+=p;continue}var u=[e.slice(0,a+l+s.length),e.slice(o.length,a+l)];return u}}return null}};var a={special:/^(\\\\|\\{|\\}|\\\$|\\&|\\#|\\%|\\_)/,math:s,func:/^\\([a-zA-Z]+)/,open:/^\{/,close:/^\}/,quote:/^(`|``|'|'')/,ordinary:/^[^\\{}$&#%_\s]+/};var h=/^%.*/;var l=/^\s+/;o.prototype._skip=function(e){this._pos+=e;this._remain=this._remain.slice(e)};o.prototype._next=function(){var e=false;while(1){var t=l.exec(this._remain);if(t){e=true;var n=t[0].length;this._skip(n)}var i=h.exec(this._remain);if(!i)break;var o=i[0].length;this._skip(o)}this._currentAtom=this._nextAtom;if(this._remain===""){this._nextAtom={type:"EOF",text:null,whitespace:false};return false}for(var s in a){var p=a[s];var u=p.exec(this._remain);if(!u)continue;var c=u[0];var f=u[1]?u[1]:c;this._nextAtom={type:s,text:f,whitespace:e};this._pos+=c.length;this._remain=this._remain.slice(u[0].length);return true}throw new r("Unrecoganizable atom",this._pos,this._input)};o.prototype._matchText=function(e){if(e===null||e===undefined)return true;if(i.isString(e))return e.toLowerCase()===this._nextAtom.text.toLowerCase();else{e=e.map(function(e){return e.toLowerCase()});return e.indexOf(this._nextAtom.text.toLowerCase())>=0}};t.exports=o},{"./ParseError":3,"./utils":6}],3:[function(e,t,n){function i(e,t,n){var i="Error: "+e;if(t!==undefined&&n!==undefined){i+=" at position "+t+": `";n=n.slice(0,t)+"\u21b1"+n.slice(t);var r=Math.max(0,t-15);var o=t+15;i+=n.slice(r,o)+"`"}this.message=i}i.prototype=Object.create(Error.prototype);i.prototype.constructor=i;t.exports=i},{}],4:[function(e,t,n){var i=e("./utils");var r=e("./ParseError");var o=function(e,t){this.type=e;this.value=t;this.children=[]};o.prototype.toString=function(e){if(!e)e=0;var t="";for(var n=0;n";if(this.value)r+=" ("+i.toString(this.value)+")";r+="\n";if(this.children){for(var o=0;o0){e.addChild(t);continue}break}return e};a.prototype._parseCaption=function(){var e=this._lexer;if(!e.accept("func","caption"))return null;var t=new o("caption");e.expect("open");t.addChild(this._parseCloseText());e.expect("close");return t};a.prototype._parseBlock=function(){var e=new o("block");while(true){var t=this._parseControl();if(t){e.addChild(t);continue}var n=this._parseFunction();if(n){e.addChild(n);continue}var i=this._parseCommand(l);if(i){e.addChild(i);continue}var r=this._parseComment();if(r){e.addChild(r);continue}break}return e};a.prototype._parseControl=function(){var e;if(e=this._parseIf())return e;if(e=this._parseLoop())return e;if(e=this._parseRepeat())return e};a.prototype._parseFunction=function(){var e=this._lexer;if(!e.accept("func",["function","procedure"]))return null;var t=this._lexer.get().text;e.expect("open");var n=e.expect("ordinary");e.expect("close");e.expect("open");var i=this._parseCloseText();e.expect("close");var r=this._parseBlock();e.expect("func","end"+t);var s=new o("function",{type:t,name:n});s.addChild(i);s.addChild(r);return s};a.prototype._parseIf=function(){if(!this._lexer.accept("func","if"))return null;var e=new o("if");this._lexer.expect("open");e.addChild(this._parseCond());this._lexer.expect("close");e.addChild(this._parseBlock());var t=0;while(this._lexer.accept("func",["elif","elsif","elseif"])){this._lexer.expect("open");e.addChild(this._parseCond());this._lexer.expect("close");e.addChild(this._parseBlock());t++}var n=false;if(this._lexer.accept("func","else")){n=true;e.addChild(this._parseBlock())}this._lexer.expect("func","endif");e.value={numElif:t,hasElse:n};return e};a.prototype._parseLoop=function(){if(!this._lexer.accept("func",["FOR","FORALL","WHILE"]))return null;var e=this._lexer.get().text.toLowerCase();var t=new o("loop",e);this._lexer.expect("open");t.addChild(this._parseCond());this._lexer.expect("close");t.addChild(this._parseBlock());var n=e!=="forall"?"end"+e:"endfor";this._lexer.expect("func",n);return t};a.prototype._parseRepeat=function(){if(!this._lexer.accept("func",["REPEAT"]))return null;var e=this._lexer.get().text.toLowerCase();var t=new o("repeat",e);t.addChild(this._parseBlock());this._lexer.expect("func","until");this._lexer.expect("open");t.addChild(this._parseCond());this._lexer.expect("close");return t};var h=["ensure","require","input","output"];var l=["state","print","return"];a.prototype._parseCommand=function(e){if(!this._lexer.accept("func",e))return null;var t=this._lexer.get().text.toLowerCase();var n=new o("command",t);n.addChild(this._parseOpenText());return n};a.prototype._parseComment=function(){if(!this._lexer.accept("func","comment"))return null;var e=new o("comment");this._lexer.expect("open");e.addChild(this._parseCloseText());this._lexer.expect("close");return e};a.prototype._parseCall=function(){var e=this._lexer;if(!e.accept("func","call"))return null;var t=e.get().whitespace;e.expect("open");var n=e.expect("ordinary");e.expect("close");var i=new o("call");i.whitespace=t;i.value=n;e.expect("open");var r=this._parseCloseText();i.addChild(r);e.expect("close");return i};a.prototype._parseCond=a.prototype._parseCloseText=function(){return this._parseText("close")};a.prototype._parseOpenText=function(){return this._parseText("open")};a.prototype._parseText=function(e){var t=new o(e+"-text");var n=false;var i;while(true){i=this._parseAtom()||this._parseCall();if(i){if(n)i.whitespace|=n;t.addChild(i);continue}if(this._lexer.accept("open")){i=this._parseCloseText();n=this._lexer.get().whitespace;i.whitespace=n;t.addChild(i);this._lexer.expect("close");n=this._lexer.get().whitespace;continue}break}return t};var p={ordinary:{tokenType:"ordinary"},math:{tokenType:"math"},special:{tokenType:"special"},"cond-symbol":{tokenType:"func",tokenValues:["and","or","not","true","false","to","downto"]},"quote-symbol":{tokenType:"quote"},"sizing-dclr":{tokenType:"func",tokenValues:["tiny","scriptsize","footnotesize","small","normalsize","large","Large","LARGE","huge","Huge"]},"font-dclr":{tokenType:"func",tokenValues:["normalfont","rmfamily","sffamily","ttfamily","upshape","itshape","slshape","scshape","bfseries","mdseries","lfseries"]},"font-cmd":{tokenType:"func",tokenValues:["textnormal","textrm","textsf","texttt","textup","textit","textsl","textsc","uppercase","lowercase","textbf","textmd","textlf"]},"text-symbol":{tokenType:"func",tokenValues:["textbackslash"]}};a.prototype._parseAtom=function(){for(var e in p){var t=p[e];var n=this._lexer.accept(t.tokenType,t.tokenValues);if(n===null)continue;var i=this._lexer.get().whitespace;if(e!=="ordinary"&&e!=="math")n=n.toLowerCase();return new s(e,n,i)}return null};t.exports=a},{"./ParseError":3,"./utils":6}],5:[function(e,t,n){var i=e("./utils");function r(e){this._css={};this._fontSize=this._outerFontSize=e!==undefined?e:1}r.prototype.outerFontSize=function(e){if(e!==undefined)this._outerFontSize=e;return this._outerFontSize};r.prototype.fontSize=function(){return this._fontSize};r.prototype._fontCommandTable={normalfont:{"font-family":"KaTeX_Main"},rmfamily:{"font-family":"KaTeX_Main"},sffamily:{"font-family":"KaTeX_SansSerif"},ttfamily:{"font-family":"KaTeX_Typewriter"},bfseries:{"font-weight":"bold"},mdseries:{"font-weight":"medium"},lfseries:{"font-weight":"lighter"},upshape:{"font-style":"normal","font-variant":"normal"},itshape:{"font-style":"italic","font-variant":"normal"},scshape:{"font-style":"normal","font-variant":"small-caps"},slshape:{"font-style":"oblique","font-variant":"normal"},textnormal:{"font-family":"KaTeX_Main"},textrm:{"font-family":"KaTeX_Main"},textsf:{"font-family":"KaTeX_SansSerif"},texttt:{"font-family":"KaTeX_Typewriter"},textbf:{"font-weight":"bold"},textmd:{"font-weight":"medium"},textlf:{"font-weight":"lighter"},textup:{"font-style":"normal","font-variant":"normal"},textit:{"font-style":"italic","font-variant":"normal"},textsc:{"font-style":"normal","font-variant":"small-caps"},textsl:{"font-style":"oblique","font-variant":"normal"},uppercase:{"text-transform":"uppercase"},lowercase:{"text-transform":"lowercase"}};r.prototype._sizingScalesTable={tiny:.68,scriptsize:.8,footnotesize:.85,small:.92,normalsize:1,large:1.17,Large:1.41,LARGE:1.58,huge:1.9,Huge:2.28};r.prototype.updateByCommand=function(e){var t=this._fontCommandTable[e];if(t!==undefined){for(var n in t)this._css[n]=t[n];return}var i=this._sizingScalesTable[e];if(i!==undefined){this._outerFontSize=this._fontSize;this._fontSize=i;return}throw new ParserError("unrecogniazed text-style command")};r.prototype.toCSS=function(){var e="";for(var t in this._css){var n=this._css[t];if(n===undefined)continue;e+=t+":"+n+";"}if(this._fontSize!==this._outerFontSize){e+="font-size:"+this._fontSize/this._outerFontSize+"em;"}return e};function o(e,t){this._nodes=e;this._textStyle=t}o.prototype._renderCloseText=function(e,t){var n=new r(this._textStyle.fontSize());var i=new o(e.children,n);if(e.whitespace)this._html.putText(" ");this._html.putHTML(i.renderToHTML(t))};o.prototype.renderToHTML=function(e){this._html=new s;var t;while((t=this._nodes.shift())!==undefined){var n=t.type;var i=t.value;if(t.whitespace)this._html.putText(" ");switch(n){case"ordinary":this._html.putText(i);break;case"math":if(typeof e==="undefined"){throw"No math backend found. Please setup KaTeX or MathJax."}else if(e.name==="katex"){this._html.putHTML(e.driver.renderToString(i))}else if(e.name==="mathjax"){this._html.putText("$"+i+"$")}else{throw"Unknown math backend "+e}break;case"cond-symbol":this._html.beginSpan("ps-keyword").putText(i.toLowerCase()).endSpan();break;case"special":if(i==="\\\\"){this._html.putHTML("
");break}var a={"\\{":"{","\\}":"}","\\$":"$","\\&":"&","\\#":"#","\\%":"%","\\_":"_"};var h=a[i];this._html.putText(h);break;case"text-symbol":var l={textbackslash:"\\"};var p=l[i];this._html.putText(p);break;case"quote-symbol":var u={"`":"\u2018","``":"\u201c","'":"\u2019","''":"\u201d"};var c=u[i];this._html.putText(c);break;case"call":this._html.beginSpan("ps-funcname").putText(i).endSpan();this._html.write("(");var f=t.children[0];this._renderCloseText(f,e);this._html.write(")");break;case"close-text":this._renderCloseText(t,e);break;case"font-dclr":case"sizing-dclr":this._textStyle.updateByCommand(i);this._html.beginSpan(null,this._textStyle.toCSS());var d=new o(this._nodes,this._textStyle);this._html.putHTML(d.renderToHTML(e));this._html.endSpan();break;case"font-cmd":var _=this._nodes[0];if(_.type!=="close-text")continue;var m=new r(this._textStyle.fontSize());m.updateByCommand(i);this._html.beginSpan(null,m.toCSS());var x=new o(_.children,m);this._html.putHTML(x.renderToHTML(e));this._html.endSpan();break;default:throw new ParseError("Unexpected ParseNode of type "+t.type)}}return this._html.toMarkup()};function s(){this._body=[];this._textBuf=[]}s.prototype.beginDiv=function(e,t,n){this._beginTag("div",e,t,n);this._body.push("\n");return this};s.prototype.endDiv=function(){this._endTag("div");this._body.push("\n");return this};s.prototype.beginP=function(e,t,n){this._beginTag("p",e,t,n);this._body.push("\n");return this};s.prototype.endP=function(){this._flushText();this._endTag("p");this._body.push("\n");return this};s.prototype.beginSpan=function(e,t,n){this._flushText();return this._beginTag("span",e,t,n)};s.prototype.endSpan=function(){this._flushText();return this._endTag("span")};s.prototype.putHTML=function(e){this._flushText();this._body.push(e);return this};s.prototype.putText=function(e){this._textBuf.push(e);return this};s.prototype.write=function(e){this._body.push(e)};s.prototype.toMarkup=function(){this._flushText();var e=this._body.join("");return e.trim()};s.prototype.toDOM=function(){var e=this.toMarkup();var t=document.createElement("div");t.innerHTML=e;return t.firstChild};s.prototype._flushText=function(){if(this._textBuf.length===0)return;var e=this._textBuf.join("");this._body.push(this._escapeHtml(e));this._textBuf=[]};s.prototype._beginTag=function(e,t,n,r){var o="<"+e;if(t)o+=' class="'+t+'"';if(n){var s;if(i.isString(n))s=n;else{s="";for(var a in n){attrVal=n[a];s+=a+":"+attrVal+";"}}if(r)s+=r;o+=' style="'+s+'"'}o+=">";this._body.push(o);return this};s.prototype._endTag=function(e){this._body.push("");return this};var a={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};s.prototype._escapeHtml=function(e){return String(e).replace(/[&<>"'/]/g,function(e){return a[e]})};function h(e){e=e||{};this.indentSize=e.indentSize?this._parseEmVal(e.indentSize):1.2;this.commentDelimiter=e.commentDelimiter||" // ";this.lineNumberPunc=e.lineNumberPunc||":";this.lineNumber=e.lineNumber!==undefined?e.lineNumber:false;this.noEnd=e.noEnd!==undefined?e.noEnd:false;if(e.captionCount!==undefined)l.captionCount=e.captionCount}h.prototype._parseEmVal=function(e){e=e.trim();if(e.indexOf("em")!==e.length-2)throw"option unit error; no `em` found";return Number(e.substring(0,e.length-2))};function l(t,n){this._root=t.parse();this._options=new h(n);this._openLine=false;this._blockLevel=0;this._textLevel=-1;this._globalTextStyle=new r;this.backend=undefined;try{if(typeof katex==="undefined")katex=e("katex")}catch(e){}try{if(typeof MathJax==="undefined")MathJax=e("mathjax")}catch(e){}if(typeof katex!=="undefined"){this.backend={name:"katex",driver:katex}}else if(typeof MathJax!=="undefined"){this.backend={name:"mathjax",driver:MathJax}}}l.captionCount=0;l.prototype.toMarkup=function(){var e=this._html=new s;this._buildTree(this._root);delete this._html;return e.toMarkup()};l.prototype.toDOM=function(){var e=this.toMarkup();var t=document.createElement("div");t.innerHTML=e;return t.firstChild};l.prototype._beginGroup=function(e,t,n){this._closeLineIfAny();this._html.beginDiv("ps-"+e+(t?" "+t:""),n)};l.prototype._endGroup=function(e){this._closeLineIfAny();this._html.endDiv()};l.prototype._beginBlock=function(){var e=this._options.lineNumber&&this._blockLevel===0?.6:0;var t=this._options.indentSize+e;this._beginGroup("block",null,{"margin-left":t+"em"});this._blockLevel++};l.prototype._endBlock=function(){this._closeLineIfAny();this._endGroup();this._blockLevel--};l.prototype._newLine=function(){this._closeLineIfAny();this._openLine=true;this._globalTextStyle.outerFontSize(1);var e=this._options.indentSize;if(this._blockLevel>0){this._numLOC++;this._html.beginP("ps-line ps-code",this._globalTextStyle.toCSS());if(this._options.lineNumber){this._html.beginSpan("ps-linenum",{left:-((this._blockLevel-1)*(e*1.25))+"em"}).putText(this._numLOC+this._options.lineNumberPunc).endSpan()}}else{this._html.beginP("ps-line",{"text-indent":-e+"em","padding-left":e+"em"},this._globalTextStyle.toCSS())}};l.prototype._closeLineIfAny=function(){if(!this._openLine)return;this._html.endP();this._openLine=false};l.prototype._typeKeyword=function(e){this._html.beginSpan("ps-keyword").putText(e).endSpan()};l.prototype._typeFuncName=function(e){this._html.beginSpan("ps-funcname").putText(e).endSpan()};l.prototype._typeText=function(e){this._html.write(e)};l.prototype._buildTreeForAllChildren=function(e){var t=e.children;for(var n=0;n0&&t[0].type==="comment"){var n=t.shift();this._buildTree(n)}};l.prototype._buildTree=function(e){var t;var n;var i;switch(e.type){case"root":this._beginGroup("root");this._buildTreeForAllChildren(e);this._endGroup();break;case"algorithm":var s;for(t=0;t