X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathParser.cpp;h=0c8ee7765a92c52cd1e22f6baaeefa7d9aa6d0cd;hb=58ab972f714309aa87e7d956ceda00e18337875f;hp=2a63b824b3a9155056d75f2749c7048e3a6a5b86;hpb=31059d1741933d95403e7f07ed033cae482f778b;p=lyx.git diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 2a63b824b3..0c8ee7765a 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" @@ -134,7 +134,7 @@ bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow, return false; } } - grid.vcrskip(LyXLength(to_utf8(vskip)), cellrow - 1); + grid.vcrskip(Length(to_utf8(vskip)), cellrow - 1); grid.rowinfo(cellrow - 1).allow_pagebreak_ = allow_pagebreak; return true; } @@ -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 @@ -292,7 +292,7 @@ ostream & operator<<(ostream & os, Token const & t) docstring const & cs = t.cs(); // FIXME: For some strange reason, the stream operator instanciate // a new Token before outputting the contents of t.cs(). - // Because of this the line + // Because of this the line // os << '\\' << cs; // below becomes recursive. // In order to avoid that we return early: @@ -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); @@ -1106,7 +1133,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "ref" || t.cs() == "prettyref" || t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") { - cell->push_back(MathAtom(new RefInset(t.cs()))); + cell->push_back(MathAtom(new InsetMathRef(t.cs()))); parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, 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();