diff --git a/lib/ui/stdtoolbars.inc b/lib/ui/stdtoolbars.inc index 1431a67e5c..f1fb9c2bbd 100644 --- a/lib/ui/stdtoolbars.inc +++ b/lib/ui/stdtoolbars.inc @@ -273,7 +273,8 @@ ToolbarSet Toolbar "frac-square" "Fractions" Item "Standard \\frac" "math-insert \frac" Item "No hor. line \\atop" "math-insert \atop" - Item "Nice \\nicefrac" "math-insert \nicefrac" + Item "Nice (3/4) \\nicefrac" "math-insert \nicefrac" + Item "Units (km/h) \\unitfrac" "math-insert \unitfrac" Item "Text frac (amsmath) \\tfrac" "math-insert \tfrac" Item "Display frac (amsmath) \\dfrac" "math-insert \dfrac" Item "Binomial \\choose" "math-insert \choose" diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index a76cceda9e..a9ff651aa8 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -403,7 +403,7 @@ char const * simplefeatures[] = { "dvipost", "fancybox", "calc", - "nicefrac", + "units", "tipa", "framed", "pdfcolmk", diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index b77dc0f508..867b04d96a 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -54,6 +54,11 @@ bool InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = cell(0).width() + cell(1).width() + 5; dim.asc = cell(0).height() + 5; dim.des = cell(1).height() - 5; + } else if (kind_ == UNITFRAC) { + ShapeChanger dummy2(mi.base.font, Font::UP_SHAPE); + dim.wid = cell(0).width() + cell(1).width() + 5; + dim.asc = cell(0).height() + 5; + dim.des = cell(1).height() - 5; } else { dim.wid = std::max(cell(0).width(), cell(1).width()) + 2; dim.asc = cell(0).height() + 2 + 5; @@ -77,16 +82,24 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const y - cell(0).descent() - 5); cell(1).draw(pi, x + cell(0).width() + 5, y + cell(1).ascent() / 2); - pi.pain.line(x + cell(0).width(), - y + dim_.des - 2, - x + cell(0).width() + 5, - y - dim_.asc + 2, Color::math); + } else if (kind_ == UNITFRAC) { + ShapeChanger dummy2(pi.base.font, Font::UP_SHAPE); + cell(0).draw(pi, x + 2, + y - cell(0).descent() - 5); + cell(1).draw(pi, x + cell(0).width() + 5, + y + cell(1).ascent() / 2); } else { cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5); cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 2 - 5); } + if (kind_ == NICEFRAC || kind_ == UNITFRAC) { + pi.pain.line(x + cell(0).width(), + y + dim_.des - 2, + x + cell(0).width() + 5, + y - dim_.asc + 2, Color::math); + } if (kind_ == FRAC || kind_ == OVER) pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, Color::math); @@ -111,7 +124,7 @@ void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1); cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent()); // ASCII art: ignore niceties - if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC) + if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC || kind_ == UNITFRAC) pain.horizontalLine(x, y, dim_.width()); } @@ -128,6 +141,7 @@ void InsetMathFrac::write(WriteStream & os) const break; case FRAC: case NICEFRAC: + case UNITFRAC: InsetMathNest::write(os); break; } @@ -143,6 +157,8 @@ docstring InsetMathFrac::name() const return from_ascii("over"); case NICEFRAC: return from_ascii("nicefrac"); + case UNITFRAC: + return from_ascii("unitfrac"); case ATOP: return from_ascii("atop"); } @@ -183,8 +199,8 @@ void InsetMathFrac::mathmlize(MathStream & os) const void InsetMathFrac::validate(LaTeXFeatures & features) const { - if (kind_ == NICEFRAC) - features.require("nicefrac"); + if (kind_ == NICEFRAC || kind_ == UNITFRAC) + features.require("units"); InsetMathNest::validate(features); } diff --git a/src/mathed/InsetMathFrac.h b/src/mathed/InsetMathFrac.h index c03157bdaa..9b7a0ad3be 100644 --- a/src/mathed/InsetMathFrac.h +++ b/src/mathed/InsetMathFrac.h @@ -27,7 +27,8 @@ public: FRAC, OVER, ATOP, - NICEFRAC + NICEFRAC, + UNITFRAC }; /// diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 85d0b3f60b..20af5fc592 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -370,6 +370,8 @@ MathAtom createInsetMath(docstring const & s) return MathAtom(new InsetMathFrac(InsetMathFrac::OVER)); if (s == "nicefrac") return MathAtom(new InsetMathFrac(InsetMathFrac::NICEFRAC)); + if (s == "unitfrac") + return MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC)); //if (s == "infer") // return MathAtom(new MathInferInset); if (s == "atop")