aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/stex
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-01-27 12:05:17 -0800
committerJose Antonio Marquez2012-01-27 12:05:17 -0800
commit3a754133dbc138390503341fd2e9beba3e43aa4b (patch)
treecdeae7d7dd9a30d7b4fab5afb7efad68d4ec7508 /imports/codemirror/mode/stex
parentb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (diff)
downloadninja-3a754133dbc138390503341fd2e9beba3e43aa4b.tar.gz
Merged old FileIO
Diffstat (limited to 'imports/codemirror/mode/stex')
-rwxr-xr-ximports/codemirror/mode/stex/index.html95
-rwxr-xr-ximports/codemirror/mode/stex/stex.js167
2 files changed, 262 insertions, 0 deletions
diff --git a/imports/codemirror/mode/stex/index.html b/imports/codemirror/mode/stex/index.html
new file mode 100755
index 00000000..ccd9dd83
--- /dev/null
+++ b/imports/codemirror/mode/stex/index.html
@@ -0,0 +1,95 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror: sTeX mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="stex.js"></script>
8 <style>.CodeMirror {background: #f8f8f8;}</style>
9 <link rel="stylesheet" href="../../doc/docs.css">
10 </head>
11 <body>
12 <h1>CodeMirror: sTeX mode</h1>
13 <form><textarea id="code" name="code">
14\begin{module}[id=bbt-size]
15\importmodule[balanced-binary-trees]{balanced-binary-trees}
16\importmodule[\KWARCslides{dmath/en/cardinality}]{cardinality}
17
18\begin{frame}
19 \frametitle{Size Lemma for Balanced Trees}
20 \begin{itemize}
21 \item
22 \begin{assertion}[id=size-lemma,type=lemma]
23 Let $G=\tup{V,E}$ be a \termref[cd=binary-trees]{balanced binary tree}
24 of \termref[cd=graph-depth,name=vertex-depth]{depth}$n>i$, then the set
25 $\defeq{\livar{V}i}{\setst{\inset{v}{V}}{\gdepth{v} = i}}$ of
26 \termref[cd=graphs-intro,name=node]{nodes} at
27 \termref[cd=graph-depth,name=vertex-depth]{depth} $i$ has
28 \termref[cd=cardinality,name=cardinality]{cardinality} $\power2i$.
29 \end{assertion}
30 \item
31 \begin{sproof}[id=size-lemma-pf,proofend=,for=size-lemma]{via induction over the depth $i$.}
32 \begin{spfcases}{We have to consider two cases}
33 \begin{spfcase}{$i=0$}
34 \begin{spfstep}[display=flow]
35 then $\livar{V}i=\set{\livar{v}r}$, where $\livar{v}r$ is the root, so
36 $\eq{\card{\livar{V}0},\card{\set{\livar{v}r}},1,\power20}$.
37 \end{spfstep}
38 \end{spfcase}
39 \begin{spfcase}{$i>0$}
40 \begin{spfstep}[display=flow]
41 then $\livar{V}{i-1}$ contains $\power2{i-1}$ vertexes
42 \begin{justification}[method=byIH](IH)\end{justification}
43 \end{spfstep}
44 \begin{spfstep}
45 By the \begin{justification}[method=byDef]definition of a binary
46 tree\end{justification}, each $\inset{v}{\livar{V}{i-1}}$ is a leaf or has
47 two children that are at depth $i$.
48 \end{spfstep}
49 \begin{spfstep}
50 As $G$ is \termref[cd=balanced-binary-trees,name=balanced-binary-tree]{balanced} and $\gdepth{G}=n>i$, $\livar{V}{i-1}$ cannot contain
51 leaves.
52 \end{spfstep}
53 \begin{spfstep}[type=conclusion]
54 Thus $\eq{\card{\livar{V}i},{\atimes[cdot]{2,\card{\livar{V}{i-1}}}},{\atimes[cdot]{2,\power2{i-1}}},\power2i}$.
55 \end{spfstep}
56 \end{spfcase}
57 \end{spfcases}
58 \end{sproof}
59 \item
60 \begin{assertion}[id=fbbt,type=corollary]
61 A fully balanced tree of depth $d$ has $\power2{d+1}-1$ nodes.
62 \end{assertion}
63 \item
64 \begin{sproof}[for=fbbt,id=fbbt-pf]{}
65 \begin{spfstep}
66 Let $\defeq{G}{\tup{V,E}}$ be a fully balanced tree
67 \end{spfstep}
68 \begin{spfstep}
69 Then $\card{V}=\Sumfromto{i}1d{\power2i}= \power2{d+1}-1$.
70 \end{spfstep}
71 \end{sproof}
72 \end{itemize}
73 \end{frame}
74\begin{note}
75 \begin{omtext}[type=conclusion,for=binary-tree]
76 This shows that balanced binary trees grow in breadth very quickly, a consequence of
77 this is that they are very shallow (and this compute very fast), which is the essence of
78 the next result.
79 \end{omtext}
80\end{note}
81\end{module}
82
83%%% Local Variables:
84%%% mode: LaTeX
85%%% TeX-master: "all"
86%%% End: \end{document}
87</textarea></form>
88 <script>
89 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
90 </script>
91
92 <p><strong>MIME types defined:</strong> <code>text/stex</code>.</p>
93
94 </body>
95</html>
diff --git a/imports/codemirror/mode/stex/stex.js b/imports/codemirror/mode/stex/stex.js
new file mode 100755
index 00000000..bb47fb45
--- /dev/null
+++ b/imports/codemirror/mode/stex/stex.js
@@ -0,0 +1,167 @@
1/*
2 * Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de)
3 * Licence: MIT
4 */
5
6CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
7{
8 function pushCommand(state, command) {
9 state.cmdState.push(command);
10 }
11
12 function peekCommand(state) {
13 if (state.cmdState.length>0)
14 return state.cmdState[state.cmdState.length-1];
15 else
16 return null;
17 }
18
19 function popCommand(state) {
20 if (state.cmdState.length>0) {
21 var plug = state.cmdState.pop();
22 plug.closeBracket();
23 }
24 }
25
26 function applyMostPowerful(state) {
27 var context = state.cmdState;
28 for (var i = context.length - 1; i >= 0; i--) {
29 var plug = context[i];
30 if (plug.name=="DEFAULT")
31 continue;
32 return plug.styleIdentifier();
33 }
34 return null;
35 }
36
37 function addPluginPattern(pluginName, cmdStyle, brackets, styles) {
38 return function () {
39 this.name=pluginName;
40 this.bracketNo = 0;
41 this.style=cmdStyle;
42 this.styles = styles;
43 this.brackets = brackets;
44
45 this.styleIdentifier = function(content) {
46 if (this.bracketNo<=this.styles.length)
47 return this.styles[this.bracketNo-1];
48 else
49 return null;
50 };
51 this.openBracket = function(content) {
52 this.bracketNo++;
53 return "bracket";
54 };
55 this.closeBracket = function(content) {
56 };
57 }
58 }
59
60 var plugins = new Array();
61
62 plugins["importmodule"] = addPluginPattern("importmodule", "tag", "{[", ["string", "builtin"]);
63 plugins["documentclass"] = addPluginPattern("documentclass", "tag", "{[", ["", "atom"]);
64 plugins["usepackage"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
65 plugins["begin"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
66 plugins["end"] = addPluginPattern("documentclass", "tag", "[", ["atom"]);
67
68 plugins["DEFAULT"] = function () {
69 this.name="DEFAULT";
70 this.style="tag";
71
72 this.styleIdentifier = function(content) {
73 };
74 this.openBracket = function(content) {
75 };
76 this.closeBracket = function(content) {
77 };
78 };
79
80 function setState(state, f) {
81 state.f = f;
82 }
83
84 function normal(source, state) {
85 if (source.match(/^\\[a-z]+/)) {
86 var cmdName = source.current();
87 cmdName = cmdName.substr(1, cmdName.length-1);
88 var plug = plugins[cmdName];
89 if (typeof(plug) == 'undefined') {
90 plug = plugins["DEFAULT"];
91 }
92 plug = new plug();
93 pushCommand(state, plug);
94 setState(state, beginParams);
95 return plug.style;
96 }
97
98 var ch = source.next();
99 if (ch == "%") {
100 setState(state, inCComment);
101 return "comment";
102 }
103 else if (ch=='}' || ch==']') {
104 plug = peekCommand(state);
105 if (plug) {
106 plug.closeBracket(ch);
107 setState(state, beginParams);
108 } else
109 return "error";
110 return "bracket";
111 } else if (ch=='{' || ch=='[') {
112 plug = plugins["DEFAULT"];
113 plug = new plug();
114 pushCommand(state, plug);
115 return "bracket";
116 }
117 else if (/\d/.test(ch)) {
118 source.eatWhile(/[\w.%]/);
119 return "atom";
120 }
121 else {
122 source.eatWhile(/[\w-_]/);
123 return applyMostPowerful(state);
124 }
125 }
126
127 function inCComment(source, state) {
128 source.skipToEnd();
129 setState(state, normal);
130 retur