QuantEcon / sphinxcontrib-jupyter

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

ENH: Update displaymath to use Latex tags rather than html table wrappers #154

Closed mmcky closed 5 years ago

mmcky commented 5 years ago

This PR changes the implementation to use \tag{} for displaymath with id labels instead of html tables. This increases compatibility with jupyterlab and makes the notebook more readable.

thanks @jlperla for the suggested solution.

Currently it looks like <a id=""> references don't work in jupyterlab.

Image size issues are also resolved as all math is in the same environment.

mmcky commented 5 years ago
mmcky commented 5 years ago

this is broken in linear_algebra on the python side. So need to take a closer look tomorrow before merging this.

Should be:

image

and is (after nbconvert)

image

and strangely it looks ok in the notebook

image

with markdown

According to the preceding rule, this gives us an $ n \times 1 $ column vector

<a id='equation-la-atx'></a>
$$
A x
=
\left[
\begin{array}{ccc}
    a_{11} &  \cdots & a_{1k} \\
    \vdots & \vdots  & \vdots \\
    a_{n1} &  \cdots & a_{nk}
\end{array}
\right]
\left[
\begin{array}{c}
    x_{1}  \\
    \vdots  \\
    x_{k}
\end{array}
\right]
:=
\left[
\begin{array}{c}
    a_{11} x_1 + \cdots + a_{1k} x_k \\
    \vdots \\
    a_{n1} x_1 + \cdots + a_{nk} x_k
\end{array}
\right] \tag{2}
$$

>**Note**
>
>$ A B $ and $ B A $ are not generally the same thing

Another important special case is the identity matrix
mmcky commented 5 years ago

It appears nbconvert is not honoring the $$ environment for displaymath reliably. The html has injected html items within the math. The source for this bug is:

$$</p>
<h1 id="A-x">A x<a class="anchor-link" href="#A-x">&#182;</a></h1><p>\left[
\begin{array}{ccc}
    a_{11} &amp;  \cdots &amp; a_{1k} \\
    \vdots &amp; \vdots  &amp; \vdots \\
    a_{n1} &amp;  \cdots &amp; a_{nk}
\end{array}
\right]
\left[
\begin{array}{c}
    x_{1}  \\
    \vdots  \\
    x_{k}
\end{array}
\right]
:=
\left[
\begin{array}{c}
    a_{11} x_1 + \cdots + a_{1k} x_k \\
    \vdots \\
    a_{n1} x_1 + \cdots + a_{nk} x_k
\end{array}
\right] \tag{2}
$$</p>
mmcky commented 5 years ago

this is an issue with nbconvert and not our template.

mmcky commented 5 years ago

There is an issue already registered with nbconvert. https://github.com/jupyter/nbconvert/issues/404

Will try and massage the LaTeX to get it to work.

mmcky commented 5 years ago

OK so the issue is the = on its own line. This is caught by nbconvert as markdown and breaks the equation environment. Given I am not sure how many edge cases there are here -- I am a bit reluctant to start editing our equations to fit around the nbconvert issue until the treatment of $$ upstream is improved. @jlperla perhaps we should stick with wrapped equations in html for now -- what do you think?

jlperla commented 5 years ago

Is the = on its own line the only thing we know that triggers this? If so, then that seems to be a regex we could easily check for in and fix across the lecture notes?

mmcky commented 5 years ago

From the issue on nbonvert -- open lists [ also seem to break it. @jlperla do you have an RA that could check edge cases across the jl side I would be happy to coordinate updating on the py side. Its a bit tricky as they would need to diagnose on the IPYNB -> HTML border but they could do this on an individual lecture basis (without the template wrapper) using `jupyter nbconvert --to html file.ipynb``

The time consuming part is there is no way to check errors without reviewing all files file-by-file

mmcky commented 5 years ago

Decision: Modify RST files to suite buggy nbconvert