Re: [LyX/master] Improve fractions bar

2016-11-22 Thread Jean-Marc Lasgouttes

Le 22/11/2016 à 10:52, Enrico Forestieri a écrit :


Another thing that would benefit from the TeXbook is typesetting of
sub/superscripts.


http://www.lyx.org/trac/changeset/17471/lyxsvn
http://www.lyx.org/trac/changeset/17518/lyxsvn


You are right of course. I did see it (I saw part of the code, but never 
searched for the commits) but then I probably forgot. There were some 
cases where I felt that the superscripts were too high, but I do not 
remember which ones. I'll chime in if I find examples.


JMarc



Re: [LyX/master] Improve fractions bar

2016-11-22 Thread Enrico Forestieri
On Tue, Nov 22, 2016 at 10:16:13AM +0100, Jean-Marc Lasgouttes wrote:

> Le 22/11/2016 à 00:56, Guillaume Munch a écrit :
> > Never mind, I found it. Now, did you have a plan for implementing the
> > various \fontdimen in LyX ? (see the hack I had to resort to just for
> > determining the math axis...)
> 
> No, but it seemed to me at the time that at least some of these dimen are
> available to us. I'll try to return to it.
> 
> Another thing that would benefit from the TeXbook is typesetting of
> sub/superscripts.

http://www.lyx.org/trac/changeset/17471/lyxsvn
http://www.lyx.org/trac/changeset/17518/lyxsvn

-- 
Enrico


Re: [LyX/master] Improve fractions bar

2016-11-22 Thread Jean-Marc Lasgouttes

Le 22/11/2016 à 00:56, Guillaume Munch a écrit :

Never mind, I found it. Now, did you have a plan for implementing the
various \fontdimen in LyX ? (see the hack I had to resort to just for
determining the math axis...)


No, but it seemed to me at the time that at least some of these dimen 
are available to us. I'll try to return to it.


Another thing that would benefit from the TeXbook is typesetting of 
sub/superscripts.


JMarc



Re: [LyX/master] Improve fractions bar

2016-11-21 Thread Guillaume Munch

Le 22/11/2016 à 00:32, Guillaume Munch a écrit :

Le 21/11/2016 à 17:33, Jean-Marc Lasgouttes a écrit :


* did you try to look at what TeX does and see what can be picked from
there? The relevant rules are 15(a-e). It is not funny reading, but last
time I looked I conlcuded that part of that could be implemented.


Thanks for the reference. I used to have a TeXbook, but books made of
paper are not easy to move around, so it ended up being given away
before it could be of any use. Do you have another source for this
algorithm?



Never mind, I found it. Now, did you have a plan for implementing the
various \fontdimen in LyX ? (see the hack I had to resort to just for
determining the math axis...)




Re: [LyX/master] Improve fractions bar

2016-11-21 Thread Guillaume Munch

Le 21/11/2016 à 17:33, Jean-Marc Lasgouttes a écrit :


It is nice to give some love to \frac (it was somewhere on my to do
list). I have not tried it yet, but I have questions:

* why not use FontMetrics::lineWidth for the witdth of the line? You do
not want to use the same width for a fraction in textstyle or in
scriptstyle.


First because TeX itself always uses the same thin line whatever the
font size. Also, following your suggestion I tried, and you can get 1px
lines next to 2px lines, so the result is not very nice.



* did you try to look at what TeX does and see what can be picked from
there? The relevant rules are 15(a-e). It is not funny reading, but last
time I looked I conlcuded that part of that could be implemented.


Thanks for the reference. I used to have a TeXbook, but books made of
paper are not easy to move around, so it ended up being given away
before it could be of any use. Do you have another source for this
algorithm?



Re: [LyX/master] Improve fractions bar

2016-11-21 Thread Jean-Marc Lasgouttes

Le 21/11/2016 à 01:17, Guillaume Munch a écrit :

commit 71ce34e821e9bb4a6e899fe939609684375be160
Author: Guillaume Munch 
Date:   Sun Nov 20 22:00:08 2016 +0100

