X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathParser.cpp;h=fc707e5a9ff4bded7710a911442a8a4f7053459f;hb=988f372843941436021a45c5d8848c514f23887c;hp=255dbadc9e4e2bc345a0011c73559a788baf3da1;hpb=897436efbb9bd641b61467d185a2dfae9839e575;p=lyx.git diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 255dbadc9e..fc707e5a9f 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -24,7 +24,6 @@ following hack as starting point to write some macros: \else \def\b{}\def\e{} \fi - ... \[\begin{array}{ccc} @@ -48,6 +47,7 @@ following hack as starting point to write some macros: #include "InsetMathComment.h" #include "InsetMathDelim.h" #include "InsetMathEnv.h" +#include "InsetMathFrac.h" #include "InsetMathKern.h" #include "MathMacro.h" #include "InsetMathPar.h" @@ -150,7 +150,7 @@ bool addCol(InsetMathGrid & grid, InsetMathGrid::col_type & cellcol) ++cellcol; if (cellcol == grid.ncols()) { //lyxerr << "adding column " << cellcol << endl; - grid.addCol(cellcol - 1); + grid.addCol(cellcol); if (cellcol == grid.ncols()) { // We can't add a column to this grid, so let's // append the content of this cell to the previous @@ -242,7 +242,7 @@ enum { FLAG_END = 1 << 3, // next \\end ends the parsing process FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing FLAG_TEXTMODE = 1 << 5, // we are in a box - FLAG_ITEM = 1 << 6, // read a (possibly braced token) + FLAG_ITEM = 1 << 6, // read a (possibly braced) token FLAG_LEAVE = 1 << 7, // leave the loop at the end FLAG_SIMPLE = 1 << 8, // next $ leaves the loop FLAG_EQUATION = 1 << 9, // next \] leaves the loop @@ -1098,6 +1098,33 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, } } + else if (t.cs() == "unit") { + // Allowed formats \unit[val]{unit} + MathData ar; + parse(ar, FLAG_OPTION, mode); + if (ar.size()) { + cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNIT))); + cell->back().nucleus()->cell(0) = ar; + parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); + } else { + cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNIT, 1))); + parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); + } + } + else if (t.cs() == "unitfrac") { + // Here allowed formats are \unitfrac[val]{num}{denom} + MathData ar; + parse(ar, FLAG_OPTION, mode); + if (ar.size()) { + cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC, 3))); + cell->back().nucleus()->cell(2) = ar; + } else { + cell->push_back(MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC))); + } + parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); + parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode); + } + else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") { cell->push_back(createInsetMath(t.cs())); parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode); @@ -1254,9 +1281,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs() == "kern") { -#ifdef WITH_WARNINGS -#warning A hack... -#endif + // FIXME: A hack... docstring s; while (true) { Token const & t = getToken();