Jupyter MathJax Physics package - jupyter-notebook

MathJax3 includes a port of the physics package, which I would like to use inside jupyter notebook / lab.
What are the steps necessary to use this extension? Can it be done without writing custom config files (important for collaboration)?
I tried installing the MathJax3 renderer for jupyter, but it seems that it does not recognize the \require command used to enable the extension. Another user already formulated an issue on github in September, but with no answers yet unfortunately.

Related

WebIO is not being detected by Jupyter Notebook

I am trying to open a Jupyter Notebook file in classic Jupyter Notebook interface. I am attempting to create an interective app that uses Julia programming language in interactive codes. For that I am trying to use the Interact library, because I know it features things such as buttons, sliders, etc. It requires the WebIo extension to be installed. However, from what I have experienced so far, Jupyter notebook does not detect the WebIO extension.
I tried following the instructions at https://juliagizmos.github.io/WebIO.jl/stable/gettingstarted/ and at https://juliagizmos.github.io/WebIO.jl/stable/troubleshooting/not-detected/. In the last link I found that another extension needed to be install and I found more information in this link (https://juliagizmos.github.io/WebIO.jl/latest/providers/ijulia/). I tried executing this command in my Windows prompt and it had apperently been succesful. When executing the command suggested at the second link, I got an error in the Julia REPL saying that WebIO extension for Jupyter Lab must be installed through Python or Conda, which I had already done.
I am also a bit confused as to how I can check to see if the extension is enabled.
I believe the problem has to do either with the installation of IJulia or the pip installation of WebIO. I rarely use pip, so I don't know if I did it correctly.
Thank you.

JuliaPro: import Jupiter notebook

I usually use Jupyter to have my interactive environment with Julia, now I am switching to JuliaPro, as they claim it is the fastest and easiest way of Julia programming. But, I cannot upload my .ipynb notebooks on JuliaPro. Are they compatible with each other? How can I work with my notebooks on JuliaPro? Thanks!
As was explained in the comments, the .ipynb file format was designed to be rendered in a browser, while Juno/Atom is a text editor that expects a plain text file for display. In general therefore you wouldn't be able to directly use an .ipynb file in Juno.
There is however an option to convert your notebooks to .jl scripts, which is exactly what Juno is expecting: in your Jupyter notebook click on File > Download as > Julia (.jl) (see below)
There's also an answer here that discusses a command line option if you need to batch convert a lot of files.
Also note that your choice of editor / programming environment is unrelated to the version of Julia you're using - while JuliaPro ships with Juno as standard (or potentially the Julia VS Code extension in future), nothing's keeping you from just doing using Pkg; Pkg.add("IJulia"); using IJulia; notebook() in your JuliaPro installation and continuing to work on your notebooks in Jupyter.

Using jupyter R kernel with visual studio code

For python jupyter notebooks I am currently using VSCode python extension. However I cannot find any way to use alternative kernels. I am interested in jupyter R kernel in particular.
Is there any way to work with jupyter notebooks using R kernel in VSCode?
Yes, it is possible. It just requires an additional configuration to connect with the R kernel in VSCode.
It's worth noting that, if you prefer, you can use the notebook in VSCode Insiders where there is native support for notebooks in many languages, including R.
If you're using Jupyter in VSCode, firstly install IRkernel (R kernel).
According to the docs, run both lines to perform the installation:
install.packages('IRkernel')
IRkernel::installspec() # to register the kernel in the current R installation
Now, you should:
Reload Window Ctrl + R
Type Ctrl + Shift + P to search for "Jupyter: Create New Blank Notebook"
Click on the button right below ellipsis in upper right corner to choose kernel
Switch to the desired kernel, in this case, R's
That's it!
Agreed with #essicolo, if you are 100% stuck on using vscode this is a no-go.
[About kernels] Sorry, but as of right now this feature is only supported with Python. We are looking at supporting other languages in the future.
Yeah, that's the case for now, even if you start an external server. I hate having to say that, as we really want to support more of the various language kernels. But we started out with a Python focus and we still are pretty locked into that for the near future. Polyglot support is coming, but it won't be right away
per Microsoft Employee IanMatthewHuff
https://github.com/microsoft/vscode-python/issues/5109#issuecomment-480097310
preface - based on the phrasing of your question, I am making the assumption that you are trying to perform IRkernel in-line execution from your text ide without having to use a jupyter notebook / jupyterlab.
That said, if you're willing to go to the dark side, there might be some alternatives:
nteract's Hydrogen kernel for Atom IDE - the only text ide that I'm aware of that still supports execution against IRkernel. I know, I know - it's not vscode but it's as close as you'll probably get for now.
TwoSigma's Beaker notebook - it's been a lonngggg time for me but this a branch of jupyter that used to support polyglot editing, I'm not sure if that's still supported and it seems like you aren't that interested in notebooks anyway.
#testing_22 it works with me too
just add some note from my experience
It will failed If you run IRkernel::installspec() from RStudio or from Jupyter Conda environment failed way
Please run this syntax with VSCode terminal
install.packages('IRkernel')
IRkernel::installspec()
The rest is same, please restart VSCode and select "R" kernel from VSCode

How to include bash scripts in a package?

I need to include several bash scripts in the R package I'm writing. I'd love to distribute them together with the package, so when a user installs the package via devtools::install_github(...) he/she gets the scripts as well.
I know it is possible, but I don't know how. Including the files in the scripts subdirectory doesn't seem to suffice. I need a means to tell R (or RStudio) to include them.
I use RStudio for development, so I would appreciate a solution that integrates with the "Build package" functionality that RStudio provides.
Simply add whatever you want to the inst/xxx folder in your package.
The folder will get installed as xxx when you compile/publish the package as a library.
You access the files via system.file(), e.g.
system.file('scripts/peak_mem.sh', package='clustertools')
See more details on the R packages by Hadley Wickham
Thank you #Axeman!

Can I use variables on an IPython notebook markup cell?

I have an IPython notebook and I would like to use one of my variables inside a markup cell. Is this even possible? If so, how do you do it?
If you don't mind a code cell that does the job, there is a possibility without adding any extensions.
from IPython.display import Markdown as md
fr=2 #GHz
md("$f_r = %i$ GHz"%(fr))
This will show a markdown cell in a nicely LaTeX formatted output
Currently, this is not possible, however there is a large discussion on this topic here https://github.com/ipython/ipython/pull/2592. The PR is currently closed, but a corresponding issue is opened https://github.com/ipython/ipython/issues/2958 and marked as wishlist.
Update
In the meantime an IPython extension has appeared which allows to render python variables in markdown cells. This extension is part of the IPython notebook extensions and works with IPython 2.x and 3.x. For a detailed description see the wiki page.
It is not officially supported, but installing the python markdown extension will allow you to do so. It is part of the nbextensions, for which you will find installation instructions on their github page. Make sure you'll enable the python markdown extension using a jupyter command or the extension configurator.
Calling python variables then should work with the {{var-name}} syntax, which is described in the readme of the corresponding github page (linked in the wiki):
For example: If you set variable a in Python
a = 1.23
and write the following line in a markdown cell:
a is {{a}}
It will be displayed as:
a is 1.23
Further info on this functionality being integrated into ipython/jupyter is discussed in the issue trackers for ipython and jupyter.
The link: installing notebook extention
gives a clear description of what is necessary to enable the use of variables in markdown cells. Following it, performed the following actions to realize it:
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
after a successful completion of the above command I enabled the python markup extension, from jupyter dashboard, as per the following illustration:
Last but not least!!! The NOTEBOOK HAS TO BE TRUSTED to make the markup extension works with python variables
and it worked for me!

Resources