+
+ // no macro mode
+ if (c == '^' || c == '_') {
+ const bool up = (c == '^');
+ selCut();
+ if (hasPrevAtom() && prevAtom()->asScriptInset()) {
+ prevAtom()->asScriptInset()->ensure(up);
+ pushRight(prevAtom());
+ pos() = size();
+ } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
+ nextAtom()->asScriptInset()->ensure(up);
+ pushLeft(nextAtom());
+ pos() = 0;
+ } else {
+ plainInsert(MathAtom(new MathScriptInset(up)));
+ pushRight(prevAtom());
+ }
+ idx() = up;
+ selPaste();
+ return;
+ }
+
+ if (selection_)
+ selDel();
+
+ if (lastcode_ == LM_TC_TEXTRM) {
+ insert(c, LM_TC_TEXTRM);
+ return;
+ }
+
+ if (c == ' ') {
+ if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
+ prevAtom()->asSpaceInset()->incSpace();
+ return;
+ }
+
+ if (mathcursor->popRight())
+ return;
+
+#warning look here
+ // this would not work if the inset is in an table!
+ //bv->text->cursorRight(bv, true);
+ //result = FINISHED;
+ return;
+ }
+
+ if (strchr("{}", c)) {
+ insert(c, LM_TC_TEX);
+ return;
+ }
+
+ if (strchr("#$%", c)) {
+ insert(MathAtom(new MathSpecialCharInset(c)));
+ lastcode_ = LM_TC_VAR;
+ return;
+ }
+
+ if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
+ static char const greekl[][26] =
+ {"alpha", "beta", "chi", "delta", "epsilon", "phi",
+ "gamma", "eta", "iota", "epsilon", "kappa", "lambda", "mu",
+ "nu", "omikron", "pi", "vartheta", "rho", "sigma",
+ "tau", "upsilon", "theta", "omega", "xi", "varphi", "zeta"};
+ static char const greeku[][26] =
+ {"Alpha", "Beta", "chi", "Delta", "varepsilon", "Phi",
+ "Gamma", "Eta", "Iota", "Epsilon", "Kappa", "Lambda", "Mu",
+ "Nu", "Omikron", "Pi", "vartheta", "varrho", "Sigma", "varsigma",
+ "Upsilon", "Theta", "Omega", "Xi", "Varphi", "Zeta"};
+
+ latexkeys const * l = 0;
+ if ('a' <= c && c <= 'z')
+ l = in_word_set(greekl[c - 'a']);
+ if ('A' <= c && c <= 'Z')
+ l = in_word_set(greeku[c - 'A']);
+
+ if (l)
+ insert(createMathInset(l));
+ else
+ insert(c, LM_TC_VAR);
+
+#warning greek insert problem? look here!
+ if (lastcode_ == LM_TC_GREEK1)
+ lastcode_ = LM_TC_VAR;
+ return;
+ }
+
+ if (c == '\\') {
+ insert(c, LM_TC_TEX);
+ //bv->owner()->message(_("TeX mode"));
+ return;
+ }
+
+ // no special circumstances, so insert the character without any fuss
+ insert(c, LM_TC_MIN);