Escaping dollar sign in ipython notebook
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?:
e.g.
Roberto
Updated on February 19, 2022Comments
-
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 over 5 yearsVery 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 over 5 yearsAnswer too short. Care to explain?
-
Oke Uwechue over 5 yearsno problem. I've updated my answer with an example. pls. see above.
-
Happypig375 over 5 yearsCare to explain why it works? (about how HTML escape codes work)
-
William M. over 2 yearsWhen 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 over 2 yearsDoes 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 over 2 yearsThe 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 over 2 yearsIt 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 $100 to $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 over 2 yearsNo problem. As I said, the breakdown is still cool
-
owen almost 2 yearsThis 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.