From f1dd80f464b46f6112f6c9a64a70dd3da76cbe7f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 12 May 2017 15:07:02 +0200 Subject: [PATCH] Proper GUI feedback for leqno option With these changes, equation numbers are shown properly on screen. When setting is default, we guess the side using these two rules * ams(art|book) and siamltex classes are leqno by default. This is signalled because the classes provide "leqno" (in amsdefs.inc). If there are other classes that do this in output, the relevant classes should be updated. * the language arabic_arabi also sets leqno by default. This is currently hardcoded for lack of a better idea. Besides, a few bugs are fixed: * use mathrm instead of mathbf for numbers metrics * set spacing between maths and labels in inches --- lib/layouts/amsdefs.inc | 3 +++ src/BufferParams.cpp | 13 +++++++++++++ src/BufferParams.h | 4 ++++ src/mathed/InsetMathHull.cpp | 31 +++++++++++++++++++++++++------ 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/layouts/amsdefs.inc b/lib/layouts/amsdefs.inc index bdf497bb26..5a96707585 100644 --- a/lib/layouts/amsdefs.inc +++ b/lib/layouts/amsdefs.inc @@ -7,6 +7,9 @@ # Including the maths stuff Format 63 +# By default AMS articles & books use leqno option (as SIAM journals). +Provides leqno 1 + # the environments copied from the old amsart.layout are: # - Bibliography # - Title diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 02dda81de7..52fd35bc20 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -667,6 +667,19 @@ void BufferParams::setDefSkip(VSpace const & vs) } +BufferParams::MathNumber BufferParams::getMathNumber() const +{ + if (math_number != DEFAULT) + return math_number; + // FIXME: do not hardcode language here + else if (language->lang() == "arabic_arabi" + || documentClass().provides("leqno")) + return LEFT; + else + return RIGHT; +} + + string BufferParams::readToken(Lexer & lex, string const & token, FileName const & filepath) { diff --git a/src/BufferParams.h b/src/BufferParams.h index c913031ef8..51029478e4 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -114,6 +114,10 @@ public: /// number formulas on left/right/default MathNumber math_number; + /// Convenience function for display: like math_number, but + /// DEFAULT is replaced by the best guess we have. + MathNumber getMathNumber() const; + /** Whether paragraphs are separated by using a indent like in * articles or by using a little skip like in letters. */ diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 3e897df0e1..86c403fb37 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -558,13 +558,14 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const } if (numberedType()) { - Changer dummy = mi.base.changeFontSet("mathbf"); + Changer dummy = mi.base.changeFontSet("mathrm"); int l = 0; for (row_type row = 0; row < nrows(); ++row) l = max(l, mathed_string_width(mi.base.font, nicelabel(row))); if (l) - dim.wid += 30 + l; + // Value was hardcoded to 30 pixels + dim.wid += Length(0.3, Length::IN).inPixels(mi.base) + l; } // reserve some space for marker. @@ -644,18 +645,36 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const Changer dummy2 = pi.base.font.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT); - InsetMathGrid::draw(pi, x + 1, y); + int xmath = x; + BufferParams::MathNumber const math_number = buffer().params().getMathNumber(); + if (numberedType() && math_number == BufferParams::LEFT) { + Changer dummy = pi.base.changeFontSet("mathrm"); + int l = 0; + for (row_type row = 0; row < nrows(); ++row) + l = max(l, mathed_string_width(pi.base.font, nicelabel(row))); + + if (l) + // Value was hardcoded to 30 pixels + xmath += Length(0.3, Length::IN).inPixels(pi.base) + l; + } + + InsetMathGrid::draw(pi, xmath + 1, y); drawMarkers2(pi, x, y); if (numberedType()) { - int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20; + Changer dummy = pi.base.changeFontSet("mathrm"); for (row_type row = 0; row < nrows(); ++row) { int const yy = y + rowinfo_[row].offset_; - Changer dummy = pi.base.changeFontSet("mathrm"); docstring const nl = nicelabel(row); - pi.draw(xx, yy, nl); + if (math_number == BufferParams::LEFT) + pi.draw(x, yy, nl); + else { + int l = mathed_string_width(pi.base.font, nl); + pi.draw(x + dim.wid - l, yy, nl); + } } } + // drawing change line if (canPaintChange(*bv)) pi.change_.paintCue(pi, x + 1, y + 1 - dim.asc,