- MathAtom at = createInsetMath(t.cs());
- InsetMath::mode_type m = mode;
- //if (m == InsetMath::UNDECIDED_MODE)
- //lyxerr << "default creation: m1: " << m << endl;
- if (at->currentMode() != InsetMath::UNDECIDED_MODE)
- m = at->currentMode();
- //lyxerr << "default creation: m2: " << m << endl;
- InsetMath::idx_type start = 0;
- // this fails on \bigg[...\bigg]
- //MathData opt;
- //parse(opt, FLAG_OPTION, InsetMath::VERBATIM_MODE);
- //if (opt.size()) {
- // start = 1;
- // at.nucleus()->cell(0) = opt;
- //}
- for (InsetMath::idx_type i = start; i < at->nargs(); ++i) {
- parse(at.nucleus()->cell(i), FLAG_ITEM, m);
- skipSpaces();
+ bool is_unicode_symbol = false;
+ if (mode == InsetMath::TEXT_MODE && !is_user_macro) {
+ int num_tokens = 0;
+ docstring cmd = prevToken().asInput();
+ CatCode cat = nextToken().cat();
+ if (cat == catBegin) {
+ int count = 0;
+ while (good() && (count || cat != catEnd)) {
+ cat = nextToken().cat();
+ cmd += getToken().asInput();
+ ++num_tokens;
+ if (cat == catBegin)
+ ++count;
+ else if (cat == catEnd)
+ --count;
+ }
+ }
+ bool is_combining;
+ bool termination;
+ char_type c = Encodings::fromLaTeXCommand(cmd,
+ Encodings::MATH_CMD | Encodings::TEXT_CMD,
+ is_combining, termination);
+ if (is_combining) {
+ if (cat == catLetter)
+ cmd += '{';
+ cmd += getToken().asInput();
+ ++num_tokens;
+ if (cat == catLetter)
+ cmd += '}';
+ c = Encodings::fromLaTeXCommand(cmd,
+ Encodings::MATH_CMD | Encodings::TEXT_CMD,
+ is_combining, termination);
+ }
+ if (c) {
+ if (termination) {
+ if (nextToken().cat() == catBegin) {
+ getToken();
+ if (nextToken().cat() == catEnd) {
+ getToken();
+ num_tokens += 2;
+ } else
+ putback();
+ } else {
+ while (nextToken().cat() == catSpace) {
+ getToken();
+ ++num_tokens;
+ }
+ }
+ }
+ is_unicode_symbol = true;
+ cell->push_back(MathAtom(new InsetMathChar(c)));
+ } else {
+ while (num_tokens--)
+ putback();
+ }
+ }
+ if (!is_unicode_symbol) {
+ MathAtom at = is_user_macro ?
+ MathAtom(new MathMacro(buf, t.cs()))
+ : createInsetMath(t.cs(), buf);
+ InsetMath::mode_type m = mode;
+ //if (m == InsetMath::UNDECIDED_MODE)
+ //lyxerr << "default creation: m1: " << m << endl;
+ if (at->currentMode() != InsetMath::UNDECIDED_MODE)
+ m = at->currentMode();
+ //lyxerr << "default creation: m2: " << m << endl;
+ InsetMath::idx_type start = 0;
+ // this fails on \bigg[...\bigg]
+ //MathData opt;
+ //parse(opt, FLAG_OPTION, InsetMath::VERBATIM_MODE);
+ //if (!opt.empty()) {
+ // start = 1;
+ // at.nucleus()->cell(0) = opt;
+ //}
+ for (InsetMath::idx_type i = start; i < at->nargs(); ++i) {
+ parse(at.nucleus()->cell(i), FLAG_ITEM, m);
+ skipSpaces();
+ }
+ cell->push_back(at);