[LyX/master] Fix math class code in InsetMathColor
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Mon Feb 8 13:18:15 UTC 2021
commit c3114515180de263597be65cc9b8724798278b7f
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Mon Feb 8 13:13:21 2021 +0100
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
---
src/mathed/InsetMathColor.cpp | 8 ++------
src/mathed/MathData.cpp | 11 +++++++++++
src/mathed/MathData.h | 2 ++
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/mathed/InsetMathColor.cpp b/src/mathed/InsetMathColor.cpp
index f2f9116..13e6fa4 100644
--- a/src/mathed/InsetMathColor.cpp
+++ b/src/mathed/InsetMathColor.cpp
@@ -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;
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index c9db36c..d3ce3a3 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -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;
diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h
index ebc59d4..865742d 100644
--- a/src/mathed/MathData.h
+++ b/src/mathed/MathData.h
@@ -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
More information about the lyx-cvs
mailing list