QuantEcon / sphinxcontrib-jupyter

A Sphinx Extension for Generating Jupyter Notebooks
BSD 3-Clause "New" or "Revised" License
77 stars 23 forks source link

FEAT: contextual equation numbering for labelled display math #47

Closed mmcky closed 6 years ago

mmcky commented 6 years ago

This PR re-adds equation numbering support for display formulae in a contextual way. If an equation has a label then it is wrapped in an html table with clear borders to enable proper placement of the equation number provided by sphinx.

jstac commented 6 years ago

I see what you mean. It's not ideal, to be honest.

Can we not have the equation number fully right aligned? Perhaps then the equation will be more centered?

mmcky commented 6 years ago

What currently happens is an html table is drawn and the math is enclosed in a cell that is 75% of the width of the page and then centred within that column. I think the problem with right align is there is no common datum point as the look and feel of that will depend on the width of each equation.

Another option (for now) would be to add a global conf.py property global_labelled_math = True that forces the use of html tables for positioning of math for common center point. This would remove the need to pre-parse but adds something to the configuration requirements, and all equations would be slightly left of centre.

mmcky commented 6 years ago

What I might try is reduce the table size for the numbers column to fit within a 10% width column, with a total table width of 110% of the paragraph width. Maybe that would work.

mmcky commented 6 years ago

Ah for the time being what I will do is add a column on the left also to balance the table to match.

<a id='equation-eq_old1'></a>
<table width=100%>
<tr style='background-color: #FFFFFF !important;'>
<td width=5%></td>
<td width=90%>
$$
m_t - p_t = -\alpha(p_{t+1} - p_t) \: , \: \alpha > 0
$$
</td><td width=5% style='text-align:center !important;'>
(1)
</td></tr></table>

$$ m_t - p_t = -\alpha(p_{t+1} - p_t) \: , \: \alpha > 0 $$ (1)
mmcky commented 6 years ago

Currently I have implemented this as 3 columns with width=10% for left and right to ensure equations remain balanced. This may present an issue for large numbers of labelled equations.

This is what the test notebook renders like:

image

mmcky commented 6 years ago

In updating the test -- another style question arises. The labelled equations have a smaller font.

image

jstac commented 6 years ago

This looks great @mmcky, nice work.

jstac commented 6 years ago

@mmcky A differnt issue, but I feel like the text lines are too long and margins are too small. It's well known that long lines put more strain on the eyes. If you agree I'll open a separate issue.

mmcky commented 6 years ago

Thanks @jstac let's open a different issue re: line length.