QuantEcon / sphinxcontrib-jupyter

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

Rendering of small equations with labels has layout issues #117

Closed jlperla closed 5 years ago

jlperla commented 6 years ago

The jupinx master seems to have flaws in the display with equations. Create something like

.. math::
    :label: test

    v = p + \beta v

And the generated HTML is

<a id='equation-test'></a>
<table width=100%><tr style='background-color: #FFFFFF !important;'>
<td width=10%></td>
<td width=80%>
$$
v = p + \beta v
$$
</td><td width=10% style='text-align:center !important;'>
(1)
</td></tr></table>

which wrapped the equation in a weird way because of the decrease in the width of the table

cc: @mmcky any thoughts on easy workaround?

mmcky commented 6 years ago

thanks @jlperla. I will add your example to our test set and check it out. Perhaps our css is altering the look of labeled equations and not working correctly on default nbconvert

mmcky commented 6 years ago

I also like you're idea of using latex \tag{#}

mmcky commented 6 years ago

@jlperla if you get the chance can you post the output. The test case packaged with the extension has a labelled equation that is a bit smaller than the original equation (without labels) but I don't know what you mean with strange wrapping.

image
mmcky commented 6 years ago

I have added the above test case to the test notebook math.rst and it renders like this:

image
mmcky commented 6 years ago

is your issue at the notebook level or post nbconvert to html?

jlperla commented 6 years ago

Notebooks. I am not sure how to generate html yet!

mmcky commented 6 years ago

are you getting rendering that is different to the screenshot above?

jlperla commented 6 years ago

image

The above is a rendered from the following rst in Jupytelab (generated using ubuntu on WSL, not that it matters, and displaying in chrome)


Fixed-Point Maps
----------------------------

Consider the simple equation, where the scalars :math:`p,\beta` are given, and  :math:`v` is the scalar we wish to solve for

.. math::
    :label: vfixed

    v = p + \beta v

Of course, in this simple example, with parameter restrictions this can be solved as :math:`v = p/(1 - \beta)`

Rearrange the equation in terms of a map :math:`f(x) : \mathbb R \to \mathbb R`

.. math::

    v = f(v)

where

.. math::

    f(v) := p + \beta v

Therefore, a fixed point :math:`v^*` of :math:`f(\cdot)` is a solution to the above problem
mmcky commented 6 years ago

Hmm. Thanks @jlperla. I can't replicate it on my local. Are you by chance using sphinx >= 1.8? I haven't tested on the newly released 1.8

image
jlperla commented 6 years ago

Key version numbers from conda list are

sphinx                    1.7.4                    py36_0
sphinxcontrib             1.0              py36h6d0f590_1
sphinxcontrib-bibtex      0.4.0                     <pip>
sphinxcontrib-jupyter     0.2b0.dev20180929           <pip>
sphinxcontrib-jupyter     0.2b0.dev20180827           <pip>
sphinxcontrib-websupport  1.0.1            py36hb5cb234_1

But I think this is probably a html/css problem, as opposed to a generation problem

mmcky commented 6 years ago

I'm using sphinx=1.7.8 but as you say I don't think that is the issue (as the html output is the same). Could a local extension be altering the alignment of equations. My environment has not jupyter extensions installed with no specific html/css adjustment to base jupyter.

jlperla commented 6 years ago

My jupyter has no extensions, but perhaps it is old. The versions are

jupyter                   1.0.0                    py36_4
jupyter_client            5.2.3                    py36_0
jupyter_console           5.2.0            py36he59e554_1
jupyter_core              4.4.0            py36h7c827e3_0
jupyterlab                0.32.1                   py36_0
jupyterlab_launcher       0.10.5                   py36_0

I will to upgrade jupyterlab tomorrow and see what happens

mmcky commented 6 years ago

I mainly just jupyter notebook rather than jupyterlab ... I will test with jupyterlab on my end also. Unfortunately jupyter notebook and jupyterlab don't always produce the same output: https://github.com/QuantEcon/sphinxcontrib-jupyter/issues/79

jlperla commented 6 years ago

I think that most jupyterhub installations are moving quickly to jupyterlab, so it might make sense to test there as the primary interface. But, if this is a jupyter vs. jupyterhub issue, I think it also points out that there is only so much you can do to deal with different versions of jupyterhub

bayeswhu commented 6 years ago

@mmcky Is there any method to enlarge the labelled equations? As you mentioned, they are a little bit smaller than the equations without labels. Especially when I tried to present the notebook in slides (with RISE), I found it is hard to read.

arnavs commented 5 years ago

Hi @mmcky, just wanted to chime in that I can reproduce this issue on https://compare-lectures.quantecon.org/jl/jupinx_test.html

<table width=100%><tr style='background-color: #FFFFFF !important;'>
<td width=10%></td>
<td width=80%>
$$
v = f(v)
$$
</td><td width=10% style='text-align:center !important;'>

</td></tr></table><p>And want to link to it in text <a href="julia_by_example.html#equation-fixed-point-map">(1)</a></p>
mmcky commented 5 years ago

we could wrap the tables in a class and adopt a local mathjax resize in our theme for now.

https://stackoverflow.com/questions/19086152/changing-mathjaxs-font-size

mmcky commented 5 years ago

A fix for the current solution has been implemented in https://github.com/QuantEcon/sphinxcontrib-jupyter/pull/152

jlperla commented 5 years ago

Was this solution used in the latest generation of the notebooks? I just downloaded a notebook geenrated from the mccall lecture and in jupyterlab it looks like image

On the other hand, to look at the julia examples file, the HTML is a little odd in that the numbered equations are larger than the other ones: image

and the of numbered equations are still an issue with weird splitting image

mmcky commented 5 years ago

these issues should be fixed by https://github.com/QuantEcon/sphinxcontrib-jupyter/pull/154 when merged.

mmcky commented 5 years ago

154 is merged so closing this issue.