InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string const & arg)
{
InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string const & arg)
{
- //lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
+ //lyxerr << "InsetFormulaBase::localDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
if (!mathcursor)
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
if (!mathcursor)
if (inner()) {
array().insert(pos(), p);
++pos();
if (inner()) {
array().insert(pos(), p);
++pos();
- swap(prevAtom()->nucleus(), nextAtom()->nucleus());
+ if (prevAtom() && nextAtom()) // should be unnecessary
+ swap(prevAtom()->nucleus(), nextAtom()->nucleus());
void MathCursor::niceInsert(MathInset * p)
{
if (!p) {
void MathCursor::niceInsert(MathInset * p)
{
if (!p) {
- lyxerr << "should not happen\n";
+ lyxerr << "MathCursor::niceInsert: should not happen\n";
- if (size())
- pullArg(false);
{
string s = macroName();
if (s.size()) {
{
string s = macroName();
if (s.size()) {
- pos() = pos() - s.size() - 1;
- for (unsigned i = 0; i <= s.size(); ++i)
- plainErase();
- lastcode_ = LM_TC_VAR;
- interpret("\\" + s);
+ size_type old = pos();
+ pos() -= s.size();
+ array().erase(pos(), old);
+ interpret(s);
-string MathCursor::macroName() const
+int MathCursor::macroNamePos() const
- string s;
- for (int i = pos() - 1; i >= 0; --i) {
+ for (int i = pos() - 1; i >= 0; --i) {
MathInset * p = array().at(i)->nucleus();
MathInset * p = array().at(i)->nucleus();
- if (!p || p->code() != LM_TC_TEX || p->getChar() == '\\')
- break;
- s = p->getChar() + s;
+ if (p && p->code() == LM_TC_TEX && p->getChar() == '\\')
+ return i;
+ return -1;
+}
+
+
+string MathCursor::macroName() const
+{
+ string s;
+ for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
+ s += array().at(i)->nucleus()->getChar();
bool MathCursor::inMacroMode() const
{
bool MathCursor::inMacroMode() const
{
- return lastcode_ == LM_TC_TEX;
+ return macroNamePos() != -1;
void MathCursor::pullArg(bool goright)
{
void MathCursor::pullArg(bool goright)
{
dump("pullarg");
MathArray a = array();
dump("pullarg");
MathArray a = array();
+
+ MathScriptInset const * p = par()->asScriptInset();
+ if (p) {
+ // special handling for scripts
+ const bool up = p->up();
+ popLeft();
+ if (nextAtom()) {
+ if (up)
+ nextAtom()->removeUp();
+ else
+ nextAtom()->removeDown();
+ }
+ ++pos();
+ array().insert(pos(), a);
+ return;
+ }
+
if (popLeft()) {
plainErase();
array().insert(pos(), a);
if (popLeft()) {
plainErase();
array().insert(pos(), a);
void MathCursor::interpret(string const & s)
{
void MathCursor::interpret(string const & s)
{
- //lyxerr << "interpret: '" << s << "'\n";
+ //lyxerr << "interpret 1: '" << s << "'\n";
//lyxerr << "in: " << in_word_set(s) << " \n";
if (s.empty())
return;
//lyxerr << "in: " << in_word_set(s) << " \n";
if (s.empty())
return;
+ if (s.size() == 1) {
+ interpret(s[0]);
+ return;
+ }
- //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
- //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
- //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
+ //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
+ //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
+ //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
unsigned int m = 1;
if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
unsigned int m = 1;
- if (s.size() > 1) {
- niceInsert(createMathInset(s.substr(1)));
- return;
- }
+ niceInsert(createMathInset(s.substr(1)));
+}
+
+
+void MathCursor::interpret(char c)
+{
+ //lyxerr << "interpret 2: '" << c << "'\n";
+
+ if (inMacroMode()) {
+ string name = macroName();
+
+ if (name == "\\" && c == '#') {
+ insert(c, LM_TC_TEX);
+ return;
+ }
+
+ if (name == "\\" && c == '\\') {
+ backspac/();
+ interpret("\\backslash");
+ return;
+ }
+ if (name == "\\#" && '1' <= c && c <= '9') {
+ insert(c, LM_TC_TEX);
+ macroModeClose();
+ return;
+ }
- // we got just a single char now
+ if (isalpha(c)) {
+ insert(c, LM_TC_TEX);
+ return;
+ }
+
+ if (name == "\\") {
+ insert(c, LM_TC_TEX);
+ macroModeClose();
+ return;
+ }
+
+ macroModeClose();
+ return;
+ }
if (c == '^' || c == '_') {
if (c == '^' || c == '_') {
- const bool up = (s[0] == '^');
+ const bool up = (c == '^');
+ const bool in = inner();
++pos();
if (!prevAtom())
insert(0);
MathInset * par = prevAtom()->ensure(up);
++pos();
if (!prevAtom())
insert(0);
MathInset * par = prevAtom()->ensure(up);
+ if (in)
+ pushLeft(par);
+ else
+ pushRight(par);
- if (inMacroMode()) {
- macroModeClose();
- lastcode_ = LM_TC_VAR;
- return;
- }
-
MathSpaceInset * p = prevSpaceInset();
if (p) {
p->incSpace();
MathSpaceInset * p = prevSpaceInset();
if (p) {
p->incSpace();
- if (lastcode_ != LM_TC_TEX && strchr("{}", c)) {
insert(c, LM_TC_TEX);
return;
}
insert(c, LM_TC_TEX);
return;
}
- if (lastcode_ != LM_TC_TEX && strchr("#$%", c)) {
+ if (strchr("#$%", c)) {
insert(new MathSpecialCharInset(c));
lastcode_ = LM_TC_VAR;
return;
}
insert(new MathSpecialCharInset(c));
lastcode_ = LM_TC_VAR;
return;
}
- if (lastcode_ == LM_TC_TEX) {
- if (macroName().empty()) {
- insert(c, LM_TC_TEX);
- if (!isalpha(c) && c != '#') {
- macroModeClose();
- lastcode_ = LM_TC_VAR;
- }
- } else {
- if ('1' <= c && c <= '9' && macroName() == "#") {
- insert(c, LM_TC_TEX);
- macroModeClose();
- lastcode_ = LM_TC_VAR;
- }
- else if (isalpha(c)) {
- insert(c, LM_TC_TEX);
- }
- else {
- macroModeClose();
- 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",
if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
static char const greekl[][26] =
{"alpha", "beta", "chi", "delta", "epsilon", "phi",
insert(c, LM_TC_TEX);
//bv->owner()->message(_("TeX mode"));
return;
insert(c, LM_TC_TEX);
//bv->owner()->message(_("TeX mode"));
return;
///
void interpret(string const &);
///
///
void interpret(string const &);
///
+ void interpret(char);
+ ///
void setSize(MathStyles);
///
bool toggleLimits();
void setSize(MathStyles);
///
bool toggleLimits();
///
string macroName() const;
///
///
string macroName() const;
///
+ int macroNamePos() const;
+ ///
void insert(char, MathTextCodes t);
/// can we enter the inset?
bool openable(MathInset *, bool selection) const;
void insert(char, MathTextCodes t);
/// can we enter the inset?
bool openable(MathInset *, bool selection) const;
if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
return new MathMacroArgument(s[1] - '0');
if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
return new MathMacroArgument(s[1] - '0');
+ if (s.size() == 3 && s[0] == '\\' && s[1] == '#' && s[2] >= '1' && s[2] <= '9')
+ return new MathMacroArgument(s[2] - '0');
+
latexkeys const * l = in_word_set(s);
if (l)
return createMathInset(l);
latexkeys const * l = in_word_set(s);
if (l)
return createMathInset(l);