I started using python with the jupyter notebook and the problem is that the printing is not like the standard LaTeX
My cell:
%%latex
\begin{center}
$(a+b)^{2} = a^{2}+2ab+b^{2}$
\end{center}
The result in the notebook looks like in the following picture:
from jupyter docs:
The subset of latex which is supported depends on the implementation in
the client. In the Jupyter Notebook, this magic only renders the
subset of latex defined by MathJax
here.
You could use markdown to display your formula: use single $ to indicate latex, or double $$ to center it. You need to format your cell as markdown instead of code
Your cell becomes one of these two lines:
$$(a+b)^{2} = a^{2}+2ab+b^{2}$$
$(a+b)^{2} = a^{2}+2ab+b^{2}$
You must run the cell to display markdown.
I had a similar problem. A certain set of latex equations in my ipython notebook just stopped rendering properly. It turned out that my latex interpreter had gotten into a weird state because I executed a cell with the code \def in it, by accident.
To fix the problem, I just saved my notebook, stopped the python kernel, closed the notebook in the browser, then re-opened it again and re-executed all the cells. This fixed the problem, and the equations rendered correctly again.
I discovered from https://stackoverflow.com/a/32166264/4347428 that the MathJax will not render unless you go into your jupyter config and ensure mathjax is enabled:
## Whether to enable MathJax for typesetting math/TeX
#
# MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
# very large, so you may want to disable it if you have a slow internet
# connection, or for offline use of the notebook.
#
# When disabled, equations etc. will appear as their untransformed TeX source.
c.NotebookApp.enable_mathjax = True
Unfortunately, this didn't get me all the way there, and neither did making sure the notebook was Trusted in the upper right, but perhaps it'll help someone else.
In my case (winpython), it looks like my firewall prevent Mathjax to be succesfully installed. I had to install Mathjax from a local file to get I to work :
download the latest Mathjax.zip
python -m IPython.external.mathjax C:\path\to\your\file\Mathjax.zip
I am now able to render latex in code cells and in markdown cells either
If you are going to use an environment like this:
\begin{equation}
(a+b)^{2} = a^{2}+2ab+b^{2}
\end{equation}
Notice I do not use the $$ env which is better used as inline math. Another thing to notice is that there are no spaces between the lines, if you add spaces between the lines, the notebook will display the latex code instead of rendering it when you run the cell.
Using jupyterlab installing this package: jupyterlab-mathjax3 solved this problem for me.
Related
I am plotting some figures using matplotlib inside a notebook in JupyterLab. The code which is plotting these figures is imported from a .py file present in the same directory as of the notebook.
Assuming that figures are of appropriate size, how can I display them entirely i.e. where scrolling is not needed or disabled to display the output and I can get one-shot overview of the output given it is not populating the display beyond the screen size?
The issue is resolved if I copy the code from .py file and run it in the notebook directly:
I have tried Toddneal's answer from Making a Jupyter notebook output cell fullscreen, but scroll bar still exists in the output cell. I also referred to How to avoid output into scrollable frames in jupyter notebook? and tried:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
as the first code cell in the notebook, but gives out the error: Javascript Error: Can't find variable: IPython.
The output cell is already expanded, so the issue is with the height of the output cell. There are bunch of cells beyond the output cells (could that be possibly affecting the height of output cell?). The extension autoscroll might not work because it is a Jupyter Notebook extension:
Due to major differences between the Jupyter Notebook and JupyterLab, the extensions in this repository will not work in JupyterLab.
As krassowki suggested in a comment, the scrolling is disabled by right-clicking on the output cell and choosing "Disable Scrolling for Outputs."
I hope this is not a redundant question, but I was not able to find a proper answer and tutorial. I am currently learning Data Science and therefore use kaggle competition for practice and jupyter notebook to tackle them (as it is visually more appealing to me). Now I stumbled upon an example kernel (see: http://nbviewer.jupyter.org/github/agconti/kaggle-titanic/blob/master/Titanic.ipynb#Data-Handling) is using comments, links and illustrations between his codes to give more context.
Is anybody aware of how to write such comments and remarks within jupyter? If so, do you have an online resource where I could learn this?
Thanks a bunch!
Yep - highlight a cell and click on the "Cell" dropdown menu and go to "Cell Type" and choose "Markdown". Then you can type any markdown text you'd like and it will render as such.
^^ Also there are shortcuts for changing cell types as well. Highlight a cell and press the esc key to change into "command" mode and press m. This changes it to a markdown cell. Press y to change it back to a code cell.
You can also do latex equations using dollar signs ($). There is documentation for this here
For markdown cells
[//]: # "Your comment in here."
allows to include a comment in jupyter notebook server version 6.0.1. See this discussion for more details on markdown comments.
Agree with #RSHAP. I just add the flow picture in the below.
select the active Cell > Cell Type > Markdown.
irrespective of the version of jupyter notebook you use, the following command should work on current cell
Pres ESC
then Press m
As mentioned in the above remarks, use markdown cells.
Once in a markdown cell, use #,##,###,#### for headings of different fonts. For bold, use **your_text_here**, and for italics use *your_text_here*. For writing equations and using latex commands, use $ symbol. Everything works just like in latex; you can even define your notations like you would normally do in Latex. For a more detailed and structured overview to format text In Jupyter, have a look at this website:
https://www.earthdatascience.org/courses/intro-to-earth-data-science/file-formats/use-text-files/format-text-with-markdown-jupyter-notebook/
I got a strange problem with jupyter-notebook.
I was practicing with notebook which has markdown and code cells.
When I save and reopen the notebook, I can edit code cells but not the
markdown cells.
Attempts:
reload the page.
Make the notebook trusted.
Try to change the cell type from markdown to code or raw but still can not edit.
NOTE:
I can delete some letters on markdown but I can not add any letters.
Also if I hit enter it will create new lines, but I can not write anything there.
Question
How can we edit the markdown cell of a jupyter-notebook ?
In case anybody also encountered the same problem, I am keeping this question
and my solution to it, instead of deleting the question.
What I did is :
a) First go to markdown cell.
b) Double click the cell, now we can only delete the letters, can not edit it.
c) Go to command mode (press esc) and again come back to edit mode (Enter).
d) Now we can edit the markdown cell.
This solved my problem.
Just double click on the markdown cell. Edit what you want to and Run. It will reflect the changes. Save your notebook.
I was using Jupyter in Windows and just switched to Ubuntu. I found the colour of the code is very weird in the firefox browser. E.g. it highlights the variables in every other line.
I tried to solve this problem by installing a custom theme and the effect should be like
Instead, it still highlights every other variable on my side, like
This just makes my eyes very tired when try to debug the code.
I also tried disabling all the add-ons in Firefox which didn't help. Is there any setting that I can change to restore to the default colour display?
I sometimes get this if I'm copying/pasting from a source that has a different indentation size than that of the jupyter notebook. In your screenshot it looks like a small indent size so this seems like the likely culprit. Try highlighting the full block of indented code and hitting ctrl+[ then ctrl+] (this unindents the selected lines of code, then reindents them using the jupyter indent size).
If this doesn't work, you might try checking to see if there are any custom indentation settings specified in either ".jupyter/nbconfig/notebook.json" or ".jupyter/custom/custom.js" (... or whatever the Windows equivalents are).
In ".jupyter/nbconfig/notebook.json", I have the indentUnit set to 4 spaces (and have also enabled linewrapping).
{
"CodeCell": {
"cm_config": {
"indentUnit": 4,
"lineWrapping":true
}
}
}
Most editors allow you to set your indent size (Atom, sublime text, etc.) so you can avoid this issue in the future by making sure you have the same indent size everywhere you're swapping code to/from (assuming this is what's causing the red highlighting). Python's default is 4 so def recommend sticking with that.
When using the web based iPython Notebook/Jupyter capability, i created a notebook with markdown cells of text and code cells to display the code and plots for matplotlib and bokeh. I then download that as .ipynb open with sublime, copy and paste to git, then access it on nbviewer through my git account. When looking at it here:
http://nbviewer.ipython.org/github/angisgrate/test/blob/master/pyohio3.ipynb
in notebook view, it works fine. the markdown, code, and plot steps are all there.
When switching to slides view, the intent of the creation needed for the presentation, this code blocks occurs first, blocking out the first 10 markdown steps and all the matplotlib steps, rendering this weird code without the plots:
http://nbviewer.ipython.org/format/slides/github/angisgrate/test/blob/master/pyohio3.ipynb
How can i fix this asap?? I've looked through and there was a similar problem in 2014 with slides, but it yielded an actual "Error" that i'm not seeing, just this contorted view
I can't say for certain. It's possible in the nbviewer slides view, the execution of JavaScript is suppressed (this happens on GitHub notebook previews, for instance). All of the rendering in Bokeh actually happens from the JavaScript library BokehJS, so if this is the case, then Bokeh will not function, and there is nothing really that can be done. This is probably a question bset directed towards the nbviewer team/community to find out the specifics of how the slides view behaves (and is intended to behave) with respect to executing embedded JavaScript.
Edit: Looks like this is a known/discussed issue. More information here: Issue #484: Jupyter>>nbviewer slides Fail, notebook view fine by angisgrate in jupyter/nbviewer on GitHub