From 376f3f08bdef0a357e22b68271b8130be79827fb Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sun, 5 Apr 2009 01:14:10 +0000 Subject: [PATCH] Unicode symbols entered or pasted in math are wrapped in \text{} by default. Unwrapped symbols can be obtained either by dissolving the text inset or by verbatim paste (Ctrl+Shift+V). In such a case, the symbols are wrapped in \lyxmathsym when exporting to latex, as usual. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29096 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathGrid.cpp | 4 ++-- src/mathed/InsetMathNest.cpp | 11 ++++++++++- src/mathed/MathParser.cpp | 18 ++++++++++++++++-- src/mathed/MathParser_flags.h | 4 +++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 61e13dfe8c..439abfa19c 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -1073,7 +1073,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) { //lyxerr << "*** InsetMathGrid: request: " << cmd << endl; - Parse::flags parseflg = Parse::QUIET; + Parse::flags parseflg = Parse::QUIET | Parse::USETEXT; switch (cmd.action) { @@ -1274,7 +1274,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) } InsetMathGrid grid(1, 1); if (!topaste.empty()) - if (topaste.size() == 1 + if ((topaste.size() == 1 && topaste.at(0) < 0x80) || !mathed_parse_normal(grid, topaste, parseflg)) { resetGrid(grid); mathed_parse_normal(grid, topaste, diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 4f3656a736..fadc82cccf 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -16,6 +16,7 @@ #include "InsetMathBig.h" #include "InsetMathBox.h" #include "InsetMathBrace.h" +#include "InsetMathChar.h" #include "InsetMathColor.h" #include "InsetMathComment.h" #include "InsetMathDelim.h" @@ -42,6 +43,7 @@ #include "Cursor.h" #include "CutAndPaste.h" #include "DispatchResult.h" +#include "Encoding.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LyXFunc.h" @@ -514,7 +516,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) { //lyxerr << "InsetMathNest: request: " << cmd << endl; - Parse::flags parseflg = Parse::QUIET; + Parse::flags parseflg = Parse::QUIET | Parse::USETEXT; switch (cmd.action) { @@ -1615,6 +1617,13 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) cur.niceInsert(createInsetMath("sim")); return true; } + if (c >= 0x80 && !Encodings::isMathAlpha(c)) { + MathAtom at = createInsetMath("text"); + at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c))); + cur.niceInsert(at); + cur.posForward(); + return true; + } } else { if (c == '^') { cur.niceInsert(createInsetMath("textasciicircum")); diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 851828c948..362b67193e 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -907,8 +907,22 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, return success_; } - else if (t.cat() == catOther) - cell->push_back(MathAtom(new InsetMathChar(t.character()))); + else if (t.cat() == catOther) { + char_type c = t.character(); + if (c < 0x80 || mode_ & Parse::VERBATIM + || !(mode_ & Parse::USETEXT)) { + cell->push_back(MathAtom(new InsetMathChar(c))); + } else { + MathAtom at = createInsetMath("text"); + at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(t.character()))); + while (nextToken().cat() == catOther + && nextToken().character() >= 0x80) { + c = getToken().character(); + at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c))); + } + cell->push_back(at); + } + } else if (t.cat() == catComment) { docstring s; diff --git a/src/mathed/MathParser_flags.h b/src/mathed/MathParser_flags.h index 41d5cd7982..06f864bd96 100644 --- a/src/mathed/MathParser_flags.h +++ b/src/mathed/MathParser_flags.h @@ -24,7 +24,9 @@ enum flags { /// Parse verbatim. VERBATIM = 0x02, /// Quiet operation (no warnigs or errors). - QUIET = 0x04 + QUIET = 0x04, + /// Wrap unicode symbols in \text{}. + USETEXT = 0x08 }; -- 2.39.2