sphinx-jupyterbook-latex icon indicating copy to clipboard operation
sphinx-jupyterbook-latex copied to clipboard

Upgrade MyST-NB to get glue:math directive to work

Open martinlarsalbert opened this issue 2 years ago • 8 comments

Describe the bug

context

The glue:math directive is not working in JupyterBook as seen in the documentation: https://jupyterbook.org/en/stable/content/executable/output-insert.html#the-glue-math-directive ...where the equation has no number ( ).

This seems to be a bug that has been corrected in later versions of MyST-NB: https://myst-nb.readthedocs.io/en/latest/render/glue.html#the-glue-math-directive

But JupyterBook is not compatible with this newer version of MyST-NB as it seems. The newer MyST-NB works for html generation but not with latex builder.

expectation

bug

$ jupyter-book build mybook --builder latex

File "E:\dev\wPCC_pipeline\venv\lib\site-packages\sphinx_jupyterbook_latex\transforms.py", line 433, in apply
from myst_nb.nodes import CellInputNode, CellOutputNode
ModuleNotFoundError: No module named 'myst_nb.nodes'

problem Apparantly "myst_nb.nodes" does no longer exist.

I removed the failing part as a dirty fix that works for me now, as I don't have any code blocks. But I suspect that is not a good solution for all.

   class CodeBlockTransforms(SphinxPostTransform):
    """Handling any post transforms needed for code cells."""

    default_priority = 999

    def apply(self):
        if isinstance(self.env.app.builder, builders.latex.LaTeXBuilder):
            """Wrapping myst_nb code cell nodes with nodes of this extension."""
            pass
            #from myst_nb.nodes import CellInputNode, CellOutputNode
            #
            #for node in self.document.traverse(CellOutputNode):
            #    celloutput = CellOutput()
            #    celloutput.append(node.deepcopy())
            #    node.replace_self(celloutput)
            #
            #for node in self.document.traverse(CellInputNode):
            #    cellinput = CellInput()
            #    cellinput.append(node.deepcopy())
            #    node.replace_self(cellinput)

Reproduce the bug

  1. upgrade MyST-NB
  2. jupyter-book build mybook --builder latex

List your environment

Jupyter Book : 0.12.3 External ToC : 0.2.3 MyST-Parser : 0.17.2 MyST-NB : 0.15.0 Sphinx Book Theme : 0.1.10 Jupyter-Cache : 0.5.0 NbClient : 0.5.9

martinlarsalbert avatar May 10 '22 16:05 martinlarsalbert

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar May 10 '22 16:05 welcome[bot]

thanks for reporting this issue @martinlarsalbert

mmcky avatar May 11 '22 00:05 mmcky

@AakashGfude this will be a blocker for upgrading jupyter-book to support the latest myst-nb so we should try and prioritise this one.

mmcky avatar May 11 '22 00:05 mmcky

sure thing @mmcky will take this up as a priority.

AakashGfude avatar May 11 '22 17:05 AakashGfude

Can the requirements be updated to pin myst-nb to an appropriate version so that pip install brings in the correct version if installed with sphinx-jupyterbook-latex? Currently the warning comes when running Sphinx, requiring people to pin the versions themselves.

mforbes avatar Oct 02 '22 08:10 mforbes

@mforbes which myst-nb version is currently throwing warning? I was assuming sphinx-jupyterbook-latex works with all versions between >=0.13 to <=0.16, as pinned https://github.com/executablebooks/sphinx-jupyterbook-latex/blob/master/setup.cfg#L34

AakashGfude avatar Oct 02 '22 13:10 AakashGfude

Ah. I did not notice that myst was an extra, pip install "sphinx-jupyterbook-latex[myst]" works. Please change my request to simply update the docs to mention the myst extra.

mforbes avatar Oct 02 '22 16:10 mforbes

Thank you @mforbes for bringing this up. I have created an issue https://github.com/executablebooks/sphinx-jupyterbook-latex/issues/110 and will create a PR.

AakashGfude avatar Oct 03 '22 06:10 AakashGfude