Escaping dollar sign in ipython notebook

35,673

Solution 1

Put two backslashes in front of dollar signs. For example:

Some prices: \\$3.10, \\$4.25, \\$8.50.

(running Jupyter notebook server 5.7.0)

Solution 2

You can escape $ with math mode by using a backslash. Try $\$$

Solution 3

If you use <span>$</span>, MathJax won't process it as a delimiter. You should be able to enter that in Markdown. For example, I've used that here: $ This is not math $.

Solution 4

I was not able to get most of these solutions working. One that did work, though, is explained here. It refers to a SO question here and is as simple as:

<span class="tex2jax_ignore">$900 vs $4,500</span>

Hope this helps someone!

Solution 5

Did you try using the equivalent HTML entity instead?:

enter image description here

e.g.

enter image description here

Share:
35,673
Roberto
Author by

Roberto

Updated on February 19, 2022

Comments

  • Roberto
    Roberto over 2 years

    I have a markdown cell in iPython that contains four dollar signs. iPython interprets anything between dollar signs as a MathJax expression, which is not what I want. How do I escape the dollar signs? Escaping them with a backslash prevents MathJax from kicking in, but the backslash shows in the compiled Markdown.

    ANy ideas on how to get just the dollar sign?

    Thanks

  • Simon
    Simon over 5 years
    Very helpful. This answer works well in quoted text while the other solutions don't work as well in that context. A single backslash in quoted text still enters math mode. Using backticks leads to a highlighted code-block in the text.
  • Happypig375
    Happypig375 over 5 years
    Answer too short. Care to explain?
  • Oke Uwechue
    Oke Uwechue over 5 years
    no problem. I've updated my answer with an example. pls. see above.
  • Happypig375
    Happypig375 over 5 years
    Care to explain why it works? (about how HTML escape codes work)
  • William M.
    William M. over 2 years
    When you export with a double backslash some dollar signs are backslashed in the exported html, other aren't. If you delete the double backslash to single backslash in Jupyter, then mathjack is compiled. Very confusing.
  • aaossa
    aaossa over 2 years
    Does this answer add new information? It seems like a cool breakdown of how you tackled and understood the problem, but it seems like it does not provide new information
  • Admin
    Admin over 2 years
    The particular information I was adding was a clearer explanation of what "using the equivalent HTML entity instead" means in the context of a Jupyter Notebook. Many people who write notebooks aren't fluent in HTML, and the previous answer using that wording showed an HTML table rather than a minimal example, so it wasn't clear how that suggestion applied to the original question.
  • Admin
    Admin over 2 years
    It probably would have been sufficient to add a comment saying something like "In other words, instead of 'The price range is $100 to $200' you can write 'The price range is &#36;100 to &#36;200'". But I'm new to contributing and lack sufficient reputation to comment on other people's answers just yet, so it had to be an answer rather than comment! Then at that point I couldn't help but write the longer explanation with headings etc. 😅
  • aaossa
    aaossa over 2 years
    No problem. As I said, the breakdown is still cool
  • owen
    owen almost 2 years
    This solution worked for me when escaping with \\$ did not. However, worth noting that the character produced in math mode is not identical to the $ character.