Skip to content

Dollar $ sign ($) triggers errors in Markdown highlighting, even when escaped #1080

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

Open
halflings opened this issue Feb 11, 2016 · 20 comments

Comments

@halflings
Copy link

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.

skarmavbild 2016-02-11 kl 12 08 31

@halflings halflings changed the title Errors in Markdown highlighting Dollar $ sign ($) triggers errors in Markdown highlighting, even when escaped Feb 11, 2016
@halflings
Copy link
Author

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.

@takluyver
Copy link
Member

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. 😕

@willingc
Copy link
Member

willingc commented Feb 12, 2016

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.

screen shot 2016-02-11 at 4 48 51 pm

screen shot 2016-02-11 at 4 48 34 pm

@halflings
Copy link
Author

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
#1080 (comment).

@takluyver
Copy link
Member

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.

@minrk minrk added this to the 5.0 milestone Jun 16, 2016
@liviu-
Copy link

liviu- commented Sep 9, 2016

I also ran into a perhaps similar issue:

syntax_highlight-issue

Hope this helps

@jaypeedevlin
Copy link

jaypeedevlin commented Dec 27, 2017

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

@magland
Copy link

magland commented Sep 6, 2018

This still appears to be an issue.

@tannert
Copy link

tannert commented Jan 31, 2019

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

@jasongrout
Copy link
Member

In the latest jlab (0.35.4), I only have to escape dollar signs with one backslash, same as the classic notebook.

@jasongrout
Copy link
Member

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.

@agnedil
Copy link

agnedil commented Mar 4, 2019

Two backslashes for $ and one for % did it. Looks fine for me in notebook server 5.7.4

@austincauthon
Copy link

A workaround for this issue is to use the unicode &#0036; in place of using a $. This will render a $ inside your rendered document, but not affect your syntax highlighting in your editor.

@mobilinkd
Copy link

mobilinkd commented Apr 4, 2020

Using &#0036; 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.

@dcompoze
Copy link

dcompoze commented Feb 7, 2022

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:

selection-1644195339

selection-1644195357

Though the symbol renders correctly, which suggests that the highlighting parser has different logic than the renderer.

@shepware
Copy link

shepware commented Feb 16, 2022

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).

@tvbush
Copy link

tvbush commented Jun 9, 2022

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".

Screen Shot 2022-06-09 at 3 51 51 PM

My second image shows how it is rendered on Github.

Screen Shot 2022-06-09 at 3 51 09 PM

@jasongrout
Copy link
Member

jasongrout commented Jun 10, 2022

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.

@tvbush
Copy link

tvbush commented Jun 10, 2022

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!

@jasongrout
Copy link
Member

This renders correctly in the latest JupyterLab and Jupyter Notebook:

A test \\${asdf} \\${asdflkj}

Screen Shot 2022-06-10 at 18 12 44

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