Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of inline code? #498

Open
matthew-brett opened this issue Apr 23, 2020 · 9 comments
Open

Possibility of inline code? #498

matthew-brett opened this issue Apr 23, 2020 · 9 comments

Comments

@matthew-brett
Copy link
Contributor

I continue to use Jupytext all the time, and here's another thank you for the huge improvement it has made to my work.

I know this is a fraught question, but I really miss the R notebook ability to put code outputs inline, as in:

```{python}
msg = "Hello"
```

My message is `py msg`.

Do you think there is any way of doing that?

@mwouts
Copy link
Owner

mwouts commented Apr 23, 2020

Thank you @matthew-brett ! Very kind of you.

Are you using Jupyter Notebook, or JupyterLab ? In the former you could use the python-markdown extension, and write

```python
msg = "Hello"
```

My message is {{msg}}.

I think this also works with nbconvert.

In JupyterLab there does not seem to be anything like this. So what people seem to be using is the following: they display Markdown text with the Markdown command, e.g.

```python tags=["hide"]
from IPython.display import Markdown
Markdown(f'''My message is {msg}.''')
```

and then they hide the input code for that cell. See for instance this blog post. Or you could also use jupyter={"source_hidden": true} according to this thread:

```python jupyter={"source_hidden": true}
from IPython.display import Markdown
Markdown(f'''My message is {msg}''' + 
         ' - the input code for this cell is hidden with a '
         'cell metadata `{"jupyter": {"source_hidden": true}}`.')
```

which gives this:
Screenshot from 2020-04-24 00-07-17

@chrisjsewell
Copy link
Contributor

@matthew-brett also for your consideration https://myst-nb.readthedocs.io/en/latest/use/glue.html 😁

@mwouts
Copy link
Owner

mwouts commented May 21, 2020

@matthew-brett , did you give a try to one of the above? Which is your favorite?

@matthew-brett
Copy link
Contributor Author

Thanks for the follow up. Sorry not to get back to you, I was reflecting.

I realize that my question wasn't properly considered. My use case is that I want to distribute notebooks as part of an interactive textbook; the textbook has the filled-in (executed) version, but the student downloaded the not-executed version. I think this means that neither of the two suggestions here are going to work well, because (I believe) they are both going to need the student to install extra stuff into their notebook setup.

But on reflection - I don't see how Jupytext could solve that - except perhaps by allowing something like automatic translation of this in .Rmd

Here is a variable value: `py a` 

into this in .ipynb:

Here is a variable value: {{a}}

Of course, this would have the same problem - that the .ipynb user would need to have the python-markdown extension, but then again, the user has used that non-standard syntax, so may well be prepared to take that risk.

Adding a reference to markdown-kernel here because of useful links therein.

@mwouts
Copy link
Owner

mwouts commented May 22, 2020

Hi @matthew-brett , well sure, we could think of translating py a in R Markdown files to {{a}} in Python Jupyter notebooks, and back. I'll think about that - it would be the first non-verbatim translation for the content of Markdown cell - but if it can help, why not?

@matthew-brett
Copy link
Contributor Author

Well - I think it wouldn't help me - at the moment - because of the problem of relying on a not-standard plugin. So maybe wait until someone screams on this thread? Maybe that will be me! But not yet.

@mwouts
Copy link
Owner

mwouts commented May 22, 2020

Haha... Sure! Then, if you don't mind maybe I'd prefer to close this thread for now, and anyone interested can either reopen of create a new follow-up. Is that ok with you? Thanks!

@matthew-brett
Copy link
Contributor Author

Fine either way. I guess, if you leave it open, you signal that you're open to negotiation on this one.

@mwouts
Copy link
Owner

mwouts commented May 22, 2020

I see - indeed I like your question, so let's keep this open and see what we can do on the long term.
Also, I was thinking, we've discussed R Markdown and ipynb, but maybe there is something that we could for Python files with the f-strings...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants