Add space before display math that starts a paragraph

This extra spacing was missing and is important for detecting extra
par breaks before equations (which are most of the times not wanted).

To do that, add a new member vmode to MetricsInfo which is equivalent
to LaTeX's \ifvmode (start of paragraph).

If in vmode, add the equivalent of an empty line before a display math inset.

At the same time, tweak value of \(above|below)displayskip, which was
12pt, whereas LaTeX uses 10pt in 10pt size (our reference).

Fixes bug #11891.
This commit is contained in:
Jean-Marc Lasgouttes 2020-08-25 13:05:29 +02:00
parent 3c1b4a5d7e
commit cc349fd031
4 changed files with 23 additions and 11 deletions

View File

@ -119,8 +119,8 @@ int MetricsBase::inPixels(Length const & len) const
/////////////////////////////////////////////////////////////////////////
MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
MacroContext const & mc)
: base(bv, font, textwidth), macrocontext(mc)
MacroContext const & mc, bool vm)
: base(bv, font, textwidth), macrocontext(mc), vmode(vm)
{}

View File

@ -95,12 +95,14 @@ public:
MetricsInfo();
///
MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
MacroContext const & mc);
MacroContext const & mc, bool vm);
///
MetricsBase base;
/// The context to resolve macros
MacroContext const & macrocontext;
/// Are we at the start of a paragraph (vertical mode)?
bool vmode;
};

View File

@ -517,7 +517,7 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
Font const & font = e.inset->inheritFont() ?
displayFont(pit, e.pos) : bufferfont;
MacroContext mc(&buffer, parPos);
MetricsInfo mi(bv_, font.fontInfo(), w, mc);
MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0);
e.inset->metrics(mi, dim);
if (!insetCache.has(e.inset) || insetCache.dim(e.inset) != dim) {
insetCache.add(e.inset, dim);

View File

@ -56,6 +56,7 @@
#include "graphics/PreviewLoader.h"
#include "frontends/alert.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "support/convert.h"
@ -520,9 +521,18 @@ bool previewTooSmall(Dimension const & dim)
void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
{
// true value in LaTeX is 12pt plus 3pt minus 9pt
// FIXME: even better would be to handle the short skip case.
int const display_margin = display() ? mi.base.inPixels(Length(12, Length::PT)) : 0;
/* Compute \(above|below)displayskip
true value in LaTeX is 10pt plus 2pt minus 5pt (in normal size at 10pt)
FIXME: make this dependent of current size? (minor improvement)
FIXME: if would be nice if this was not part of the inset, but
just increased the row ascent/descent.
FIXME: even better would be to handle the short skip case.
*/
int const bottom_display_margin = mi.base.inPixels(Length(10, Length::PT));
int top_display_margin = bottom_display_margin;
// at start of paragraph, add an empty line
if (mi.vmode)
top_display_margin += theFontMetrics(mi.base.font).maxHeight() + 2;
if (previewState(mi.base.bv)) {
preview_->metrics(mi, dim);
@ -535,8 +545,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
// value was hardcoded to 1 pixel
dim.wid += mi.base.bv->zoomedPixels(1) ;
if (display()) {
dim.asc += display_margin;
dim.des += display_margin;
dim.asc += top_display_margin;
dim.des += bottom_display_margin;
}
}
return;
@ -577,8 +587,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
if (display()) {
dim.asc += display_margin;
dim.des += display_margin;
dim.asc += top_display_margin;
dim.des += bottom_display_margin;
}
// reserve some space for marker.