mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Display the correct horizontal alignment in AMS environments
A longstanding problem... (related: #1861) The columns in AMS math environments have a fixed alignment (colAlign() in InsetMathGrid.cpp). We set this alignment for display (Georg's displayColAlign()) in InsetMathHull and InsetMathSplit. This is done according to tests and documentation for the various environments. There is also some mechanical code factoring via colAlign(). Finally, I disable setting the horizontal alignment in InsetMathSplit, which has no impact on the LaTeX output, and has no longer any impact on the screen. (As for vertical alignment I discovered that it was in fact customisable for \aligned & friends! I hope that the more faithful interface will let other users discover that too.)
This commit is contained in:
parent
3a4af5a3e1
commit
f3b70fd2cd
@ -1827,4 +1827,29 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
char InsetMathGrid::colAlign(HullType type, col_type col)
|
||||
{
|
||||
switch (type) {
|
||||
case hullEqnArray:
|
||||
return "rcl"[col % 3];
|
||||
|
||||
case hullMultline:
|
||||
case hullGather:
|
||||
return 'c';
|
||||
|
||||
case hullAlign:
|
||||
case hullAlignAt:
|
||||
case hullXAlignAt:
|
||||
case hullXXAlignAt:
|
||||
case hullFlAlign:
|
||||
return "rl"[col & 1];
|
||||
|
||||
default:
|
||||
return 'c';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -258,10 +258,11 @@ protected:
|
||||
virtual docstring eocString(col_type col, col_type lastcol) const;
|
||||
/// splits cells and shifts right part to the next cell
|
||||
void splitCell(Cursor & cur);
|
||||
/// Column aligmment for display of cell \p idx.
|
||||
/// Column alignment for display of cell \p idx.
|
||||
/// Must not be written to file!
|
||||
virtual char displayColAlign(idx_type idx) const;
|
||||
|
||||
/// The value of a fixed col align for a certain hull type
|
||||
static char colAlign(HullType type, col_type col);
|
||||
|
||||
/// row info.
|
||||
/// rowinfo_[nrows()] is a dummy row used only for hlines.
|
||||
|
@ -349,28 +349,38 @@ bool InsetMathHull::idxLast(Cursor & cur) const
|
||||
}
|
||||
|
||||
|
||||
// FIXME: InsetMathGrid should be changed to let the real column alignment be
|
||||
// given by a virtual method like displayColAlign, because the values produced
|
||||
// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect
|
||||
// that for the moment the values produced by defaultColAlign are not used,
|
||||
// notably because alignment is not implemented in the LyXHTML output.
|
||||
char InsetMathHull::defaultColAlign(col_type col)
|
||||
{
|
||||
if (type_ == hullEqnArray)
|
||||
return "rcl"[col];
|
||||
if (type_ == hullMultline)
|
||||
return 'c';
|
||||
if (type_ == hullGather)
|
||||
return 'c';
|
||||
if (type_ >= hullAlign)
|
||||
return "rl"[col & 1];
|
||||
return 'c';
|
||||
return colAlign(type_, col);
|
||||
}
|
||||
|
||||
|
||||
char InsetMathHull::displayColAlign(idx_type idx) const
|
||||
{
|
||||
if (type_ == hullMultline) {
|
||||
switch (type_) {
|
||||
case hullMultline: {
|
||||
row_type const r = row(idx);
|
||||
if (r == 0)
|
||||
return 'l';
|
||||
if (r == nrows() - 1)
|
||||
return 'r';
|
||||
return 'c';
|
||||
}
|
||||
case hullEqnArray:
|
||||
case hullGather:
|
||||
case hullAlign:
|
||||
case hullAlignAt:
|
||||
case hullXAlignAt:
|
||||
case hullXXAlignAt:
|
||||
case hullFlAlign:
|
||||
return colAlign(type_, col(idx));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return InsetMathGrid::displayColAlign(idx);
|
||||
}
|
||||
|
@ -48,20 +48,45 @@ Inset * InsetMathSplit::clone() const
|
||||
}
|
||||
|
||||
|
||||
// FIXME: InsetMathGrid should be changed to let the real column alignment be
|
||||
// given by a virtual method like displayColAlign, because the values produced
|
||||
// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect
|
||||
// that for the moment the values produced by defaultColAlign are not used,
|
||||
// notably because alignment is not implemented in the LyXHTML output.
|
||||
char InsetMathSplit::defaultColAlign(col_type col)
|
||||
{
|
||||
if (name_ == "split")
|
||||
return 'l';
|
||||
if (name_ == "gathered")
|
||||
return 'c';
|
||||
if (name_ == "aligned" || name_ == "align")
|
||||
return (col & 1) ? 'l' : 'r';
|
||||
if (name_ == "alignedat")
|
||||
return (col & 1) ? 'l' : 'r';
|
||||
if (name_ == "lgathered")
|
||||
return 'l';
|
||||
if (name_ == "rgathered")
|
||||
return 'r';
|
||||
if (name_ == "split"
|
||||
|| name_ == "aligned"
|
||||
|| name_ == "align"
|
||||
|| name_ == "alignedat")
|
||||
return colAlign(hullAlign, col);
|
||||
return 'l';
|
||||
}
|
||||
|
||||
|
||||
char InsetMathSplit::displayColAlign(idx_type idx) const
|
||||
{
|
||||
if (name_ == "gathered")
|
||||
return 'c';
|
||||
if (name_ == "lgathered")
|
||||
return 'l';
|
||||
if (name_ == "rgathered")
|
||||
return 'r';
|
||||
if (name_ == "split"
|
||||
|| name_ == "aligned"
|
||||
|| name_ == "align"
|
||||
|| name_ == "alignedat")
|
||||
return colAlign(hullAlign, col(idx));
|
||||
return InsetMathGrid::displayColAlign(idx);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
InsetMathGrid::draw(pi, x, y);
|
||||
@ -82,6 +107,10 @@ bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
flag.setEnabled(false);
|
||||
return true;
|
||||
}
|
||||
if (s == "align-left" || s == "align-center" || s == "align-right") {
|
||||
flag.setEnabled(false);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
///
|
||||
char defaultColAlign(col_type);
|
||||
///
|
||||
char displayColAlign(idx_type idx) const;
|
||||
///
|
||||
InsetCode lyxCode() const { return MATH_SPLIT_CODE; }
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user