lyx_mirror/src/mathed/MathClass.cpp
Jean-Marc Lasgouttes 361bd53bc3 Introduce the notion of math class
This done according to the TeXbook. This class replaces the individual
isMathXXX() methods. The mathClass() method (currently unused) is
provided for the following insets:

 * InsetMathChar (with a revised list of affected characters)
 * InsetMathSymbol: the class is given by the `extra' field
   Operators defined in lib/symbols (e.g. \log) are MC_OP
 * InsetMathFrac is MC_INNER (except nicefrac and units)
 * InsetDelimiters is MC_INNER
 * InsetStackrel is MC_REL
 * The class of InsetScript is the class of the last element of its
   nucleus (yes, it is a hack, but doing it right is more work).

Remove the explicit spacing that was done in the different insets. The spacing
will be reintroduced properly in a forthcoming commit.
2016-11-16 15:21:52 +01:00

83 lines
1.3 KiB
C++

/**
* \file MathClass.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "MathClass.h"
#include "support/docstring.h"
#include "support/lassert.h"
using namespace std;
namespace lyx {
docstring const class_to_string(MathClass const mc)
{
string s;
switch (mc) {
case MC_ORD:
s = "mathord";
break;
case MC_OP:
s = "mathop";
break;
case MC_BIN:
s = "mathbin";
break;
case MC_REL:
s = "mathrel";
break;
case MC_OPEN:
s = "mathopen";
break;
case MC_CLOSE:
s = "mathclose";
break;
case MC_PUNCT:
s = "mathpunct";
break;
case MC_INNER:
s = "mathinner";
break;
case MC_UNKNOWN:
LATTEST(false);
s = "mathord";
}
return from_ascii(s);
}
MathClass string_to_class(docstring const &s)
{
if (s == "mathop")
return MC_OP;
else if (s == "mathbin")
return MC_BIN;
else if (s == "mathrel")
return MC_REL;
else if (s == "mathopen")
return MC_OPEN;
else if (s == "mathclose")
return MC_CLOSE;
else if (s == "mathpunct")
return MC_PUNCT;
else if (s == "mathinner")
return MC_INNER;
else if (s == "mathord")
return MC_ORD;
else
return MC_UNKNOWN;
}
} // namespace lyx