QuantEcon / sphinxcontrib-jupyter

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

how to use jupyter_lang_synonyms and jupyter_kernels settings #174

Closed sglyon closed 4 years ago

sglyon commented 5 years ago

Hi team, sorry if this is posted somewhere else, but I couldn't find it.

My want is to be able to able to define a code-block like this

.. code-block:: XXX
    my_code_here

and be able to configure that when the code block's language is XXX a specific jupyter kernel will be used. If language XXX is not configured with or linked to a kernel then the default behavior will be to include the associated code as a highlighted code block in a markdown cell.

Is this possible?

Thanks!

mmcky commented 5 years ago

hi @sglyon the default behaviour for the extension is the use the project wide default language (in sphinx) for matching with the kernel. If a code-block differs to the default it will be added as markdown as it cannot be executed using the default kernel. Perhaps that is your issue?

mmcky commented 5 years ago

in the lecture site we use .. highlight:: {{ programming_language }} to set the default language at the top of each file.

sglyon commented 5 years ago

Ok, I was hoping that this could be configured at the project level and thought that perhaps the jupyter_lang_synonyms or jupyter_kernels settings in the conf.py would let me do it.

Is that right?

arnavs commented 5 years ago

Per https://github.com/QuantEcon/lectures_quantecon_datascience/issues/101, it looks like jupyter_lang_synonyms = ["python"] is sufficient to include in the src/conf.py.

arnavs commented 5 years ago

To be clear, though, I don't know if it's possible to configure a general map. I think what jupyter_lang_synonyms does is map the array entries to the project wide default --- is that correct?

mmcky commented 5 years ago

hey @sglyon sorry just saw this. The jupyter_lang_synonyms is really there to allow ipython highlighted code to be recognised as python code in a mixed code sense in projects that use both. The default lang for sphinx is python. Is data science going to be in multiple languages?

mmcky commented 5 years ago

We are going to make the python kernel the default for jupyter_kernels until we learn how to infer it from the documents. That way you will have an example to go by for any other language. See Issue #196

mmcky commented 5 years ago

@sglyon did this thread answer your question?

mmcky commented 4 years ago

the use here is

jupyter_lang_synonyms = ['ipython', 'python2'] # synonyms for python3 highlighting for code-blocks