]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathParser.cpp
use FileName::isDirectory()
[lyx.git] / src / mathed / MathParser.cpp
index 255dbadc9e4e2bc345a0011c73559a788baf3da1..fc707e5a9ff4bded7710a911442a8a4f7053459f 100644 (file)
@@ -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();