Improve fractions bar

* The bar grows with the zoom according to MetricsBase::solidLineThickness()

* The spacing around the bar grows with the font size.


It is nice to give some love to \frac (it was somewhere on my to do 
list). I have not tried it yet, but I have questions:


* why not use FontMetrics::lineWidth for the witdth of the line? You do 
not want to use the same width for a fraction in textstyle or in 
scriptstyle.


* did you try to look at what TeX does and see what can be picked from 
there? The relevant rules are 15(a-e). It is not funny reading, but last 
time I looked I conlcuded that part of that could be implemented.


JMarc


---
 src/mathed/InsetMathFrac.cpp |   28 ++--
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp
index 6b768c9..8aed948 100644
--- a/src/mathed/InsetMathFrac.cpp
+++ b/src/mathed/InsetMathFrac.cpp
@@ -242,8 +242,8 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & 
dim) const
cell(0).metrics(mi, dim0);
cell(1).metrics(mi, dim1);
dim.wid = max(dim0.wid, dim1.wid) + 2;
-   dim.asc = dim0.height() + 2 + dy;
-   dim.des = max(0, dim1.height() + 2 - dy);
+   dim.asc = dim0.height() + dy/2 + dy;
+   dim.des = max(0, dim1.height() + dy/2 - dy);
}
} //switch (kind_)
metricsMarkers(mi, dim);
@@ -294,7 +294,8 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) 
const
// Diag line:
pi.pain.line(xx + dim0.wid + 1, y + dim.des - 2,
 xx + dim0.wid + 6, y - dim.asc + 2,
-pi.base.font.color());
+pi.base.font.color(), pi.pain.line_solid,
+pi.base.solidLineThickness());
}
break;

@@ -326,13 +327,18 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) 
const
(kind_ == CFRACRIGHT) ? x + dim.wid - dim0.wid - 2 :
// center
m - dim0.wid / 2;
-   cell(0).draw(pi, xx, y - dim0.des - 2 - dy);
+   // take dy/2 for the spacing around the horizontal line. This is
+   // arbitrary. In LaTeX it is more complicated to ensure that 
displayed
+   // fractions line up next to each other.
+   cell(0).draw(pi, xx, y - dim0.des - dy/2 - dy);
// center
-   cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - dy);
+   cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + dy/2 - dy);
// horizontal line
if (kind_ != ATOP)
pi.pain.line(x + 1, y - dy,
-x + dim.wid - 2, y - dy, 
pi.base.font.color());
+x + dim.wid - 2, y - dy,
+pi.base.font.color(), pi.pain.line_solid,
+pi.base.solidLineThickness());
}
} //switch (kind_)
drawMarkers(pi, x, y);
@@ -632,8 +638,8 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & 
dim) const
mi.base.changeFrac();
cell(0).metrics(mi, dim0);
cell(1).metrics(mi, dim1);
-   dim.asc = dim0.height() + 4 + dy;
-   dim.des = max(0, dim1.height() + 4 - dy);
+   dim.asc = dim0.height() + 1 + dy/2 + dy;
+   dim.des = max(0, dim1.height() + 1 + dy/2 - dy);
dim.wid = max(dim0.wid, dim1.wid) + 2 * dw(dim.height()) + 4;
metricsMarkers2(mi, dim);
 }
@@ -657,8 +663,10 @@ void InsetMathBinom::draw(PainterInfo & pi, int x, int y) 
const
(kind_ == DBINOM) ? 
pi.base.font.changeStyle(LM_ST_DISPLAY) :
(kind_ == TBINOM) ? 
pi.base.font.changeStyle(LM_ST_SCRIPT) :
pi.base.changeFrac();
-   cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - dy);
-   cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - dy);
+   // take dy both for the vertical alignment and for the spacing 
between
+   // cells
+   cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - dy/2 - dy);
+   cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + dy/2 - dy);
}
// draw the brackets and the marker
mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()),