Fix math class code in InsetMathColor

The current code is too naïve and asserts on MC_UNKNOWN class.

See discussion here:
https://marc.info/?l=lyx-devel&m=161267112524889&w=2
This commit is contained in:
Jean-Marc Lasgouttes 2021-02-08 13:13:21 +01:00
parent 983d327fe3
commit c311451518
3 changed files with 15 additions and 6 deletions

View File

@ -98,12 +98,8 @@ void InsetMathColor::write(TeXMathStream & os) const
{
// We have to ensure correct spacing when the front and/or back
// atoms are not ordinary ones (bug 11827).
docstring const frontclass =
!cell(0).empty() ? class_to_string(cell(0).front()->mathClass())
: from_ascii("mathord");
docstring const backclass =
!cell(0).empty() ? class_to_string(cell(0).back()->mathClass())
: from_ascii("mathord");
docstring const frontclass = class_to_string(cell(0).firstMathClass());
docstring const backclass = class_to_string(cell(0).lastMathClass());
bool adjchk = os.latex() && !os.inMathClass() && (normalcolor(color_) || oldstyle_);
bool adjust_front = frontclass != "mathord" && adjchk;
bool adjust_back = backclass != "mathord" && adjchk;

View File

@ -969,6 +969,17 @@ MathClass MathData::mathClass() const
}
MathClass MathData::firstMathClass() const
{
for (MathAtom const & at : *this) {
MathClass mc = at->mathClass();
if (mc != MC_UNKNOWN)
return mc;
}
return MC_ORD;
}
MathClass MathData::lastMathClass() const
{
MathClass res = MC_ORD;

View File

@ -144,6 +144,8 @@ public:
void drawT(TextPainter & pi, int x, int y) const;
/// approximate mathclass of the data
MathClass mathClass() const;
/// math class of first interesting element
MathClass firstMathClass() const;
/// math class of last interesting element
MathClass lastMathClass() const;
/// is the cell in display style