notebook
notebook copied to clipboard
Dollar $ sign ($) triggers errors in Markdown highlighting, even when escaped
For an unknown reason, one of my cells has weird Markdown highlighting (see attached screenshot). It seems like it might have something to do with the presence of "%" characeters? Other cells are formatted correctly.
EDIT: seems caused by the first dollar sign.

I updated the post because it seems that the dollar triggers these errors. Even escaping it (by adding a back-slash before the dollar sign) doesn't help.
When Markdown cells are rendered, dollar signs can be used to delimit latex-style formulae. However, I didn't think that affected the syntax highlighting when they're in edit mode. :confused:
I did a bit of diving into this. I don't think that the "$" is the issue but rather how CodeMirror (or possibly our code) behaves when it reaches a special character. There is likely a regex in the CodeMirror code that causes % to be treated as the start of a <span class="cm-comment"> instead of the more common use of <span class="cm-delimit cm-delimit-open"> for the "$".
If any front end folks have a good suggestion to fix this, that would be great.
FWIW, the syntax highlighting is wonky but the rendered cell after hitting SHIFT-ENTER looks fine.


The formatting looks OK (while editing) once I remove the dollar sign from the example I've shown.
But yes, this is a code highlighting problem (that makes it hard to edit), but the Markdown is still correctly rendered
fre 12 feb. 2016 02:29 Carol Willing [email protected] skrev:
I did a bit of diving into this. I don't think that the "$" is the issue but rather how CodeMirror (or possibly our code) behaves when it reaches a special character. There is likely a regex in the CodeMirror code that causes % to be treated as the start of a instead of the more common use of for the "$".
If any front end folks have a good suggestion to fix this, that would be great.
FWIW, the syntax highlighting is wonky but the rendered cell after hitting SHIFT-ENTER looks fine.
[image: screen shot 2016-02-11 at 4 48 51 pm] https://cloud.githubusercontent.com/assets/2680980/12996371/02290146-d0e4-11e5-9c33-9e3ea43bed4f.png
[image: screen shot 2016-02-11 at 4 48 34 pm] https://cloud.githubusercontent.com/assets/2680980/12996370/01bcd5ac-d0e4-11e5-93ed-c172b5028e48.png
— Reply to this email directly or view it on GitHub https://github.com/jupyter/notebook/issues/1080#issuecomment-183142847.
Someone also pointed out to me yesterday that if you put something that looks like a git commit ID in a markdown cell, it gets highlighted in blue and underlined. I guess the syntax highlighting is a bit more Github flavoured than the rendering.
I also ran into a perhaps similar issue:

Hope this helps
This is something I run into almost daily, and while obviously the notebook renders fine, I do get annoyed at the minor syntax highlighting error.
Would this be something that would need to be fixed upstream (ie CodeMirror), or would this be handled inside Jupyter?
Edit: I can now see that CodeMirror doesn't support LaTeX and that support is added here inside the Jupyter Repo: https://github.com/jupyter/notebook/blob/ca50f1af5afb525fd95b98b2e61e69db28094467/notebook/static/notebook/js/codemirror-ipythongfm.js
This still appears to be an issue.
Looks like it works if you escape it with two backslashes. I just tried it in Jupyter Lab 0.34.3 and it worked.
source: https://stackoverflow.com/questions/16089089/escaping-dollar-sign-in-ipython-notebook
In the latest jlab (0.35.4), I only have to escape dollar signs with one backslash, same as the classic notebook.
Ah, I didn't understand that the issue here is about the syntax highlighting, not the rendering. Yes, I still see an issue with the syntax highlighting.
Two backslashes for $ and one for % did it. Looks fine for me in notebook server 5.7.4
A workaround for this issue is to use the unicode $ in place of using a $. This will render a $ inside your rendered document, but not affect your syntax highlighting in your editor.
Using $ does not fix the problem in the version 5.7.8. Worse, there does not seem to be an escaping mechanism that works across Jupyter, Github's notebook renderer, and nbviewer. The fact that jupyter and nbviewer disagree about markup rendering is a bit frustrating. The notebook renderer requires double-backslashes to escape $ but nbviewer will show a \$ for some of these.
The $ sign breaks the markdown cell syntax highlighting (in edit mode) and the escape sequences don't seem to make a difference.
Also, it's not possible to escape it when you write it in a code block:


Though the symbol renders correctly, which suggests that the highlighting parser has different logic than the renderer.
I'm finding that if I do a two-slash-then-dollar-sign "\$" rather than just typing dollar-sign "$" in the context of writing a paragraph, it makes things look good (within Jupyter Notebook, Python 3, using narrative, Esc+M to set Markdown type cells that present well if you hit Enter after typing. Unfortunately, after you "git add .", "git commit -m 'comment'", and "git push origin master", the rendering at github.com ends up doing some odd font intermittently between instances of double-slash-dollar-sign "\$" in my text narrative, failing to ignore the stylistic implications of dollar-sign "$" in the way that jupyter ignored in the version I last reviewed before pushing to git.
TLDR: markdown in jupyter looks like hell on github, meaning it unfortunately might be easier to pdf writeups from jupyter (generally available at the time of creation) than github (generally available for retro-browsing, as version control software).
Well, this really doesn't work. I don't see any solution at all. I've tried everything suggested on this page. The only one that works is where there is only a single dollar sign on a line. Anything else seems to break, sometimes in VERY strange ways. Note that when this is rendered, both Chrome and Firefox display the second line correctly for a moment, and then it is turned into math-renderer style which is clearly NOT what I want.
My first image shows the source in plain text. The file is named "EXAMPLE.md".

My second image shows how it is rendered on Github.

how it is rendered on Github.
@tvbush - we don't have any control over how GitHub renders Jupyter notebooks. If this is an issue with displaying a notebook on GitHub, you'll need to file a support request with GitHub.
Did you try to reproduce my issue? Yes, I will send it to Github too. Thanks! I was just happy to find someone else who had similar issues!
This renders correctly in the latest JupyterLab and Jupyter Notebook:
A test \\${asdf} \\${asdflkj}