first commit
This commit is contained in:
98
codemirror/mode/stex/index.html
vendored
Normal file
98
codemirror/mode/stex/index.html
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<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>
|
||||
|
||||
<p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#stex_*">normal</a>, <a href="../../test/index.html#verbose,stex_*">verbose</a>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
175
codemirror/mode/stex/stex.js
vendored
Normal file
175
codemirror/mode/stex/stex.js
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Author: Constantin Jucovschi (c.jucovschi@jacobs-university.de)
|
||||
* Licence: MIT
|
||||
*/
|
||||
|
||||
CodeMirror.defineMode("stex", function()
|
||||
{
|
||||
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() {
|
||||
if (this.bracketNo<=this.styles.length)
|
||||
return this.styles[this.bracketNo-1];
|
||||
else
|
||||
return null;
|
||||
};
|
||||
this.openBracket = function() {
|
||||
this.bracketNo++;
|
||||
return "bracket";
|
||||
};
|
||||
this.closeBracket = function() {};
|
||||
};
|
||||
}
|
||||
|
||||
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 = this.openBracket = this.closeBracket = function() {};
|
||||
};
|
||||
|
||||
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);
|
||||
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);
|
||||
return t;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-stex", "stex");
|
||||
CodeMirror.defineMIME("text/x-latex", "stex");
|
||||
343
codemirror/mode/stex/test.js
vendored
Normal file
343
codemirror/mode/stex/test.js
vendored
Normal file
@@ -0,0 +1,343 @@
|
||||
var MT = ModeTest;
|
||||
MT.modeName = 'stex';
|
||||
MT.modeOptions = {};
|
||||
|
||||
MT.testMode(
|
||||
'word',
|
||||
'foo',
|
||||
[
|
||||
null, 'foo'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'twoWords',
|
||||
'foo bar',
|
||||
[
|
||||
null, 'foo bar'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'beginEndDocument',
|
||||
'\\begin{document}\n\\end{document}',
|
||||
[
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'document',
|
||||
'bracket', '}',
|
||||
'tag', '\\end',
|
||||
'bracket', '{',
|
||||
'atom', 'document',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'beginEndEquation',
|
||||
'\\begin{equation}\n E=mc^2\n\\end{equation}',
|
||||
[
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'equation',
|
||||
'bracket', '}',
|
||||
null, ' E=mc^2',
|
||||
'tag', '\\end',
|
||||
'bracket', '{',
|
||||
'atom', 'equation',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'beginModule',
|
||||
'\\begin{module}[]',
|
||||
[
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'module',
|
||||
'bracket', '}[]'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'beginModuleId',
|
||||
'\\begin{module}[id=bbt-size]',
|
||||
[
|
||||
'tag', '\\begin',
|
||||
'bracket', '{',
|
||||
'atom', 'module',
|
||||
'bracket', '}[',
|
||||
null, 'id=bbt-size',
|
||||
'bracket', ']'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'importModule',
|
||||
'\\importmodule[b-b-t]{b-b-t}',
|
||||
[
|
||||
'tag', '\\importmodule',
|
||||
'bracket', '[',
|
||||
'string', 'b-b-t',
|
||||
'bracket', ']{',
|
||||
'builtin', 'b-b-t',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'importModulePath',
|
||||
'\\importmodule[\\KWARCslides{dmath/en/cardinality}]{card}',
|
||||
[
|
||||
'tag', '\\importmodule',
|
||||
'bracket', '[',
|
||||
'tag', '\\KWARCslides',
|
||||
'bracket', '{',
|
||||
'string', 'dmath/en/cardinality',
|
||||
'bracket', '}]{',
|
||||
'builtin', 'card',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'psForPDF',
|
||||
'\\PSforPDF[1]{#1}', // could treat #1 specially
|
||||
[
|
||||
'tag', '\\PSforPDF',
|
||||
'bracket', '[',
|
||||
'atom', '1',
|
||||
'bracket', ']{',
|
||||
null, '#1',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'comment',
|
||||
'% foo',
|
||||
[
|
||||
'comment', '% foo'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagComment',
|
||||
'\\item% bar',
|
||||
[
|
||||
'tag', '\\item',
|
||||
'comment', '% bar'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'commentTag',
|
||||
' % \\item',
|
||||
[
|
||||
null, ' ',
|
||||
'comment', '% \\item'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'commentLineBreak',
|
||||
'%\nfoo',
|
||||
[
|
||||
'comment', '%',
|
||||
null, 'foo'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagErrorCurly',
|
||||
'\\begin}{',
|
||||
[
|
||||
'tag', '\\begin',
|
||||
'error', '}',
|
||||
'bracket', '{'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagErrorSquare',
|
||||
'\\item]{',
|
||||
[
|
||||
'tag', '\\item',
|
||||
'error', ']',
|
||||
'bracket', '{'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'commentCurly',
|
||||
'% }',
|
||||
[
|
||||
'comment', '% }'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagHash',
|
||||
'the \\# key',
|
||||
[
|
||||
null, 'the ',
|
||||
'tag', '\\#',
|
||||
null, ' key'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagNumber',
|
||||
'a \\$5 stetson',
|
||||
[
|
||||
null, 'a ',
|
||||
'tag', '\\$',
|
||||
'atom', 5,
|
||||
null, ' stetson'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagPercent',
|
||||
'100\\% beef',
|
||||
[
|
||||
'atom', '100',
|
||||
'tag', '\\%',
|
||||
null, ' beef'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagAmpersand',
|
||||
'L \\& N',
|
||||
[
|
||||
null, 'L ',
|
||||
'tag', '\\&',
|
||||
null, ' N'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagUnderscore',
|
||||
'foo\\_bar',
|
||||
[
|
||||
null, 'foo',
|
||||
'tag', '\\_',
|
||||
null, 'bar'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagBracketOpen',
|
||||
'\\emph{\\{}',
|
||||
[
|
||||
'tag', '\\emph',
|
||||
'bracket', '{',
|
||||
'tag', '\\{',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagBracketClose',
|
||||
'\\emph{\\}}',
|
||||
[
|
||||
'tag', '\\emph',
|
||||
'bracket', '{',
|
||||
'tag', '\\}',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagLetterNumber',
|
||||
'section \\S1',
|
||||
[
|
||||
null, 'section ',
|
||||
'tag', '\\S',
|
||||
'atom', '1'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'textTagNumber',
|
||||
'para \\P2',
|
||||
[
|
||||
null, 'para ',
|
||||
'tag', '\\P',
|
||||
'atom', '2'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'thinspace',
|
||||
'x\\,y', // thinspace
|
||||
[
|
||||
null, 'x',
|
||||
'tag', '\\,',
|
||||
null, 'y'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'thickspace',
|
||||
'x\\;y', // thickspace
|
||||
[
|
||||
null, 'x',
|
||||
'tag', '\\;',
|
||||
null, 'y'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'negativeThinspace',
|
||||
'x\\!y', // negative thinspace
|
||||
[
|
||||
null, 'x',
|
||||
'tag', '\\!',
|
||||
null, 'y'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'periodNotSentence',
|
||||
'J.\\ L.\\ is', // period not ending a sentence
|
||||
[
|
||||
null, 'J.\\ L.\\ is'
|
||||
]
|
||||
); // maybe could be better
|
||||
|
||||
MT.testMode(
|
||||
'periodSentence',
|
||||
'X\\@. The', // period ending a sentence
|
||||
[
|
||||
null, 'X',
|
||||
'tag', '\\@',
|
||||
null, '. The'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'italicCorrection',
|
||||
'{\\em If\\/} I', // italic correction
|
||||
[
|
||||
'bracket', '{',
|
||||
'tag', '\\em',
|
||||
null, ' If',
|
||||
'tag', '\\/',
|
||||
'bracket', '}',
|
||||
null, ' I'
|
||||
]
|
||||
);
|
||||
|
||||
MT.testMode(
|
||||
'tagBracket',
|
||||
'\\newcommand{\\pop}',
|
||||
[
|
||||
'tag', '\\newcommand',
|
||||
'bracket', '{',
|
||||
'tag', '\\pop',
|
||||
'bracket', '}'
|
||||
]
|
||||
);
|
||||
Reference in New Issue
Block a user