diff options
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/mode/stex')
| -rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/stex/index.html | 95 | ||||
| -rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/stex/stex.js | 182 | ||||
| -rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/stex/test.html | 263 | 
3 files changed, 540 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/stex/index.html b/codemirror_ui/lib/CodeMirror-2.3/mode/stex/index.html new file mode 100644 index 0000000..e49289e --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/stex/index.html @@ -0,0 +1,95 @@ +<!doctype html> +<html> +  <head> +    <title>CodeMirror: sTeX mode</title> +    <link rel="stylesheet" href="../../lib/codemirror.css"> +    <script src="../../lib/codemirror.js"></script> +    <script src="stex.js"></script> +    <style>.CodeMirror {background: #f8f8f8;}</style> +    <link rel="stylesheet" href="../../doc/docs.css"> +  </head> +  <body> +    <h1>CodeMirror: sTeX mode</h1> +     <form><textarea id="code" name="code"> +\begin{module}[id=bbt-size] +\importmodule[balanced-binary-trees]{balanced-binary-trees} +\importmodule[\KWARCslides{dmath/en/cardinality}]{cardinality} + +\begin{frame} +  \frametitle{Size Lemma for Balanced Trees} +  \begin{itemize} +  \item +    \begin{assertion}[id=size-lemma,type=lemma]  +    Let $G=\tup{V,E}$ be a \termref[cd=binary-trees]{balanced binary tree}  +    of \termref[cd=graph-depth,name=vertex-depth]{depth}$n>i$, then the set +     $\defeq{\livar{V}i}{\setst{\inset{v}{V}}{\gdepth{v} = i}}$ of +    \termref[cd=graphs-intro,name=node]{nodes} at  +    \termref[cd=graph-depth,name=vertex-depth]{depth} $i$ has +    \termref[cd=cardinality,name=cardinality]{cardinality} $\power2i$. +   \end{assertion} +  \item +    \begin{sproof}[id=size-lemma-pf,proofend=,for=size-lemma]{via induction over the depth $i$.} +      \begin{spfcases}{We have to consider two cases} +        \begin{spfcase}{$i=0$} +          \begin{spfstep}[display=flow] +            then $\livar{V}i=\set{\livar{v}r}$, where $\livar{v}r$ is the root, so +            $\eq{\card{\livar{V}0},\card{\set{\livar{v}r}},1,\power20}$. +          \end{spfstep} +        \end{spfcase} +        \begin{spfcase}{$i>0$} +          \begin{spfstep}[display=flow] +           then $\livar{V}{i-1}$ contains $\power2{i-1}$ vertexes  +           \begin{justification}[method=byIH](IH)\end{justification} +          \end{spfstep} +          \begin{spfstep} +           By the \begin{justification}[method=byDef]definition of a binary +              tree\end{justification}, each $\inset{v}{\livar{V}{i-1}}$ is a leaf or has +            two children that are at depth $i$. +          \end{spfstep} +          \begin{spfstep} +           As $G$ is \termref[cd=balanced-binary-trees,name=balanced-binary-tree]{balanced} and $\gdepth{G}=n>i$, $\livar{V}{i-1}$ cannot contain +            leaves. +          \end{spfstep} +          \begin{spfstep}[type=conclusion] +           Thus $\eq{\card{\livar{V}i},{\atimes[cdot]{2,\card{\livar{V}{i-1}}}},{\atimes[cdot]{2,\power2{i-1}}},\power2i}$. +          \end{spfstep} +        \end{spfcase} +      \end{spfcases} +    \end{sproof} +  \item  +    \begin{assertion}[id=fbbt,type=corollary]	 +      A fully balanced tree of depth $d$ has $\power2{d+1}-1$ nodes. +    \end{assertion} +  \item +      \begin{sproof}[for=fbbt,id=fbbt-pf]{} +        \begin{spfstep} +          Let $\defeq{G}{\tup{V,E}}$ be a fully balanced tree +        \end{spfstep} +        \begin{spfstep} +          Then $\card{V}=\Sumfromto{i}1d{\power2i}= \power2{d+1}-1$. +        \end{spfstep} +      \end{sproof} +    \end{itemize} +  \end{frame} +\begin{note} +  \begin{omtext}[type=conclusion,for=binary-tree] +    This shows that balanced binary trees grow in breadth very quickly, a consequence of +    this is that they are very shallow (and this compute very fast), which is the essence of +    the next result. +  \end{omtext} +\end{note} +\end{module} + +%%% Local Variables:  +%%% mode: LaTeX +%%% TeX-master: "all" +%%% End: \end{document} +</textarea></form> +    <script> +      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {}); +    </script> + +    <p><strong>MIME types defined:</strong> <code>text/x-stex</code>.</p> + +  </body> +</html> diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/stex/stex.js b/codemirror_ui/lib/CodeMirror-2.3/mode/stex/stex.js new file mode 100644 index 0000000..c0739de --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/stex/stex.js @@ -0,0 +1,182 @@ +/* + * Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de) + * Licence: MIT + */ + +CodeMirror.defineMode("stex", function(cmCfg, modeCfg)  +{     +    function pushCommand(state, command) { +	state.cmdState.push(command); +    } + +    function peekCommand(state) {  +	if (state.cmdState.length>0) +	    return state.cmdState[state.cmdState.length-1]; +	else +	    return null; +    } + +    function popCommand(state) { +	if (state.cmdState.length>0) { +	    var plug = state.cmdState.pop(); +	    plug.closeBracket(); +	}	     +    } + +    function applyMostPowerful(state) { +      var context = state.cmdState; +      for (var i = context.length - 1; i >= 0; i--) { +	  var plug = context[i]; +	  if (plug.name=="DEFAULT") +	      continue; +	  return plug.styleIdentifier(); +      } +      return null; +    } + +    function addPluginPattern(pluginName, cmdStyle, brackets, styles) { +	return function () { +	    this.name=pluginName; +	    this.bracketNo = 0; +	    this.style=cmdStyle; +	    this.styles = styles; +	    this.brackets = brackets; + +	    this.styleIdentifier = function(content) { +		if (this.bracketNo<=this.styles.length) +		    return this.styles[this.bracketNo-1]; +		else +		    return null; +	    }; +	    this.openBracket = function(content) { +		this.bracketNo++; +		return "bracket"; +	    }; +	    this.closeBracket = function(content) { +	    }; +	} +    } + +    var plugins = new Array(); +    +    plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]); +    plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]); +    plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]); +    plugins["begin"] = addPluginPattern("documentclass", "tag", "[", ["atom"]); +    plugins["end"] = addPluginPattern("documentclass", "tag", "[", ["atom"]); + +    plugins["DEFAULT"] = function () { +	this.name="DEFAULT"; +	this.style="tag"; + +	this.styleIdentifier = function(content) { +	}; +	this.openBracket = function(content) { +	}; +	this.closeBracket = function(content) { +	}; +    }; + +    function setState(state, f) { +	state.f = f; +    } + +    function normal(source, state) { +	if (source.match(/^\\[a-zA-Z@]+/)) { +	    var cmdName = source.current(); +	    cmdName = cmdName.substr(1, cmdName.length-1); +            var plug; +            if (plugins.hasOwnProperty(cmdName)) { +	      plug = plugins[cmdName]; +            } else { +              plug = plugins["DEFAULT"]; +            } +	    plug = new plug(); +	    pushCommand(state, plug); +	    setState(state, beginParams); +	    return plug.style; +	} + +        // escape characters  +        if (source.match(/^\\[$&%#{}_]/)) { +          return "tag"; +        } + +        // white space control characters +        if (source.match(/^\\[,;!\/]/)) { +          return "tag"; +        } + +	var ch = source.next(); +	if (ch == "%") { +            // special case: % at end of its own line; stay in same state +            if (!source.eol()) { +              setState(state, inCComment); +            } +	    return "comment"; +	}  +	else if (ch=='}' || ch==']') { +	    plug = peekCommand(state); +	    if (plug) { +		plug.closeBracket(ch); +		setState(state, beginParams); +	    } else +		return "error"; +	    return "bracket"; +	} else if (ch=='{' || ch=='[') { +	    plug = plugins["DEFAULT"];	     +	    plug = new plug(); +	    pushCommand(state, plug); +	    return "bracket";	     +	} +	else if (/\d/.test(ch)) { +	    source.eatWhile(/[\w.%]/); +	    return "atom"; +	} +	else { +	    source.eatWhile(/[\w-_]/); +	    return applyMostPowerful(state); +	} +    } + +    function inCComment(source, state) { +	source.skipToEnd(); +	setState(state, normal); +	return "comment"; +    } + +    function beginParams(source, state) { +	var ch = source.peek(); +	if (ch == '{' || ch == '[') { +	   var lastPlug = peekCommand(state); +	   var style = lastPlug.openBracket(ch); +	   source.eat(ch); +	   setState(state, normal); +	   return "bracket"; +	} +	if (/[ \t\r]/.test(ch)) { +	    source.eat(ch); +	    return null; +	} +	setState(state, normal); +	lastPlug = peekCommand(state); +	if (lastPlug) { +	    popCommand(state); +	} +        return normal(source, state); +    } + +    return { +     startState: function() { return { f:normal, cmdState:[] }; }, +	 copyState: function(s) { return { f: s.f, cmdState: s.cmdState.slice(0, s.cmdState.length) }; }, +	  +	 token: function(stream, state) { +	 var t = state.f(stream, state); +	 var w = stream.current(); +	 return t; +     } + }; +}); + + +CodeMirror.defineMIME("text/x-stex", "stex"); diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/stex/test.html b/codemirror_ui/lib/CodeMirror-2.3/mode/stex/test.html new file mode 100644 index 0000000..a60f418 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/stex/test.html @@ -0,0 +1,263 @@ +<!doctype html> +<html> +  <head> +    <title>CodeMirror: sTeX mode</title> +    <link rel="stylesheet" href="../../lib/codemirror.css"> +    <script src="../../lib/codemirror.js"></script> +    <script src="stex.js"></script> +    <link rel="stylesheet" href="../../test/mode_test.css"> +    <script src="../../test/mode_test.js"></script> +    <link rel="stylesheet" href="../../doc/docs.css"> +  </head> +  <body> +    <h1>Tests for the sTeX Mode</h1> +    <h2>Basics</h2> +    <script language="javascript"> +      MT = ModeTest; + +      MT.test('foo', +        null, 'foo'); + +      MT.test('foo bar', +        null, 'foo', +        null, ' bar'); +    </script> + +    <h2>Tags</h2> +    <script language="javascript"> +      MT.test('\\begin{document}\n\\end{document}', +        'tag',     '\\begin', +        'bracket', '{', +        'atom',    'document', +        'bracket', '}', +        'tag',     '\\end', +        'bracket', '{', +        'atom',    'document', +        'bracket', '}'); + +      MT.test('\\begin{equation}\n  E=mc^2\n\\end{equation}', +        'tag',     '\\begin', +        'bracket', '{', +        'atom',    'equation', +        'bracket', '}', +        null,      ' ', +        null,      ' ', +        null,      'E', +        null,      '=mc', +        null,      '^2', +        'tag',     '\\end', +        'bracket', '{', +        'atom',    'equation', +        'bracket', '}'); + +      MT.test('\\begin{module}[]', +        'tag',     '\\begin', +        'bracket', '{', +        'atom',    'module', +        'bracket', '}', +        'bracket', '[', +        'bracket', ']'); + +      MT.test('\\begin{module}[id=bbt-size]', +        'tag',     '\\begin', +        'bracket', '{', +        'atom',    'module', +        'bracket', '}', +        'bracket', '[', +        null,      'id', +        null,      '=bbt-size', +        'bracket', ']'); + +      MT.test('\\importmodule[b-b-t]{b-b-t}', +        'tag',     '\\importmodule', +        'bracket', '[', +        'string',   'b-b-t', +        'bracket', ']', +        'bracket', '{', +        'builtin', 'b-b-t', +        'bracket', '}'); + +      MT.test('\\importmodule[\\KWARCslides{dmath/en/cardinality}]{card}', +        'tag',     '\\importmodule', +        'bracket', '[', +        'tag',     '\\KWARCslides', +        'bracket', '{', +        'string',   'dmath', +        'string',   '/en', +        'string',   '/cardinality', +        'bracket', '}', +        'bracket', ']', +        'bracket', '{', +        'builtin', 'card', +        'bracket', '}'); + +      MT.test('\\PSforPDF[1]{#1}', // could treat #1 specially +        'tag',     '\\PSforPDF', +        'bracket', '[', +        'atom',    '1', +        'bracket', ']', +        'bracket', '{', +        null,      '#1', +        'bracket', '}'); +    </script> + +    <h2>Comments</h2> +    <script language="javascript"> +      MT.test('% foo', +        'comment', '%', +        'comment', ' foo'); + +      MT.test('\\item% bar', +        'tag',     '\\item', +        'comment', '%', +        'comment', ' bar'); + +      MT.test(' % \\item', +        null,      ' ', +        'comment', '%', +        'comment', ' \\item'); + +      MT.test('%\nfoo', +        'comment', '%', +        null, 'foo'); +    </script> + +    <h2>Errors</h2> +    <script language="javascript"> +      MT.test('\\begin}{', +        'tag',     '\\begin', +        'error',   '}', +        'bracket', '{'); + +      MT.test('\\item]{', +        'tag',     '\\item', +        'error',   ']', +        'bracket', '{'); + +      MT.test('% }', +        'comment', '%', +        'comment', ' }'); +    </script> + +    <h2>Character Escapes</h2> +    <script language="javascript"> +      MT.test('the \\# key', +        null,  'the', +        null,  ' ', +        'tag', '\\#', +        null,  ' key'); + +      MT.test('a \\$5 stetson', +        null, 'a', +        null, ' ', +        'tag', '\\$', +        'atom', 5, +        null, ' stetson'); + +      MT.test('100\\% beef', +        'atom', '100', +        'tag', '\\%', +        null, ' beef'); + +      MT.test('L \\& N', +        null, 'L', +        null, ' ', +        'tag', '\\&', +        null, ' N'); + +      MT.test('foo\\_bar', +        null, 'foo', +        'tag', '\\_', +        null, 'bar'); + +      MT.test('\\emph{\\{}', +        'tag',    '\\emph', +        'bracket','{', +        'tag',    '\\{', +        'bracket','}'); + +      MT.test('\\emph{\\}}', +        'tag',    '\\emph', +        'bracket','{', +        'tag',    '\\}', +        'bracket','}'); + +      MT.test('section \\S1', +        null,  'section', +        null,  ' ', +        'tag', '\\S', +        'atom',  '1'); + +      MT.test('para \\P2', +        null,  'para', +        null,  ' ', +        'tag', '\\P', +        'atom',  '2'); + +    </script> + +    <h2>Spacing control</h2> + +    <script language="javascript"> +      MT.test('x\\,y', // thinspace +        null,  'x', +        'tag', '\\,', +        null,  'y'); + +      MT.test('x\\;y', // thickspace +        null,  'x', +        'tag', '\\;', +        null,  'y'); + +      MT.test('x\\!y', // negative thinspace +        null,  'x', +        'tag', '\\!', +        null,  'y'); + +      MT.test('J.\\ L.\\ is', // period not ending a sentence +        null, 'J', +        null, '.', +        null, '\\', +        null, ' L', +        null, '.', +        null, '\\', +        null, ' is'); // maybe could be better + +      MT.test('X\\@. The', // period ending a sentence +        null,  'X', +        'tag', '\\@', +        null,  '.', +        null,  ' The'); + +      MT.test('{\\em If\\/} I', // italic correction +        'bracket', '{', +        'tag',     '\\em', +        null,      ' ', +        null,      'If', +        'tag',     '\\/', +        'bracket', '}', +        null,      ' ', +        null,      'I'); + +    </script> + +    <h2>New Commands</h2> + +    Should be able to define a new command that happens to be a method on Array +    (e.g. <tt>pop</tt>): +    <script language="javascript"> +      MT.test('\\newcommand{\\pop}', +        'tag', '\\newcommand', +        'bracket', '{', +        'tag', '\\pop', +        'bracket', '}'); +    </script> + +    <h2>Summary</h2> +    <script language="javascript"> +      MT.printSummary(); +    </script> + +  </body> +</html> +  | 
